summarylogtreecommitdiffstats
path: root/1panel.install
blob: aacd4195c02fb60d9ac4e863187a0790230bb03c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
pre_install() {
    echo -e "================== installing 1Panel =================="
}

post_install() {
    echo -e "Obtaining the local IP address of this machine..."
    _1panel_active_interface=$(ip route get 8.8.8.8 | awk 'NR==1 {print $5}')
    if [[ -z $_1panel_active_interface ]]; then
        _1panel_local_ip="127.0.0.1"
    else
        _1panel_local_ip=`ip -4 addr show dev "$_1panel_active_interface" | grep -oP '(?<=inet\s)\d+(\.\d+){3}'`
    fi
    echo -e "Obtaining the public IP address of this machine..."
    _1panel_public_ip=`curl -s https://api64.ipify.org`
    if [[ -z "$_1panel_public_ip" ]]; then
        _1panel_public_ip="N/A"
    fi
    if echo "$_1panel_public_ip" | grep -q ":"; then
        _1panel_public_ip=[${_1panel_public_ip}]
        1panel listen-ip ipv6
    fi
    if [ $_1panel_public_ip == "N/A" ]; then
        echo -e "\033[31mFailed to get 1Panel public IP address.\033[0m"
    fi
    # ORIGINAL_PORT=port (/usr/bin/1pctl)
    _1panel_port=$(sed -n 's/^ORIGINAL_PORT=\(.*\)/\1/p' /usr/bin/1pctl)
    _1panel_username=$(sed -n 's/^ORIGINAL_USERNAME=\(.*\)/\1/p' /usr/bin/1pctl)
    _1panel_password=$(sed -n 's/^ORIGINAL_PASSWORD=\(.*\)/\1/p' /usr/bin/1pctl)
    _1panel_entrance=$(sed -n 's/^ORIGINAL_ENTRANCE=\(.*\)/\1/p' /usr/bin/1pctl)
    echo -e "================== 1Panel installed ==================="
    echo -e "Please access 1Panel using your web browser after the \033[33m 1panel.service\033[0m service is started."
    echo -e "Local IP: http://$_1panel_local_ip:$_1panel_port/$_1panel_entrance"
    echo -e "Public IP: http://$_1panel_public_ip:$_1panel_port/$_1panel_entrance"
    echo -e "Username: $_1panel_username"
    echo -e "Password: $_1panel_password"
    echo -e "If you are not Chinese user, please click \033[32m'中文(简体)'\033[0m and switch it to English."
    # 判断docker和docker-compose安装
    if pacman -Qs docker >/dev/null 2>&1; then
        echo -e "\033[32mDocker is installed correctly.\033[0m"
    else
        echo -e "\033[31mWarning: Docker is not installed, please install it, or most of the features of this package will not be available.\033[0m"
    fi
    if pacman -Qs docker-compose >/dev/null 2>&1; then
        echo -e "\033[32mDocker Compose is installed correctly.\033[0m"
    else
        echo -e "\033[31mWarning: Docker Compose is not installed, please install it, or 1Panel application store will not be avaliable.\033[0m"
    fi
    unset _1panel_active_interface
    unset _1panel_local_ip
    unset _1panel_public_ip
    unset _1panel_port
    unset _1panel_username
    unset _1panel_password
    unset _1panel_entrance
}

pre_remove() {
    echo -e "================== Uninstalling 1Panel =================="
    echo -e "\033[34mStopping systemd service...\033[0m"
    systemctl disable --now 1panel
}

post_remove() {
    echo -e "\033[34mPlease delete /opt/1panel files after backup them...\033[0m"
    echo -e "=================== 1Panel uninstalled =================="
}

pre_upgrade() {
    export no_need_start="false"
    echo -e "================== Upgrading 1Panel ==================="
    # Stop 1panel service`
    if systemctl is-active --quiet 1panel; then
        echo -e "Temporarily stoping 1Panel service..."
        systemctl stop 1panel
        export _restart_1panel_service=true
    fi
}


post_upgrade() {
    if [ -n "${_restart_1panel_service+x}" ]; then
        echo -e "Restarting..."
        systemctl start 1panel
        unset _restart_1panel_service
    fi
    echo -e "=================== 1Panel upgraded ==================="
}