repo-update 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #!/bin/bash
  2. set -e;
  3. if [[ "$1" != "" ]];then
  4. host_to_sync="$1";
  5. force=true;
  6. else
  7. force=false;
  8. fi;
  9. root="$(readlink -f $(dirname $BASH_SOURCE)/..)";
  10. . $root/etc/repo.conf
  11. . $root/etc/sites.conf
  12. for val in "${sites[@]}"; do
  13. unset site;
  14. declare -A site;
  15. eval "site=($val)";
  16. host=${site[host]};
  17. user=${site[username]};
  18. if ! $force || [[ "$host_to_sync" == "all" ]] || [[ "$host_to_sync" == "$user@$host" ]];then
  19. echo "Updating $user@$host";
  20. case ${site[type]} in
  21. ssh)
  22. escp(){
  23. length=$(($#-1));
  24. files=${@:1:$length};
  25. expect -c "
  26. set timeout 1
  27. log_user 0
  28. spawn scp -r $files \"$user@$host:${site[root]}/${!#}\"
  29. expect yes/no { send yes\r ; exp_continue }
  30. expect password: {
  31. send $(echo ${site[password]} | base64 --decode | gpg -d -q --no-mdc-warning)\r
  32. set timeout -1
  33. }
  34. expect eof {
  35. exit
  36. }";
  37. }
  38. essh(){
  39. args="$@";
  40. expect -c "
  41. set timeout 1
  42. log_user 0
  43. spawn ssh $user@$host $args
  44. expect yes/no { send yes\r ; exp_continue }
  45. expect password: {
  46. send $(echo ${site[password]} | base64 --decode | gpg -d -q --no-mdc-warning)\r
  47. set timeout -1
  48. }
  49. expect eof {
  50. exit
  51. }";
  52. }
  53. upload_local_dir(){
  54. find $root/$1 -mindepth 1 | while read file; do
  55. if [ -f "$file" ] && [[ "$(basename $file)" != '.gitignore' ]] && [[ "$(basename $file)" != '$reponame.db' ]];then
  56. echo -e "\t\tF: $(basename $file)";
  57. nfile=${file:((${#root}+${#1}+2))};
  58. escp $file $nfile;
  59. elif [ -d "$file" ];then
  60. file=${file:((${#root}+${#1}+2))};
  61. echo -e "\t\tD: $file";
  62. essh mkdir -p ${site[root]}/$2/$file;
  63. fi;
  64. done;
  65. }
  66. echo -e "\tUploading files to ${site[root]}";
  67. essh mkdir -p ${site[root]}/;
  68. upload_local_dir skel;
  69. if $force; then
  70. upload_local_dir repo/latest;
  71. else
  72. upload_local_dir repo/updates;
  73. ls -l $root/repo/latest/ | egrep '^d' | awk '{print $9}' | while read arch; do
  74. if [ -d "$root/repo/latest/$arch" ];then
  75. escp $root/repo/latest/$arch/$reponame.db.tar.gz /$arch/$reponame.db.tar.gz;
  76. essh cd ${site[root]}/$arch && rm -f $reponame.db && ln -s $reponame.db.tar.gz $reponame.db;
  77. fi;
  78. done;
  79. fi;
  80. echo -e "\tDone.";
  81. ;;
  82. *)
  83. echo -e "\tType '${site[type]}' not implemented.";
  84. esac;
  85. fi;
  86. done;
  87. if ! $force; then
  88. ls -l $root/repo/updates/ | egrep '^d' | awk '{print $9}' | while read arch; do
  89. rm -f $root/repo/updates/$arch/*.pkg.tar.xz;
  90. done;
  91. fi;