AlexanderNorup

CleanChat-AutoClearChannel AutoUpdate script

Mar 29th, 2020
402
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env bash
  2.  
  3. #SETTINGS
  4.  
  5. DLL="CleanChat-AutoClearChannel.dll"
  6. VERSION_URL="http://drive.alexandernorup.com/CleanChat/latest.txt"
  7. DOWNLOAD_URL="http://drive.alexandernorup.com/CleanChat/latest.zip"
  8.  
  9.  
  10. #Thanks to "Paused until further notice." on Stackoverflow <3
  11. #https://stackoverflow.com/a/4025065
  12. vercomp () {
  13.     if [[ $1 == $2 ]]
  14.     then
  15.         return 0
  16.     fi
  17.     local IFS=.
  18.     local i ver1=($1) ver2=($2)
  19.     # fill empty fields in ver1 with zeros
  20.     for ((i=${#ver1[@]}; i<${#ver2[@]}; i++))
  21.     do
  22.         ver1[i]=0
  23.     done
  24.     for ((i=0; i<${#ver1[@]}; i++))
  25.     do
  26.         if [[ -z ${ver2[i]} ]]
  27.         then
  28.             # fill empty fields in ver2 with zeros
  29.             ver2[i]=0
  30.         fi
  31.         if ((10#${ver1[i]} > 10#${ver2[i]}))
  32.         then
  33.             return 1
  34.         fi
  35.         if ((10#${ver1[i]} < 10#${ver2[i]}))
  36.         then
  37.             return 2
  38.         fi
  39.     done
  40.     return 0
  41. }
  42.  
  43. testvercomp () {
  44.     vercomp $1 $2
  45.     case $? in
  46.         0) op='=';;
  47.         1) op='>';;
  48.         2) op='<';;
  49.     esac
  50.     if [[ $op != $3 ]]
  51.     then
  52.         echo "Server is up to date!"
  53.         start_server
  54.         return 0
  55.     else
  56.         do_update $2
  57.     fi
  58. }
  59.  
  60. get_version() {
  61.    strings $DLL | egrep '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$'
  62. }
  63.  
  64. get_latest_version() {
  65.    curl -s --user-agent "CleanChat Auto Updater" $VERSION_URL
  66. }
  67.  
  68. do_update () {
  69.    echo "New update ready to download: v. $1"
  70.    curl -o "update.zip" --user-agent "CleanChat AutoUpdater" $DOWNLOAD_URL
  71.    echo "Update downloaded!"
  72.    unzip -o "update.zip"
  73.    rm "update.zip"
  74.    echo "Update installed!"
  75.    start_server
  76. }
  77.  
  78. start_server () {
  79.    echo "Starting server..."
  80.    dotnet $DLL
  81. }
  82.  
  83. VERSION=$(get_version)
  84. NEWEST=$(get_latest_version)
  85. echo "Checking for updates..."
  86. echo "Current version: $VERSION"
  87. echo "Newest version: $NEWEST"
  88. testvercomp $VERSION $NEWEST '<'
RAW Paste Data