do pull while submitting already configured repository v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Wed, 24 Apr 2019 16:59:17 +0200
branchv_0
changeset 19d7978ca64a20
parent 18 9353b2531cda
child 20 8cd5d49dfaa2
do pull while submitting already configured repository
vcs-backup.sh
     1.1 --- a/vcs-backup.sh	Tue Apr 23 17:56:16 2019 +0200
     1.2 +++ b/vcs-backup.sh	Wed Apr 24 16:59:17 2019 +0200
     1.3 @@ -170,16 +170,13 @@
     1.4  	socat -u "unix-recv:${VCS_BACKUP_SUBVOLUME_SOCKET},group=${VCS_BACKUP_MANAGER},mode=770" - | while read d; do
     1.5  		mkdir -p $(dirname "$VCS_BACKUP_CURRENT_DIR/$d");
     1.6  		if [[ -e "$VCS_BACKUP_CURRENT_DIR/$d" ]]; then
     1.7 -			callBackSocket="$VCS_BACKUP_CONFIG_DIR/$d/$VCS_BACKUP_CLONE_CALLBACK_SOCKET";
     1.8 -			if [[ -e "$callBackSocket" ]]; then
     1.9 -				echo "alreadyDone" | socat -u - unix-send:"$callBackSocket";
    1.10 -			fi
    1.11 +			echo "cloned" > "$VCS_BACKUP_CONFIG_DIR/$d/state.txt";
    1.12  		else
    1.13  			btrfs subvolume create "$VCS_BACKUP_CURRENT_DIR/$d" && \
    1.14  			echo "subvolumeCreated" > "$VCS_BACKUP_CONFIG_DIR/$d/state.txt" && \
    1.15 -			chown "${VCS_BACKUP_USER}:${VCS_BACKUP_USER}" "$VCS_BACKUP_CURRENT_DIR/$d" && \
    1.16 -			echo "$d" | socat -u - unix-send:${VCS_BACKUP_CLONE_SOCKET};
    1.17 +			chown "${VCS_BACKUP_USER}:${VCS_BACKUP_USER}" "$VCS_BACKUP_CURRENT_DIR/$d"
    1.18  		fi
    1.19 +		echo "$d" | socat -u - unix-send:${VCS_BACKUP_CLONE_SOCKET};
    1.20  	done
    1.21  }
    1.22  
    1.23 @@ -190,11 +187,20 @@
    1.24  	socat -u "unix-recv:${VCS_BACKUP_CLONE_SOCKET},mode=700" - | while read d; do
    1.25  		vcsType=$(echo "$d" | sed 's@/.*@@g');
    1.26  		url=$(cat "$VCS_BACKUP_CONFIG_DIR/$d/url.txt");
    1.27 +		state=$(cat "$VCS_BACKUP_CONFIG_DIR/$d/state.txt");
    1.28  
    1.29  		if isValidTypeAndURL "$vcsType" "$url"; then
    1.30 -			if   [[ "$vcsType" == "hg"  ]]; then  hg clone -U       "$url" "$VCS_BACKUP_CURRENT_DIR/$d";
    1.31 -			elif [[ "$vcsType" == "git" ]]; then git clone --mirror "$url" "$VCS_BACKUP_CURRENT_DIR/$d";
    1.32 -			fi && echo "cloned" > "$VCS_BACKUP_CONFIG_DIR/$d/state.txt";
    1.33 +			if [[ "$state" == "cloned"  ]]; then
    1.34 +				# Already cloned repository → just pull
    1.35 +				if   [[ "$vcsType" == "hg"  ]]; then hg -R "$VCS_BACKUP_CURRENT_DIR/$d" pull;
    1.36 +				elif [[ "$vcsType" == "git" ]]; then git -C "$VCS_BACKUP_CURRENT_DIR/$d" fetch;
    1.37 +				fi
    1.38 +			else
    1.39 +				# New repository → clone
    1.40 +				if   [[ "$vcsType" == "hg"  ]]; then  hg clone -U       "$url" "$VCS_BACKUP_CURRENT_DIR/$d";
    1.41 +				elif [[ "$vcsType" == "git" ]]; then git clone --mirror "$url" "$VCS_BACKUP_CURRENT_DIR/$d";
    1.42 +				fi && echo "cloned" > "$VCS_BACKUP_CONFIG_DIR/$d/state.txt";
    1.43 +			fi
    1.44  		else
    1.45  			echo "Unsupported VCS type: '$vcsType' or URL: '$url'" >&2;
    1.46  		fi