panel.sh 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. /bin/cp ${oneinstack_dir}/init.d/panel.service /lib/systemd/system/
  19. sed -i "s@/root/git/repo/panel@`pwd`@g" /lib/systemd/system/panel.service
  20. systemctl enable panel
  21. # Panel iptables
  22. Panel_port=`cat data/port.conf`
  23. if [ "${PM}" == 'yum' ]; then
  24. if [ -n "`grep 'dport 80 ' /etc/sysconfig/iptables`" ] && [ -z "$(grep -w ${Panel_port} /etc/sysconfig/iptables)" ]; then
  25. iptables -I INPUT 5 -p tcp -m state --state NEW -m tcp --dport ${Panel_port} -j ACCEPT
  26. service iptables save
  27. ip6tables -I INPUT 5 -p tcp -m state --state NEW -m tcp --dport ${Panel_port} -j ACCEPT
  28. service ip6tables save
  29. fi
  30. elif [ "${PM}" == 'apt-get' ]; then
  31. if [ -e '/etc/iptables/rules.v4' ]; then
  32. if [ -n "`grep 'dport 80 ' /etc/iptables/rules.v4`" ] && [ -z "$(grep -w ${Panel_port} /etc/iptables/rules.v4)" ]; then
  33. iptables -I INPUT 5 -p tcp -m state --state NEW -m tcp --dport ${Panel_port} -j ACCEPT
  34. iptables-save > /etc/iptables/rules.v4
  35. ip6tables -I INPUT 5 -p tcp -m state --state NEW -m tcp --dport ${Panel_port} -j ACCEPT
  36. ip6tables-save > /etc/iptables/rules.v6
  37. fi
  38. elif [ -e '/etc/iptables.up.rules' ]; then
  39. if [ -n "`grep 'dport 80 ' /etc/iptables.up.rules`" ] && [ -z "$(grep -w ${Panel_port} /etc/iptables.up.rules)" ]; then
  40. iptables -I INPUT 5 -p tcp -m state --state NEW -m tcp --dport ${Panel_port} -j ACCEPT
  41. iptables-save > /etc/iptables.up.rules
  42. fi
  43. fi
  44. fi
  45. popd > /dev/null
  46. popd > /dev/null
  47. systemctl start panel
  48. }
  49. Upgrade_Panel() {
  50. pushd ${oneinstack_dir}/../panel > /dev/null
  51. git pull
  52. ${python_install_dir}/bin/pip3 install -r requirements.txt -U
  53. ${python_install_dir}/bin/python3 manage.py makemigrations
  54. ${python_install_dir}/bin/python3 manage.py migrate
  55. popd > /dev/null
  56. systemctl reload panel
  57. }
  58. Uninstall_Panel() {
  59. systemctl stop panel
  60. pushd ${oneinstack_dir}/../ > /dev/null
  61. rm -rf panel
  62. popd > /dev/null
  63. }