summarylogtreecommitdiffstats
path: root/1panel.install
blob: da12e575a8577f054e110c0f1f33b79fb027bb75 (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
#!/bin/bash

pre_install() {
    echo -e "==================== 准备安装 1Panel ===================="
    # 判断/var/lib/1p是否存在
    if [ -d "/var/lib/1p/1panel" ]; then
        echo -e "\033[32m警告: \033[0m/var/lib/1p/1panel 目录已存在,可能会影响 1Panel 的初始化。"
    fi
}

post_install() {
    # Detecting if docker and docker-compose are successfully installed.
    if pacman -Qs docker >/dev/null 2>&1; then
        echo -e "\033[32mDocker 已成功安装.\033[0m"
    else
        echo -e "\033[33m警告: Docker 未安装,请安装它,否则 1Panel 的大部分服务将无法使用。\033[0m"
    fi
    if pacman -Qs docker-compose >/dev/null 2>&1; then
        echo -e "\033[32mDocker-compose 已成功安装。\033[0m"
    else
        echo -e "\033[33m警告: docker-compose 未安装,请安装它,否则 1Panel 应用商店将无法使用。\033[0m"
    fi
    echo -e "\033[31m使用默认的用户名和密码将是一个十分危险的行为!!!\033[0m."
    echo -e "请务必在启动 \033[34m1panel.service\033[0m 之前运行 \033[34m1pctl init\033[0m 来设置您的用户名和密码!"
    echo -e ""
    echo -e "==================== 1Panel 安装完成 ===================="
}

pre_remove() {
    echo -e "==================== 准备卸载 1Panel ===================="
    echo -e "\033[34m正在停止 systemd 服务...\033[0m"
    systemctl disable --now 1panel
}

post_remove() {
    echo -e "请手动备份 \033[34m/var/lib/1p/1panel\033[0m 目录后删除它。"
    echo -e "==================== 1Panel 卸载完成 ===================="
}

pre_upgrade() {
    export no_need_start="false"
    echo -e "==================== 准备更新 1Panel ===================="
    echo -e " 正在备份1pctl文件"
    cp /usr/bin/1pctl /usr/bin/1pctl.bak
    if systemctl is-active --quiet 1panel; then
        echo -e "检测到systemd服务正在运行,正在临时停止 1Panel 服务..."
        systemctl stop 1panel
        export _restart_1panel_service=true
    fi
}


post_upgrade() {
    if [ -n "${_restart_1panel_service+x}" ]; then
        echo -e "正在重启服务重启服务..."
        systemctl start 1panel
        unset _restart_1panel_service
        systemctl daemon-reload
    fi
    # 提取1pctl的ORIGINAL_VERSION变量的值
    _1panel_version=$(grep -oP '(?<=ORIGINAL_VERSION=).*' /usr/bin/1pctl)
    echo -e "正在恢复1pctl备份"
    mv /usr/bin/1pctl.bak /usr/bin/1pctl
    # 更新1pctl的ORIGINAL_VERSION变量的值
    sed -i -e "s#ORIGINAL_VERSION=.*#ORIGINAL_VERSION=${_1panel_version}#g" /usr/bin/1pctl
    chmod 755 /usr/bin/1pctl
    echo -e "==================== 1Panel 更新完成 ===================="
}