panel.sh 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/bin/bash
  2. # Author: yeho <lj2007331 AT gmail.com>
  3. # BLOG: https://blog.linuxeye.cn
  4. #
  5. # Notes: OneinStack for CentOS/RedHat 6+ Debian 7+ and Ubuntu 12+
  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. /bin/cp /etc/sysconfig/{iptables,ip6tables}
  35. sed -i 's@icmp@icmpv6@g' /etc/sysconfig/ip6tables
  36. ip6tables-restore < /etc/sysconfig/ip6tables
  37. service ip6tables save
  38. fi
  39. elif [ "${PM}" == 'apt-get' ]; then
  40. if [ -e '/etc/iptables/rules.v4' ]; then
  41. if [ -n "`grep 'dport 80 ' /etc/iptables/rules.v4`" ] && [ -z "$(grep -w ${Panel_port} /etc/iptables/rules.v4)" ]; then
  42. iptables -I INPUT 5 -p tcp -m state --state NEW -m tcp --dport ${Panel_port} -j ACCEPT
  43. iptables-save > /etc/iptables/rules.v4
  44. /bin/cp /etc/iptables/rules.v{4,6}
  45. sed -i 's@icmp@icmpv6@g' /etc/iptables/rules.v6
  46. ip6tables-restore < /etc/iptables/rules.v6
  47. ip6tables-save > /etc/iptables/rules.v6
  48. fi
  49. elif [ -e '/etc/iptables.up.rules' ]; then
  50. if [ -n "`grep 'dport 80 ' /etc/iptables.up.rules`" ] && [ -z "$(grep -w ${Panel_port} /etc/iptables.up.rules)" ]; then
  51. iptables -I INPUT 5 -p tcp -m state --state NEW -m tcp --dport ${Panel_port} -j ACCEPT
  52. iptables-save > /etc/iptables.up.rules
  53. fi
  54. fi
  55. fi
  56. popd > /dev/null
  57. popd > /dev/null
  58. service panel start
  59. }
  60. Upgrade_Panel() {
  61. pushd ${oneinstack_dir}/../panel > /dev/null
  62. git pull
  63. ${python_install_dir}/bin/pip3 install -r requirements.txt -U
  64. ${python_install_dir}/bin/python3 manage.py makemigrations
  65. ${python_install_dir}/bin/python3 manage.py migrate
  66. popd > /dev/null
  67. service panel reload
  68. }
  69. Uninstall_Panel() {
  70. service panel stop
  71. pushd ${oneinstack_dir}/../ > /dev/null
  72. rm -rf panel
  73. popd > /dev/null
  74. }