|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# |
| 4 | +# xiechengqi |
| 5 | +# 2026/02/24 |
| 6 | +# install pake |
| 7 | +# curl -SsL https://gitee.com/Xiechengqi/scripts/raw/master/install/pake/gmail.sh | sudo bash |
| 8 | +# |
| 9 | + |
| 10 | +source /etc/profile |
| 11 | +BASEURL="https://install.xiecq.top" |
| 12 | +source <(curl -SsL $BASEURL/tool/common.sh) |
| 13 | + |
| 14 | +main() { |
| 15 | +# check location |
| 16 | +countryCode=$(check_if_in_china) |
| 17 | +[ ".${countryCode}" = "." ] && ERROR "Get country location fail ..." |
| 18 | +INFO "Location: ${countryCode}" |
| 19 | + |
| 20 | +export serviceName="pake-gmail" |
| 21 | +export serviceUrl="https://gmail.com" |
| 22 | +export serviceTaskbar="Gmail" |
| 23 | +export installPath="/data/${serviceName}" |
| 24 | +export downloadUrl="https://github.com/Xiechengqi/Pake/releases/download/latest/pake-native-linux-amd64-ubuntu22" |
| 25 | +[ "${countryCode}" = "China" ] && downloadUrl="${GITHUB_PROXY}/${downloadUrl}" |
| 26 | +export binary="pake" |
| 27 | +export startCmd="WAYLAND_DISPLAY=wayland-1 /usr/local/bin/${binary} ${serviceUrl} --native --name ${serviceTaskbar} --data-dir ${installPath}/data" |
| 28 | + |
| 29 | +# check service |
| 30 | +systemctl is-active ${serviceName} &> /dev/null && YELLOW "${serviceName} is running ..." && return 0 |
| 31 | + |
| 32 | +# check install path |
| 33 | +EXEC "rm -rf ${installPath}" |
| 34 | +EXEC "mkdir -p ${installPath}/{data,logs}" |
| 35 | + |
| 36 | +# download and install |
| 37 | +! which ${binary} && EXEC "curl -SsL ${downloadUrl} -o /usr/local/bin/${binary} && chmod +x /usr/local/bin/${binary}" |
| 38 | +EXEC "which ${binary}" |
| 39 | + |
| 40 | +# create start.sh |
| 41 | +cat > ${installPath}/start.sh << EOF |
| 42 | +#!/usr/bin/env bash |
| 43 | +source /etc/profile |
| 44 | +
|
| 45 | +export installPath="${installPath}" |
| 46 | +
|
| 47 | +timestamp=\$(date +%Y%m%d-%H%M%S) |
| 48 | +touch \${installPath}/logs/\${timestamp}.log && ln -fs \${installPath}/logs/\${timestamp}.log \${installPath}/logs/latest.log |
| 49 | +
|
| 50 | +${startCmd} &> \${installPath}/logs/latest.log |
| 51 | +EOF |
| 52 | +EXEC "chmod +x ${installPath}/start.sh" |
| 53 | + |
| 54 | +# register service |
| 55 | +cat > ${installPath}/${serviceName}.service << EOF |
| 56 | +[Unit] |
| 57 | +Description=Pake ${serviceTaskbar} Service |
| 58 | +Documentation=https://github.com/xiechengqi/Pake |
| 59 | +After=network.target |
| 60 | +
|
| 61 | +[Service] |
| 62 | +User=root |
| 63 | +Group=root |
| 64 | +ExecStart=/bin/bash ${installPath}/start.sh |
| 65 | +ExecStop=/bin/kill -s QUIT \$MAINPID |
| 66 | +Restart=always |
| 67 | +RestartSec=5 |
| 68 | +
|
| 69 | +[Install] |
| 70 | +WantedBy=multi-user.target |
| 71 | +EOF |
| 72 | +EXEC "rm -f /lib/systemd/system/${serviceName}.service" |
| 73 | +EXEC "ln -fs ${installPath}/${serviceName}.service /lib/systemd/system/${serviceName}.service" |
| 74 | + |
| 75 | +# start |
| 76 | +EXEC "systemctl daemon-reload && systemctl enable ${serviceName} && systemctl start ${serviceName}" |
| 77 | +EXEC "systemctl status ${serviceName} --no-pager" && systemctl status ${serviceName} --no-pager |
| 78 | + |
| 79 | +} |
| 80 | + |
| 81 | +main $@ |
0 commit comments