diff -r 9a2e2812c319 -r 4c9994be0688 vcs-backup.sh --- a/vcs-backup.sh Thu Apr 18 21:16:33 2019 +0200 +++ b/vcs-backup.sh Fri Apr 19 16:53:22 2019 +0200 @@ -20,6 +20,7 @@ # Server-side configuration: VCS_BACKUP_DATA_DIR="/mnt/data"; VCS_BACKUP_CURRENT_DIR="$VCS_BACKUP_DATA_DIR/current"; +VCS_BACKUP_PUBLIC_DIR="$VCS_BACKUP_DATA_DIR/public"; VCS_BACKUP_CONFIG_DIR="$VCS_BACKUP_DATA_DIR/config"; VCS_BACKUP_SNAPSHOT_DIR="$VCS_BACKUP_DATA_DIR/snapshot"; VCS_BACKUP_SUBVOLUME_SOCKET="/run/vcs-backup-subvolume"; @@ -65,31 +66,34 @@ # Environment: client # $1 = VCS type: hg, git # $2 = URL +# $3 = "public" or "private" (default), whether the repository should be available through the public web interface vcs_backup_public_clientSubmitBackupRequest() { if isValidTypeAndURL "$1" "$2"; then loadConfigFile ~/.config/vcs-backup/client.cfg - ${VCS_BACKUP_SSH_COMMAND[@]} vcs-backup.sh serverSubmitBackupRequest "$1" "$2" + ${VCS_BACKUP_SSH_COMMAND[@]} vcs-backup.sh serverSubmitBackupRequest "$1" "$2" "$3" else echo "Unsupported VCS type: '$1' or URL: '$2'" >&2; fi } # Environment: server -# $1 = VCS type: hg, git -# $2 = URL +# has same parameters as clientSubmitBackupRequest (see above) vcs_backup_public_serverSubmitBackupRequest() { if isValidTypeAndURL "$1" "$2"; then loadConfigFile "/etc/vcs-backup/server.cfg"; relativePath=$1/$(urlToRelativeDirectoryPath "$2"); absolutePath="$VCS_BACKUP_CONFIG_DIR/$relativePath"; mkdir -p "$absolutePath"; - echo "$1" > "$absolutePath/type.txt" echo "$2" > "$absolutePath/url.txt" echo "submited" > "$absolutePath/state.txt" - setfacl -m u:${VCS_BACKUP_USER}:r "$absolutePath/type.txt" setfacl -m u:${VCS_BACKUP_USER}:r "$absolutePath/url.txt" setfacl -m u:${VCS_BACKUP_USER}:rw "$absolutePath/state.txt" echo "$relativePath" | socat -u - unix-send:${VCS_BACKUP_SUBVOLUME_SOCKET}; + if [[ "$3" == "public" ]]; then + cd "$VCS_BACKUP_PUBLIC_DIR"; + mkdir -p "$(dirname $relativePath)"; + ln -rs "../current/$relativePath" "$(dirname $relativePath)"; + fi else echo "Unsupported VCS type: '$1' or URL: '$2'" >&2; fi @@ -114,8 +118,7 @@ # should be started as a systemd/init service vcs_backup_public_serverStartCloneService() { socat -u "unix-recv:${VCS_BACKUP_CLONE_SOCKET},mode=700" - | while read d; do - # FIXME: hg vs. git, clone - vcsType=$(cat "$VCS_BACKUP_CONFIG_DIR/$d/type.txt"); + vcsType=$(echo "$d" | sed 's@/.*@@g'); url=$(cat "$VCS_BACKUP_CONFIG_DIR/$d/url.txt"); if isValidTypeAndURL "$vcsType" "$url"; then if [[ "$vcsType" == "hg" ]]; then hg clone -U "$url" "$VCS_BACKUP_CURRENT_DIR/$d";