123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- #!/bin/bash
- set -e;
- if [[ "$1" != "" ]];then
- host_to_sync="$1";
- force=true;
- else
- force=false;
- fi;
- root="$(readlink -f $(dirname $BASH_SOURCE)/..)";
- . $root/etc/repo.conf
- . $root/etc/sites.conf
- for val in "${sites[@]}"; do
- unset site;
- declare -A site;
- eval "site=($val)";
- host=${site[host]};
- user=${site[username]};
- if ! $force || [[ "$host_to_sync" == "all" ]] || [[ "$host_to_sync" == "$user@$host" ]];then
- echo "Updating $user@$host";
- case ${site[type]} in
- rsync)
- rsyncd(){
- echo -e "\t\tSyncing $1";
- ARGS="-rzvlhe ssh --progress --stats --exclude=\".gitignore\" $1 $user@$host:${site[root]}";
- FILES=$(expect -c "
- set timeout -1
- log_user 1
- spawn rsync --dry-run $ARGS;
- expect {
- \"yes/no\" {
- send yes\r
- exp_continue
- }
- password: {
- log_user 0;
- send $(echo ${site[password]} | base64 --decode | gpg -d -q --no-mdc-warning)\r;
- log_user 1;
- exp_continue
- }
- eof {
- exit
- }
- }
- " | grep "^Number of regular files transferred:" | awk '{print $6}');
- if [[ "$FILES" == "" ]]; then
- FILES="0";
- fi;
- echo -e "\t\t\tFiles to transfer: $FILES";
- expect -c "
- set timeout -1
- set count 0
- log_user 0
- spawn rsync $ARGS;
- expect {
- to-chk {
- set count \"[expr \$count + 1]\"
- send_user \"\t\t\t\tDone \";
- send_user \$count;
- send_user \"/$FILES\n\";
- exp_continue
- }
- yes/no {
- send yes\r
- exp_continue
- }
- password: {
- log_user 0;
- send $(echo ${site[password]} | base64 --decode | gpg -d -q --no-mdc-warning)\r;
- send_user \"\t\t\tLogged In\n\"
- exp_continue
- }
- eof {
- send_user \"\t\t\tDone\n\"
- exit
- }
- }
- send_user \"\t\tTimed Out\n\"
- ";
- }
- echo -e "\tUploading files to ${site[root]}";
- rsyncd $root/skel/;
- rsyncd $root/repo/latest/;
- echo -e "\tDone.";
- ;;
- ssh)
- escp(){
- length=$(($#-1));
- files=${@:1:$length};
- expect -c "
- set timeout 1
- log_user 0
- spawn scp -r $files \"$user@$host:${site[root]}/${!#}\"
- expect {
- yes/no {
- send yes\r;
- exp_continue
- }
- password: {
- send $(echo ${site[password]} | base64 --decode | gpg -d -q --no-mdc-warning)\r
- set timeout -1
- }
- eof {
- exit
- }
- }";
- }
- essh(){
- args="$@";
- expect -c "
- set timeout 1
- log_user 0
- spawn ssh $user@$host $args
- expect {
- yes/no {
- send yes\r;
- exp_continue
- }
- password: {
- send $(echo ${site[password]} | base64 --decode | gpg -d -q --no-mdc-warning)\r
- set timeout -1
- }
- eof {
- exit
- }
- }";
- }
- upload_local_dir(){
- find $root/$1 -mindepth 1 | while read file; do
- if [ -f "$file" ] && [[ "$(basename $file)" != '.gitignore' ]] && [[ "$(basename $file)" != '$reponame.db' ]];then
- echo -e "\t\tF: $(basename $file)";
- nfile=${file:((${#root}+${#1}+2))};
- escp $file $nfile;
- elif [ -d "$file" ];then
- file=${file:((${#root}+${#1}+2))};
- echo -e "\t\tD: $file";
- essh mkdir -p ${site[root]}/$2/$file;
- fi;
- done;
- }
- echo -e "\tUploading files to ${site[root]}";
- essh mkdir -p ${site[root]}/;
- upload_local_dir skel;
- if $force; then
- upload_local_dir repo/latest;
- else
- upload_local_dir repo/updates;
- ls -l $root/repo/latest/ | egrep '^d' | awk '{print $9}' | while read arch; do
- if [ -d "$root/repo/latest/$arch" ];then
- escp $root/repo/latest/$arch/$reponame.db.tar.gz /$arch/$reponame.db.tar.gz;
- essh cd ${site[root]}/$arch && rm -f $reponame.db && ln -s $reponame.db.tar.gz $reponame.db;
- fi;
- done;
- fi;
- echo -e "\tDone.";
- ;;
- *)
- echo -e "\tType '${site[type]}' not implemented.";
- esac;
- fi;
- done;
- if ! $force; then
- ls -l $root/repo/updates/ | egrep '^d' | awk '{print $9}' | while read arch; do
- rm -f $root/repo/updates/$arch/*.pkg.tar.xz;
- done;
- fi;
|