You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
93 lines
2.9 KiB
93 lines
2.9 KiB
#!/bin/bash |
|
|
|
action=$(basename $0) |
|
declare -a dirlist |
|
logfile=/tmp/push_pull.log |
|
rsync_options="--archive --perms --compress --delete-during --exclude=*.git* --exclude=git.code-workspace" |
|
|
|
case "$(hostname)" in |
|
pistache|noix|noisette) |
|
dirlist=( /datas/workspace /datas/git /datas/P1 /datas/P2 /datas/P3 /datas/P4 /datas/P5 /datas/P6 /datas/P7 /datas/rebuild ) |
|
;; |
|
queensland) |
|
dirlist=( /datas/workspace /datas/git /datas/P1 /datas/P2 /datas/P3 /datas/P4 /datas/P5 /datas/P6 ) |
|
;; |
|
pecan) |
|
dirlist=( /datas/workspace /datas/git /datas/P1 /datas/P2 /datas/P3 /datas/P4 /datas/P5 ) |
|
;; |
|
eee) |
|
dirlist=( /datas/workspace /datas/git /datas/P1 /datas/P2 /datas/P3 ) |
|
;; |
|
mllse) |
|
dirlist=( /datas/P1/KEEPASS /datas/P1/PARENTS /datas/P2/*_THUOT /datas/P6/*_THUOT ) |
|
;; |
|
*) |
|
dirlist=( /datas/worspace ) |
|
;; |
|
esac |
|
|
|
# dirlist=( /datas/P1 /datas/P2 /datas/P3 /datas/P4 /datas/P5 /datas/P6 /datas/P7 ) |
|
|
|
ask() { |
|
USER_ANSWER="?"; |
|
while [ "x$USER_ANSWER" != "xno" -a "x$USER_ANSWER" != "xnon" -a "x$USER_ANSWER" != "xyes" -a "$USER_ANSWER" != "xoui" ] ; do |
|
echo -n "$1 $2 $3 ? [yes/no] " |
|
read -n 3 USER_ANSWER |
|
echo ""; |
|
done |
|
if [ "x$USER_ANSWER" == "xyes" -o "x$USER_ANSWER" == "xoui" ] ; then |
|
return 0 |
|
else |
|
return 1 |
|
fi |
|
} |
|
|
|
echo "Snapshot git repositories (without history)" |
|
|
|
case "$(hostname)" in |
|
noix) |
|
[ -e ${logfile} ] && rm ${logfile} |
|
rsync --dry-run ${rsync_options} --exclude=*.terraform* --out-format="%B %l %M %f" /datas/git/* /datas/P1/git/ |tee ${logfile} |
|
if [ -s ${logfile} ] |
|
then |
|
if ask snapshot git repo /datas/git /datas/P1/git |
|
then |
|
rsync --verbose ${rsync_options} --exclude=*.terraform* /datas/git/* /datas/P1/git/ |
|
fi |
|
fi |
|
;; |
|
esac |
|
|
|
echo "List of files differences from master" |
|
|
|
for directory in ${dirlist[@]} |
|
do |
|
echo "check ${directory}" |
|
[ -w ${directory} ] || ( echo "${directory} is not writable" && exit 3 ) |
|
[ -e ${logfile} ] && rm ${logfile} |
|
case "${action}" in |
|
pull) |
|
rsync --dry-run ${rsync_options} --out-format="%B %l %M %f" banana:${directory}/ ${directory} |tee ${logfile} |
|
[ -s ${logfile} ] || continue |
|
if ask rsync banana:${directory}/ ${directory} |
|
then |
|
echo "rsync --verbose ${rsync_options} banana:${directory}/ ${directory}" |
|
rsync --verbose ${rsync_options} banana:${directory}/ ${directory} |
|
fi |
|
;; |
|
push) |
|
rsync --dry-run ${rsync_options} --out-format="%B %l %M %f" ${directory}/ banana:${directory} |tee ${logfile} |
|
[ -s ${logfile} ] || continue |
|
if ask rsync ${directory}/ banana:${directory} |
|
then |
|
echo "rsync --verbose ${rsync_options} ${directory}/ banana:${directory}" |
|
rsync --verbose ${rsync_options} ${directory}/ banana:${directory} |
|
fi |
|
;; |
|
*) |
|
echo "command ${command} is unknown ... push or pull ??" |
|
exit 2 |
|
;; |
|
esac |
|
done |
|
|
|
|