panel.sh 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/bin/bash
  2. # Author: yeho <lj2007331 AT gmail.com>
  3. # BLOG: https://linuxeye.com
  4. #
  5. # Notes: OneinStack for CentOS/RedHat 7+ Debian 8+ and Ubuntu 16+
  6. #
  7. # Project home page:
  8. # https://oneinstack.com
  9. # https://github.com/oneinstack/oneinstack
  10. Install_Panel() {
  11. pushd ${oneinstack_dir}/../ > /dev/null
  12. git clone https://github.com/oneinstack/panel.git
  13. pushd panel > /dev/null
  14. sed -i "s@/root/oneinstack/options.conf@${oneinstack_dir}/options.conf@" panel/settings.py
  15. ${python_install_dir}/bin/pip3 install -r requirements.txt
  16. ${python_install_dir}/bin/python3 manage.py makemigrations
  17. ${python_install_dir}/bin/python3 manage.py migrate
  18. if [ -e /bin/systemctl ]; then
  19. /bin/cp ${oneinstack_dir}/init.d/panel.service /lib/systemd/system/
  20. sed -i "s@/root/git/repo/panel@`pwd`@g" /lib/systemd/system/panel.service
  21. systemctl enable panel
  22. else
  23. /bin/cp ${oneinstack_dir}/init.d/Panel-init /etc/init.d/panel
  24. sed -i "s@/root/git/repo/panel@`pwd`@g" /etc/init.d/panel
  25. [ "${PM}" == 'yum' ] && { chkconfig --add panel; chkconfig panel on; }
  26. [ "${PM}" == 'apt-get' ] && update-rc.d panel defaults
  27. fi
  28. # Panel iptables
  29. Panel_port=`cat data/port.conf`
  30. if [ "${PM}" == 'yum' ]; then
  31. if [ -n "`grep 'dport 80 ' /etc/sysconfig/iptables`" ] && [ -z "$(grep -w ${Panel_port} /etc/sysconfig/iptables)" ]; then
  32. iptables -I INPUT 5 -p tcp -m state --state NEW -m tcp --dport ${Panel_port} -j ACCEPT
  33. service iptables save
  34. ip6tables -I INPUT 5 -p tcp -m state --state NEW -m tcp --dport ${Panel_port} -j ACCEPT
  35. service ip6tables save
  36. fi
  37. elif [ "${PM}" == 'apt-get' ]; then
  38. if [ -e '/etc/iptables/rules.v4' ]; then
  39. if [ -n "`grep 'dport 80 ' /etc/iptables/rules.v4`" ] && [ -z "$(grep -w ${Panel_port} /etc/iptables/rules.v4)" ]; then
  40. iptables -I INPUT 5 -p tcp -m state --state NEW -m tcp --dport ${Panel_port} -j ACCEPT
  41. iptables-save > /etc/iptables/rules.v4
  42. ip6tables -I INPUT 5 -p tcp -m state --state NEW -m tcp --dport ${Panel_port} -j ACCEPT
  43. ip6tables-save > /etc/iptables/rules.v6
  44. fi
  45. elif [ -e '/etc/iptables.up.rules' ]; then
  46. if [ -n "`grep 'dport 80 ' /etc/iptables.up.rules`" ] && [ -z "$(grep -w ${Panel_port} /etc/iptables.up.rules)" ]; then
  47. iptables -I INPUT 5 -p tcp -m state --state NEW -m tcp --dport ${Panel_port} -j ACCEPT
  48. iptables-save > /etc/iptables.up.rules
  49. fi
  50. fi
  51. fi
  52. popd > /dev/null
  53. popd > /dev/null
  54. service panel start
  55. }
  56. Upgrade_Panel() {
  57. pushd ${oneinstack_dir}/../panel > /dev/null
  58. git pull
  59. ${python_install_dir}/bin/pip3 install -r requirements.txt -U
  60. ${python_install_dir}/bin/python3 manage.py makemigrations
  61. ${python_install_dir}/bin/python3 manage.py migrate
  62. popd > /dev/null
  63. service panel reload
  64. }
  65. Uninstall_Panel() {
  66. service panel stop
  67. pushd ${oneinstack_dir}/../ > /dev/null
  68. rm -rf panel
  69. popd > /dev/null
  70. }