hst-migration.sh 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. #!/bin/bash
  2. # Hestia installation wrapper
  3. # https://www.hestiacp.com
  4. #
  5. # Currently supported Operating Systems:
  6. #
  7. # Debian 8, 9
  8. # Ubuntu 14.04, 16.04, 18.04
  9. #
  10. HESTIA="/usr/local/hestia"
  11. RHOST='apt.hestiacp.com'
  12. os=$(head -n1 /etc/issue | cut -f 1 -d ' ')
  13. apt="/etc/apt/sources.list.d"
  14. # Detect OS
  15. case $os in
  16. Debian) type="debian" ;;
  17. Ubuntu) type="ubuntu" ;;
  18. *) type="NoSupport" ;;
  19. esac
  20. # Check if OS is supported
  21. if [ "$type" = "NoSupport" ]; then
  22. echo "Your OS is currently not supported."
  23. exit 1;
  24. fi
  25. # Detect codename
  26. if [ "$type" = "debian" ]; then
  27. codename="$(cat /etc/os-release |grep VERSION= |cut -f 2 -d \(|cut -f 1 -d \))"
  28. release=$(cat /etc/debian_version|grep -o [0-9]|head -n1)
  29. VERSION='debian'
  30. fi
  31. if [ "$type" = "ubuntu" ]; then
  32. codename="$(lsb_release -s -c)"
  33. release="$(lsb_release -s -r)"
  34. VERSION='ubuntu'
  35. fi
  36. hestiacp="$HESTIA/install/$VERSION/$release"
  37. # Am I root?
  38. if [ "x$(id -u)" != 'x0' ]; then
  39. echo 'Error: this script can only be executed by root'
  40. exit 1
  41. fi
  42. # Check if Vesta is installed
  43. if [ -f /usr/local/vesta/conf/vesta.conf ]; then
  44. source /usr/local/vesta/conf/vesta.conf
  45. else
  46. echo "Vesta not found, stopping here."
  47. exit 1
  48. fi
  49. # Check current Vesta version
  50. if [ ! "$VERSION" = "0.9.8" ]; then
  51. echo "Wrong Vesta version, stopping here."
  52. exit 1
  53. fi
  54. # Inform user and request confirmation for migration
  55. loop=1
  56. while [ "$loop" -eq 1 ]; do
  57. echo "Would you like to migrate to HestiaCP?"
  58. read -p "Please be warned, that we have removed and do not support Softaculous and paid VestaCP extensions! [yes/no]: " sure
  59. if [ $sure == 'yes' ] || [ $sure == 'no' ]; then
  60. loop=0
  61. if [ $sure == 'no' ]; then
  62. echo "Cancelling migration..."
  63. exit 1
  64. fi
  65. else
  66. echo "Please enter yes or no!"
  67. fi
  68. done
  69. # Update apt repository
  70. echo "Updating system repository..."
  71. apt-get -qq update
  72. # Check if apt-transport-https is installed
  73. if [ ! -e '/usr/lib/apt/methods/https' ]; then
  74. apt-get -y install apt-transport-https
  75. check_result $? "Can't install apt-transport-https"
  76. fi
  77. # Remove Vesta Repository if it exists
  78. echo "Removeing VestaCP Repository..."
  79. if [ -f /usr/local/vesta/conf/vesta.conf ]; then
  80. rm /etc/apt/sources.list.d/vesta.list*
  81. fi
  82. if [ "$type" = "debian" ]; then
  83. # Installing sury PHP repo
  84. echo "deb https://packages.sury.org/php/ $codename main" > $apt/php.list
  85. wget https://packages.sury.org/php/apt.gpg -O /tmp/php_signing.key
  86. apt-key add /tmp/php_signing.key
  87. fi
  88. if [ "$type" = "ubuntu" ]; then
  89. # Check if apt-add-repository is installed
  90. if [ ! -e '/usr/bin/apt-add-repository' ]; then
  91. apt-get -y install python-software-properties
  92. check_result $? "Can't install python-software-properties"
  93. fi
  94. add-apt-repository -y ppa:ondrej/php > /dev/null 2>&1
  95. fi
  96. # Installing HestiaCP repo
  97. echo "deb https://$RHOST/ $codename main" > $apt/hestia.list
  98. wget https://gpg.hestiacp.com/deb_signing.key -O deb_signing.key
  99. apt-key add deb_signing.key
  100. # Remove Vesta packages
  101. echo "Removing VestaCP packages..."
  102. systemctl stop vesta
  103. apt-get -qq remove vesta vesta-nginx vesta-php vesta-ioncube vesta-softaculous -y > /dev/null 2>&1
  104. # Remove Softaculous
  105. rm -fr /usr/local/vesta/softaculous
  106. sed -i '/SOFTACULOUS/d' /usr/local/vesta/conf/vesta.conf
  107. # Move Vesta to Hestia Folder
  108. mv /etc/profile.d/vesta.sh /etc/profile.d/hestia.sh
  109. mv /usr/local/vesta $HESTIA
  110. mv $HESTIA/conf/vesta.conf $HESTIA/conf/hestia.conf
  111. # Install Hestia packages
  112. echo "Update System Repository and install HestiaCP Packages..."
  113. apt-get -qq update
  114. apt-get -qq upgrade -y > /dev/null 2>&1
  115. apt-get -qq install hestia hestia-nginx hestia-php -y > /dev/null 2>&1
  116. # Add modified configuration files
  117. echo "export HESTIA='$HESTIA'" >> /etc/profile.d/hestia.sh
  118. rm /etc/sudoers.d/admin
  119. cp -f $hestiacp/sudo/admin /etc/sudoers.d/
  120. chmod 440 /etc/sudoers.d/admin
  121. sed -i 's/vesta/hestia/g' /root/.bash_profile
  122. sed -i 's/VESTA/HESTIA/g' /etc/profile.d/hestia.sh
  123. sed -i 's/vesta/hestia/g' /etc/profile.d/hestia.sh
  124. cp -rf $hestiacp/firewall $HESTIA/data/
  125. rm -f /var/log/vesta
  126. rm /usr/share/roundcube/plugins/password/drivers/vesta.php
  127. cp -f $hestiacp/roundcube/hestia.php \
  128. /usr/share/roundcube/plugins/password/drivers/
  129. sed -i 's/vesta/hestia/g' /etc/roundcube/config.inc.php
  130. rm /etc/logrotate.d/vesta
  131. cp -f $hestiacp/logrotate/vesta /etc/logrotate.d/hestia
  132. # Restart Hestia service
  133. systemctl restart hestia
  134. # Create compatiblity symlinks
  135. ln -s $HESTIA /usr/local/vesta
  136. ln -s $HESTIA/conf/hestia.conf /usr/local/vesta/conf/vesta.conf
  137. # Update firewall rules
  138. $HESTIA/bin/v-update-firewall
  139. echo "Migration has finished successfully! You are now running HestiaCP instead of VestaCP."
  140. echo "Please contact us in case you face any issues, by using our forum: https://forum.hestiacp.com"