Advertisement
dsonbill

DMPServer Bash Updater

Sep 8th, 2014
824
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.99 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # LICENSE: SEE http://forum.kerbalspaceprogram.com/threads/92665-DMP-Linux-Server-Tools
  4.  
  5. # Config
  6. . /etc/dmpserver/dmpserver.cfg
  7.  
  8. # Lib
  9. . /var/lib/dmpserver/dmpbashlib
  10.  
  11.  
  12. # Check for root
  13. rootCheck
  14.  
  15.  
  16. ## Hash Functions
  17.  
  18. function buildHashList(){
  19.     curr_hash=()
  20.    
  21.     echo "Building Hash List"
  22.     h=0
  23.     for name in ${name_list[@]} ; do
  24.         curr_hash[$h]=$(sha256sum $DMPBIN/$name | awk -F " " '{print $1}')
  25.         ((h++))
  26.     done
  27. }
  28.  
  29. function checkFileFreshness(){
  30.     diff_res=()
  31.    
  32.     echo "Getting File Freshness"
  33.     h=0
  34.     for hash in ${curr_hash[@]} ; do
  35.         diff <(echo $hash) <(echo ${hash_list[$h]}) &> /dev/null
  36.         diff_res[$h]="$?"
  37.         ((h++))
  38.     done
  39. }
  40.  
  41.  
  42. ## Functions
  43. function dmpDirExists(){
  44.     dirExistTest $DMPBIN
  45.     if [ $RETVAL == "False" ] ; then
  46.         echo -e "${formatWarn}'$DMPBIN' does not exist! Please install with DMP Linux Tools,${formatEnd}"
  47.         echo -e "${formatWarn}create the directory with the proper permissions, or modify the${formatEnd}"
  48.         echo -e "${formatWarn}DMP binary install directory.${formatEnd}"
  49.         exit 2
  50.     fi
  51. }
  52.  
  53. function buildTargetLists(){
  54.     echo "Generating Target Lists"
  55.     getTargetNames $REPOindex
  56.     name_list=("${RETVAL[@]}")
  57.     getTargetHashes $REPOindex
  58.     hash_list=("${RETVAL[@]}")
  59. }
  60.  
  61. function checkTargetInstall(){
  62.     echo "Generating Missing Files"
  63.     for name in ${name_list[@]} ; do
  64.         fileExistTest $DMPBIN/$name
  65.         if [ ! $RETVAL == "True" ] ; then
  66.             # Make Missing File
  67.             echo "Adding missing file $name"
  68.             touch $DMPBIN/$name
  69.         fi
  70.     done
  71. }
  72.  
  73. function updateOutdatedFiles(){
  74.     echo
  75.     echo
  76.     echo "Beginning DMPServer Update."
  77.     echo
  78.    
  79.     environment_dirs=`ls -l --time-style="long-iso" $DMPDIR | egrep '^d' | awk '{print $8}'`
  80.     for env_dir in $environment_dirs ; do
  81.         dmpserver $env_dir stop-fast
  82.     done
  83.  
  84.  
  85.     findex=0
  86.     for res in ${diff_res[@]} ; do
  87.         if [ $res -eq 1 ];
  88.         then
  89.             echo "Updating ${name_list[$findex]}..."
  90.             curl --progress-bar $REPOobj/${hash_list[${findex}]} > $DMPBIN/${name_list[${findex}]}
  91.             echo -e "${name_list[${findex}]} Update is ${formatDone} DONE ${formatEnd}"
  92.         elif [ $res -eq 0 ];
  93.         then
  94.             echo -e "File ${name_list[${findex}]} is ${formatDone}up-to-date${formatEnd}."
  95.         else
  96.             echo "Something went wrong when updating! diff gave exit code of: $res ."
  97.             echo "Updater was expecting a 0 (up-to-date) or a 1 (out-of-date)."
  98.         fi
  99.         ((findex++))
  100.     done
  101.  
  102.  
  103.     echo "Updating DMPServer environment links."
  104.    
  105.     for env_dir in $environment_dirs ; do
  106.         dmpenv update $env_dir
  107.         dmpserver $env_dir start
  108.     done
  109.  
  110.    
  111.     echo
  112.     echo "DMPServer Update Completed."
  113. }
  114.  
  115.  
  116. ## Execution
  117. dmpDirExists
  118.  
  119. buildTargetLists
  120.  
  121. checkTargetInstall
  122.  
  123. buildHashList
  124.  
  125. checkFileFreshness
  126.  
  127. updateOutdatedFiles
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement