#!/bin/bash # update-sym-links - Symlink latest versions in parent folders # # Copyright 2023 Corwin Brust # # This program is distributed under the terms of the GNU Public # License version 3 or (at your option) any later version. # BASE=/home/dh_aw28jd/corwin-emacs DIRS="emacs-30 emacs-31 emacs-32" PKGS="-installer.exe .zip -no-deps.zip -src.zip -sha256sums.txt" FOUND= for DIR in $DIRS ; do #find emacs-29/* -type d -print0 | xargs -0 stat --format '%Y :%y %n' | sort -nr | cut -d: -f2- | head -1 | cut -d / -f 2 LATEST=$( ls -t $BASE/$DIR | grep -v 'latest' | grep "^$DIR" | head -1 ) HTACCESS=$BASE/$DIR/.htaccess echo ' deny from all ' > $HTACCESS # remove AddDescription lines from .htaccess cat $HTACCESS | grep -v ^AddDescription >> $HTACCESS BL="$BASE/$DIR/$LATEST" if [[ -r $BL ]] ; then BN="${BASE}/${DIR}" ln -sfT $BL $BN/${DIR}-latest MOD=$( perl -MPOSIX=strftime -le \ "print strftime('%F.%H',localtime [stat shift]->[9])" \ $BN/${DIR}-latest) FOUND="{\"branch\":\"$DIR\",\"latest\":\"$LATEST\",\"date\":\"$MOD\"} $FOUND" # put an invarient link to the latest of each kind in each root for FILE in $PKGS ; do LINK=$( ls -1 ${BL}/*${FILE} ) NAME="${BN}/${DIR}-latest${FILE}" #echo "$DIR $FILE $LINK" if [[ -r $LINK ]] ; then ln -fT $LINK $NAME #ln -fT $LINK.sig $NAME.sig #NOEXT=$(echo $FILE | perl -pne 's/^(?:\.|-)//; s/\..*$//g') #BASENAME=$(basename $LINK) echo "AddDescription \"$(basename $LINK)\" $(basename $NAME)\$" >>$HTACCESS else rm -f $NAME #rm -f $NAME.sig fi done echo "AddDescription \"latest: $LATEST\" ${DIR}-latest\$" >>$HTACCESS #echo "$DIR $LATEST" else echo "WARNING: No latest version found for $DIR" fi done (TOTAL=0 for JSON in $FOUND ; do TOTAL=$((TOTAL+1)) ; done COUNT=0 (echo -n "[" for JSON in $FOUND ; do echo -n "$JSON"; COUNT=$((COUNT+1)) if [[ $COUNT -ne $TOTAL ]] ; then echo -n ", " fi done echo "]")) | tee $BASE/emacs-latest.json (echo -n "// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-v3-or-Later document.emacsVersionData = "; \ cat $BASE/emacs-latest.json ; \ echo "// @license-end" ) | tee $BASE/emacs-latest.js