optional callback → local clone v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Fri, 19 Apr 2019 17:52:37 +0200
branchv_0
changeset 31c7536a0beda
parent 2 4c9994be0688
child 4 1539711d8657
optional callback → local clone
vcs-backup.sh
     1.1 --- a/vcs-backup.sh	Fri Apr 19 16:53:22 2019 +0200
     1.2 +++ b/vcs-backup.sh	Fri Apr 19 17:52:37 2019 +0200
     1.3 @@ -25,6 +25,7 @@
     1.4  VCS_BACKUP_SNAPSHOT_DIR="$VCS_BACKUP_DATA_DIR/snapshot";
     1.5  VCS_BACKUP_SUBVOLUME_SOCKET="/run/vcs-backup-subvolume";
     1.6  VCS_BACKUP_CLONE_SOCKET="/run/vcs-backup-clone";
     1.7 +VCS_BACKUP_CLONE_CALLBACK_SOCKET="clone-callback";
     1.8  VCS_BACKUP_USER="vcs-backup";
     1.9  VCS_BACKUP_MANAGER="vcs-backup-manager";
    1.10  
    1.11 @@ -70,7 +71,12 @@
    1.12  vcs_backup_public_clientSubmitBackupRequest() {
    1.13  	if isValidTypeAndURL "$1" "$2"; then
    1.14  		loadConfigFile ~/.config/vcs-backup/client.cfg
    1.15 -		${VCS_BACKUP_SSH_COMMAND[@]} vcs-backup.sh serverSubmitBackupRequest "$1" "$2" "$3"
    1.16 +		${VCS_BACKUP_SSH_COMMAND[@]} vcs-backup.sh serverSubmitBackupRequest "$1" "$2" "$3" "$4"
    1.17 +		if [[ "$4" == "clone" ]]; then
    1.18 +			if   [[ "$1" == "hg"  ]]; then  hg clone "ssh://${VCS_BACKUP_SERVER}//mnt/data/current/$1/$(urlToRelativeDirectoryPath $2)";
    1.19 +			elif [[ "$1" == "git" ]]; then git clone "ssh://${VCS_BACKUP_SERVER}//mnt/data/current/$1/$(urlToRelativeDirectoryPath $2)";
    1.20 +			fi
    1.21 +		fi
    1.22  	else
    1.23  		echo "Unsupported VCS type: '$1' or URL: '$2'" >&2;
    1.24  	fi
    1.25 @@ -89,11 +95,18 @@
    1.26  		setfacl -m u:${VCS_BACKUP_USER}:r  "$absolutePath/url.txt"
    1.27  		setfacl -m u:${VCS_BACKUP_USER}:rw "$absolutePath/state.txt"
    1.28  		echo "$relativePath" | socat -u - unix-send:${VCS_BACKUP_SUBVOLUME_SOCKET};
    1.29 +
    1.30  		if [[ "$3" == "public" ]]; then
    1.31  			cd "$VCS_BACKUP_PUBLIC_DIR";
    1.32  			mkdir -p "$(dirname $relativePath)";
    1.33  			ln -rs "../current/$relativePath" "$(dirname $relativePath)";
    1.34  		fi
    1.35 +
    1.36 +		if [[ "$4" == "clone" ]]; then
    1.37 +			socat -u "unix-recvfrom:$absolutePath/${VCS_BACKUP_CLONE_CALLBACK_SOCKET},mode=777" - | while read m; do # TODO: ,group=${VCS_BACKUP_USER} and no 777
    1.38 +				echo "Message from the clone service: $m";
    1.39 +			done;
    1.40 +		fi
    1.41  	else
    1.42  		echo "Unsupported VCS type: '$1' or URL: '$2'" >&2;
    1.43  	fi
    1.44 @@ -120,6 +133,7 @@
    1.45  	socat -u "unix-recv:${VCS_BACKUP_CLONE_SOCKET},mode=700" - | while read d; do
    1.46  		vcsType=$(echo "$d" | sed 's@/.*@@g');
    1.47  		url=$(cat "$VCS_BACKUP_CONFIG_DIR/$d/url.txt");
    1.48 +
    1.49  		if isValidTypeAndURL "$vcsType" "$url"; then
    1.50  			if   [[ "$vcsType" == "hg"  ]]; then  hg clone -U     "$url" "$VCS_BACKUP_CURRENT_DIR/$d";
    1.51  			elif [[ "$vcsType" == "git" ]]; then git clone --bare "$url" "$VCS_BACKUP_CURRENT_DIR/$d";
    1.52 @@ -127,7 +141,11 @@
    1.53  		else
    1.54  			echo "Unsupported VCS type: '$vcsType' or URL: '$url'" >&2;
    1.55  		fi
    1.56 -		# TODO: call-back to the client if client is waiting (socket exist in the config dir)
    1.57 +
    1.58 +		callBackSocket="$VCS_BACKUP_CONFIG_DIR/$d/$VCS_BACKUP_CLONE_CALLBACK_SOCKET";
    1.59 +		if [[ -e "$callBackSocket" ]]; then
    1.60 +			echo "done" | socat -u - unix-send:"$callBackSocket";
    1.61 +		fi
    1.62  	done
    1.63  }
    1.64