Created
August 18, 2021 19:04
-
-
Save sid22/5e506dc9d8b335523947ec3228698b8f to your computer and use it in GitHub Desktop.
Sync Local and VM Git Repos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
POSITIONAL=() | |
while [[ $# -gt 0 ]]; do | |
key="$1" | |
case $key in | |
-l|--localpath) | |
LCPATH="$2" | |
shift # past argument | |
shift # past value | |
;; | |
-r|--remotepath) | |
REMPATH="$2" | |
shift # past argument | |
shift # past value | |
;; | |
-u|--sshuser) | |
USER="$2" | |
shift # past argument | |
shift # past value | |
;; | |
-h|--sshhost) | |
HOST="$2" | |
shift # past argument | |
shift # past value | |
;; | |
--default) | |
DEFAULT=YES | |
shift # past argument | |
;; | |
*) # unknown option | |
POSITIONAL+=("$1") # save it in an array for later | |
shift # past argument | |
;; | |
esac | |
done | |
set -- "${POSITIONAL[@]}" # restore positional parameters | |
echo "local_base_path: $LCPATH"; | |
echo "vm_base_path: $REMPATH"; | |
echo "ssh_user: $USER"; | |
echo "ssh_host: $HOST"; | |
my_array=( $(git status --porcelain=v2) ) | |
idx=0 | |
for element in "${my_array[@]}" | |
do | |
rem=$(( $idx % 2 )) | |
if [ $rem -ne 0 ] | |
then | |
scp_cmd="scp ${local_base_path}/${element} ${ssh_user}@${ssh_host}:${vm_base_path}/{${element}" | |
echo "${scp_cmd}" | |
#echo "${element}" | |
fi | |
idx=$(($idx+1)) | |
done | |
bash tr3.sh -l /home/f1 -r /home/f2/f3 -u ubuntu -h 10.10.100.1 | |
bash tr3.sh -l=/home/f1 -r=/home/f2/f3 -u=ubuntu -h=10.10.100.1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment