summaryrefslogtreecommitdiff
path: root/web-server/wwwcvs-orig-files/modules/wwwgnu-nongnu/files/update-gnu-rewritemaps
diff options
context:
space:
mode:
Diffstat (limited to 'web-server/wwwcvs-orig-files/modules/wwwgnu-nongnu/files/update-gnu-rewritemaps')
-rwxr-xr-xweb-server/wwwcvs-orig-files/modules/wwwgnu-nongnu/files/update-gnu-rewritemaps280
1 files changed, 280 insertions, 0 deletions
diff --git a/web-server/wwwcvs-orig-files/modules/wwwgnu-nongnu/files/update-gnu-rewritemaps b/web-server/wwwcvs-orig-files/modules/wwwgnu-nongnu/files/update-gnu-rewritemaps
new file mode 100755
index 0000000..96b78ef
--- /dev/null
+++ b/web-server/wwwcvs-orig-files/modules/wwwgnu-nongnu/files/update-gnu-rewritemaps
@@ -0,0 +1,280 @@
+#! /bin/bash
+# Create plain text maps for mod_rewrite from .symlinks files.
+# Main control is at the end.
+#
+# Originally written by Ineiev <ineiev@gmail.com>, feb 2011.
+# Ineiev <ineiev@gmail.com>, Mar 2012: fix links to absolute paths.
+
+web_root=${1-/srv/data/www-mirror}
+www_maps_dir=${2-~}
+verbose=${3-no}
+
+# The fancy /%\// here removes any trailing / that might have been
+# specified in the above variables, since we re-insert the / below.
+# Maybe not 100% necessary, but cleaner.
+web_root=${web_root/%\//}
+www_maps_dir=${www_maps_dir/%\//}
+
+max_link_depth=17
+
+# These file names are used in the vhost configuration.
+html_map_name=html-map.txt
+nonhtml_map_name=nonhtml-map.txt
+dir_map_name=dir-map.txt
+
+SED=sed
+FIND=find
+
+# function to filter out from file "$1" any
+# empty lines, comments, trailing spaces, invalid lines;
+# and replace multiple spaces with single one;
+# and prefix the line with its number if "$2" is "-n".
+cleanup-symlinks () {
+ ${SED} "s/#.*//;s/[[:blank:]]\+/ /g;\
+ s/[[:blank:]]$//;s/^[[:blank:]]//" "$1" \
+ | grep $2 ".[[:blank:]]." | grep -v "[[:blank:]].*[[:blank:]]"
+}
+
+# check if the file or directory exists,
+# assign the "type" variable accordignly
+get-file-type () {
+ if test -f "$1"; then
+ type=file
+ if test ${verbose} = yes; then
+ echo found $1 file
+ fi
+ return 0;
+ fi
+ if test -d "$1"; then
+ type=directory
+ if test ${verbose} = yes; then
+ echo found $1 directory
+ fi
+ return 0;
+ fi
+ type=
+ return 1;
+}
+
+# sed programs to normalize paths
+simplify_path=":cycle;s%/[^/]*/\.\./%/%;t cycle"
+normalize_link="${simplify_path};"
+# should we add something like
+# "s%\(^\| \)/savannah-checkouts/gnu%\1/software%g"
+# to normalize_link?
+
+# function used to subsitute software <-> savannah-checkouts/gnu in paths
+substitute-path () {
+ aliased_path=$(echo $1 | ${SED} "s%^/$2%/$3%;${simplify_path}")
+ if test ${verbose} = yes; then
+ echo "$1 is absent; I'll look in /$3"
+ fi
+}
+
+substitute-software () {
+ substitute-path "$1" software savannah-checkouts/gnu
+}
+
+substitute-checkouts () {
+ substitute-path "$1" savannah-checkouts/gnu software
+}
+
+# output the common part for diagnostic messages
+show-current-line () {
+ printf "%s" "${web_root}${symlinks_directory}.symlinks:$lineno: "
+ echo ${current_line} | ${SED} "s/[[:blank:]]\+/ <- /"
+}
+
+# function to process a single .symlinks file.
+append-symlinks () {
+
+ if test ${verbose} = yes; then
+ echo processing file "$1":
+ fi
+ symlinks_directory=$(echo $1 \
+ | ${SED} "s ^${web_root}/\(.*\)\.symlinks$ /\1 ")
+ cleanup-symlinks "$1" -n | while read current_line; do
+ lineno=$(echo ${current_line} | ${SED} "s/:.*//")
+ current_line=$(echo ${current_line} | ${SED} "s/^[^:]*://")
+
+ link=$(echo ${current_line} | ${SED} "s/^.*[[:blank:]]//")
+ target=$(echo ${current_line} | ${SED} "s/[[:blank:]].*$//")
+ target_directory=${symlinks_directory}
+
+ if test ${verbose} = yes; then
+ echo line ${lineno}: ${current_line}
+ fi
+
+ link_depth=0
+ type=none
+ # follow subsequent links until we get the real thing or find an error
+ while true; do
+ case "x${target}" in
+ # external link
+ x*://*)
+ full_target="${target}"
+ type=external
+ break
+ ;;
+ # absolute link
+ x/*)
+ target_directory=
+ ;;
+ esac
+ # check if the target exists
+ if get-file-type "${web_root}${target_directory}${target}"; then
+ full_target="${target_directory}${target}"
+ break
+ fi
+ case "x${target_directory}${target}" in
+ # look for /software files in /savannah-checkouts/gnu
+ x/software/*)
+ substitute-software "${target_directory}${target}"
+ if get-file-type "${web_root}${aliased_path}"; then
+ full_target="${aliased_path}"
+ break
+ fi
+ ;;
+ # look for /savannah-checkouts/gnu files in /software
+ x/savannah-checkouts/gnu*)
+ substitute-checkouts "${target_directory}${target}"
+ if get-file-type "${web_root}${aliased_path}"; then
+ full_target="${aliased_path}"
+ break
+ fi
+ ;;
+ esac
+ target_directory=$(echo ${target_directory}${target} \
+ | ${SED} "s%[^/]*$%%")
+ target_symlinks=${target_directory}.symlinks
+ if test ! -f "${web_root}${target_symlinks}"; then
+ # no .symlinks file found: try alternative places
+ # (/software for /savannah-checkouts/gnu and vice versa
+ case "x${target_symlinks}" in
+ x/software/*)
+ substitute-software "${target_symlinks}"
+ target_symlinks="$aliased_path"
+ if test ! -f "${web_root}${target_symlinks}"; then
+ type=no-symlinks
+ break
+ fi
+ target_directory=${target_symlinks/%.symlinks/}
+ ;;
+ x/savannah-checkouts/gnu*)
+ substitute-checkouts "${target_symlinks}"
+ target_symlinks="$aliased_path"
+ if test ! -f "${web_root}${target_symlinks}"; then
+ type=no-symlinks
+ break
+ fi
+ target_directory=${target_symlinks/%.symlinks/}
+ ;;
+ *)
+ type=no-symlinks
+ break
+ ;;
+ esac
+ fi
+
+ escaped_target=$(echo ${target} | ${SED} "s%.*/%%;s/\./\\\\./g")
+ if ! cleanup-symlinks "${web_root}${target_symlinks}" \
+ | grep -q "[[:blank:]]${escaped_target}$"; then
+ type=no-subsequent-link
+ break
+ fi
+ target=$(cleanup-symlinks "${web_root}${target_symlinks}" \
+ | ${SED} -n "s/[[:blank:]]${escaped_target}$//p")
+ link_depth=$(expr ${link_depth} + 1)
+ if test ${link_depth} -gt ${max_link_depth}; then
+ type=deep-link
+ break
+ fi
+ if test ${verbose} = yes; then
+ echo "go to the next target (depth ${link_depth}): ${target}"
+ fi
+ done # while true
+
+ # output the results of our link analysis
+ case ${type} in
+ file)
+ if (echo ${target} | grep -q "\.html$") \
+ && (echo ${link} | grep -q "\.html$"); then
+ echo ${symlinks_directory}${link} ${full_target} \
+ | ${SED} "s/\.html[[:blank:]]*/ /;s/\.html$//;\
+ ${normalize_link}" >> "${html_map_name}"
+ if test ${verbose} = yes; then
+ echo link to a HTML file found
+ fi
+ else
+ echo ${symlinks_directory}${link} ${full_target} \
+ | ${SED} "${normalize_link}" >> "${nonhtml_map_name}"
+ if test ${verbose} = yes; then
+ echo link to a non-HTML file found
+ fi
+ fi
+ ;;
+ directory | external)
+ echo ${symlinks_directory}${link} ${full_target} \
+ | ${SED} "${normalize_link}" >> "${dir_map_name}"
+ if test ${verbose} = yes; then
+ echo ${type} link found
+ fi
+ ;;
+ no-symlinks)
+ show-current-line
+ echo " ${target_symlinks} list"
+ echo " and ${target} file/directory are absent."
+ ;;
+ no-subsequent-link)
+ show-current-line
+ echo " ${target} file/directory is absent,"
+ echo " and no subsequent link in ${target_directory}.symlinks found."
+ ;;
+ deep-link)
+ show-current-line
+ echo " link depth limit ${max_link_depth} has been reached."
+ ;;
+ *)
+ show-current-line
+ echo " an unclassified error occurred."
+ exit 1
+ ;;
+ esac # case ${type} in
+ done # cleanup-symlinks "$1" -n | while read current_line; do
+}
+
+# Main program.
+
+if test "x${verbose}" != xyes; then
+ verbose=no
+fi
+
+html_map_name="${www_maps_dir}/${html_map_name}"
+nonhtml_map_name="${www_maps_dir}/${nonhtml_map_name}"
+dir_map_name="${www_maps_dir}/${dir_map_name}"
+
+# Initialize the output files.
+WARNING="# DO NOT EDIT, GENERATED by $0 `date`"
+echo ${WARNING} > "${html_map_name}"
+echo "# links to HTML files" >> "${html_map_name}"
+echo ${WARNING} > "${nonhtml_map_name}"
+echo "# links to non-HTML files" >> "${nonhtml_map_name}"
+echo ${WARNING} > "${dir_map_name}"
+echo "# links to directories and external links" >> "${dir_map_name}"
+
+# Scan every .symlinks file except
+# in non-gnu projects (they are managed with another script).
+${FIND} "${web_root}" -type f -name '.symlinks' \
+ ! -path "${web_root}/savannah-checkouts/non-gnu/*" \
+ -print \
+| while read next_file; do
+ append-symlinks ${next_file}
+ done
+
+# transform directory and external links into rewriterules
+${SED} -i '/^[^#]/ { h; s/ .*//;s/\./\\./g;
+ x; s/.* //; H; x; s/\n/ /;
+ s/ /((\/.*)?)$ /;
+ s/^/RewriteRule ^/;
+ s/ *$/$1 [R=302,L]/
+ }' "${dir_map_name}"