upgrade.sh 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/bin/bash
  2. cd /seafile
  3. echo "Checking if Seafile is installed ..."
  4. if [ ! -d "/seafile/seafile-server-latest" ]; then
  5. echo "[FAILED] Seafile is not installed!"
  6. exit 0
  7. fi
  8. # Get version based on the seafile-server-latest symbolic link that is pointing to the current installation.
  9. CURRENT_VERSION=$(ls -lah | grep 'seafile-server-latest' | awk -F"seafile-pro-server-" '{print $2}')
  10. NEW_VERSION=$1
  11. if [ "$CURRENT_VERSION" == "$NEW_VERSION" ]; then
  12. echo "[FAILED] You already have the most recent version installed"
  13. exit 0
  14. else
  15. echo "Downloading seafile-pro-server_${NEW_VERSION}_x86-64.tar.gz"
  16. if [ ! -f /seafile-pro-server_${NEW_VERSION}_x86-64.tar.gz ];then
  17. wget "https://download.seafile.com/d/6e5297246c/files/?p=/pro/seafile-pro-server_${NEW_VERSION}_x86-64.tar.gz&dl=1" -O "/seafile-pro-server_${NEW_VERSION}_x86-64.tar.gz" 2>/dev/null
  18. fi
  19. fi
  20. echo "Extracting server binary ..."
  21. tar -xzf "/seafile-pro-server_${NEW_VERSION}_x86-64.tar.gz" 2>/dev/null
  22. if [[ $? != 0 ]];then
  23. echo "Could not extract server binary. Are you sure $NEW_VERSION is a valid version number?"
  24. rm /seafile-pro-server_${NEW_VERSION}_x86-64.tar.gz
  25. exit 1
  26. fi
  27. mv "/seafile-pro-server_${NEW_VERSION}_x86-64.tar.gz" installed/
  28. cd "/seafile/seafile-pro-server-${NEW_VERSION}"
  29. # First we need to check if it's a maintenance update, since the process is different from a major/minor version upgrade
  30. CURRENT_MAJOR_VERSION=$(echo $CURRENT_VERSION | awk -F"." '{print $1}')
  31. CURRENT_MINOR_VERSION=$(echo $CURRENT_VERSION | awk -F"." '{print $2}')
  32. CURRENT_MAINTENANCE_VERSION=$(echo $CURRENT_VERSION | awk -F"." '{print $3}')
  33. NEW_MAJOR_VERSION=$(echo $NEW_VERSION | awk -F"." '{print $1}')
  34. NEW_MINOR_VERSION=$(echo $NEW_VERSION | awk -F"." '{print $2}')
  35. NEW_MAINTENANCE_VERSION=$(echo $NEW_VERSION | awk -F"." '{print $3}')
  36. if [ "$CURRENT_MAJOR_VERSION" == "$NEW_MAJOR_VERSION" ] && [ "$CURRENT_MINOR_VERSION" == "$NEW_MINOR_VERSION" ]; then
  37. # Alright, this is only a maintenance update.
  38. echo "Performing maintenance update ..."
  39. ./upgrade/minor-upgrade.sh
  40. cd /seafile
  41. rm -rf "/seafile/seafile-pro-server-${CURRENT_VERSION}"
  42. else
  43. # Big version jump (e.g. 6.1.x to 6.2.x)
  44. for file in ./upgrade/upgrade_*.sh
  45. do
  46. UPGRADE_FROM=$(echo "$file" | awk -F"_" '{print $2}')
  47. UPGRADE_TO=$(echo "$file" | awk -F"_" '{print $3}' | sed 's/\.sh//g')
  48. if [ "$UPGRADE_FROM" == "$CURRENT_MAJOR_VERSION.$CURRENT_MINOR_VERSION" ]; then
  49. echo "Upgrading from $UPGRADE_FROM to $UPGRADE_TO ..."
  50. $file
  51. CURRENT_MAJOR_VERSION=$(echo $UPGRADE_TO | awk -F"." '{print $1}')
  52. CURRENT_MINOR_VERSION=$(echo $UPGRADE_TO | awk -F"." '{print $2}')
  53. fi
  54. done
  55. fi
  56. echo "All done! Bye."