vcs-backup.sh
branchv_0
changeset 2 4c9994be0688
parent 0 6207c211aafd
child 3 1c7536a0beda
     1.1 --- a/vcs-backup.sh	Thu Apr 18 21:16:33 2019 +0200
     1.2 +++ b/vcs-backup.sh	Fri Apr 19 16:53:22 2019 +0200
     1.3 @@ -20,6 +20,7 @@
     1.4  # Server-side configuration:
     1.5  VCS_BACKUP_DATA_DIR="/mnt/data";
     1.6  VCS_BACKUP_CURRENT_DIR="$VCS_BACKUP_DATA_DIR/current";
     1.7 +VCS_BACKUP_PUBLIC_DIR="$VCS_BACKUP_DATA_DIR/public";
     1.8  VCS_BACKUP_CONFIG_DIR="$VCS_BACKUP_DATA_DIR/config";
     1.9  VCS_BACKUP_SNAPSHOT_DIR="$VCS_BACKUP_DATA_DIR/snapshot";
    1.10  VCS_BACKUP_SUBVOLUME_SOCKET="/run/vcs-backup-subvolume";
    1.11 @@ -65,31 +66,34 @@
    1.12  # Environment: client
    1.13  # $1 = VCS type: hg, git
    1.14  # $2 = URL
    1.15 +# $3 = "public" or "private" (default), whether the repository should be available through the public web interface
    1.16  vcs_backup_public_clientSubmitBackupRequest() {
    1.17  	if isValidTypeAndURL "$1" "$2"; then
    1.18  		loadConfigFile ~/.config/vcs-backup/client.cfg
    1.19 -		${VCS_BACKUP_SSH_COMMAND[@]} vcs-backup.sh serverSubmitBackupRequest "$1" "$2"
    1.20 +		${VCS_BACKUP_SSH_COMMAND[@]} vcs-backup.sh serverSubmitBackupRequest "$1" "$2" "$3"
    1.21  	else
    1.22  		echo "Unsupported VCS type: '$1' or URL: '$2'" >&2;
    1.23  	fi
    1.24  }
    1.25  
    1.26  # Environment: server
    1.27 -# $1 = VCS type: hg, git
    1.28 -# $2 = URL
    1.29 +# has same parameters as clientSubmitBackupRequest (see above)
    1.30  vcs_backup_public_serverSubmitBackupRequest() {
    1.31  	if isValidTypeAndURL "$1" "$2"; then
    1.32  		loadConfigFile "/etc/vcs-backup/server.cfg";
    1.33  		relativePath=$1/$(urlToRelativeDirectoryPath "$2");
    1.34  		absolutePath="$VCS_BACKUP_CONFIG_DIR/$relativePath";
    1.35  		mkdir -p "$absolutePath";
    1.36 -		echo "$1" > "$absolutePath/type.txt"
    1.37  		echo "$2" > "$absolutePath/url.txt"
    1.38  		echo "submited" > "$absolutePath/state.txt"
    1.39 -		setfacl -m u:${VCS_BACKUP_USER}:r  "$absolutePath/type.txt"
    1.40  		setfacl -m u:${VCS_BACKUP_USER}:r  "$absolutePath/url.txt"
    1.41  		setfacl -m u:${VCS_BACKUP_USER}:rw "$absolutePath/state.txt"
    1.42  		echo "$relativePath" | socat -u - unix-send:${VCS_BACKUP_SUBVOLUME_SOCKET};
    1.43 +		if [[ "$3" == "public" ]]; then
    1.44 +			cd "$VCS_BACKUP_PUBLIC_DIR";
    1.45 +			mkdir -p "$(dirname $relativePath)";
    1.46 +			ln -rs "../current/$relativePath" "$(dirname $relativePath)";
    1.47 +		fi
    1.48  	else
    1.49  		echo "Unsupported VCS type: '$1' or URL: '$2'" >&2;
    1.50  	fi
    1.51 @@ -114,8 +118,7 @@
    1.52  # should be started as a systemd/init service
    1.53  vcs_backup_public_serverStartCloneService() {
    1.54  	socat -u "unix-recv:${VCS_BACKUP_CLONE_SOCKET},mode=700" - | while read d; do
    1.55 -		# FIXME: hg vs. git, clone
    1.56 -		vcsType=$(cat "$VCS_BACKUP_CONFIG_DIR/$d/type.txt");
    1.57 +		vcsType=$(echo "$d" | sed 's@/.*@@g');
    1.58  		url=$(cat "$VCS_BACKUP_CONFIG_DIR/$d/url.txt");
    1.59  		if isValidTypeAndURL "$vcsType" "$url"; then
    1.60  			if   [[ "$vcsType" == "hg"  ]]; then  hg clone -U     "$url" "$VCS_BACKUP_CURRENT_DIR/$d";