#!/usr/bin/env bash PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin export PATH # fonts color Green="\033[32m" Red="\033[31m" Yellow="\033[33m" GreenBG="\033[42;37m" RedBG="\033[41;37m" Font="\033[0m" # fonts color WORK_PATH=$(dirname $(readlink -f $0)) GHPROXY=https://ghproxy.com/ VERSION=1.5.0 UNAME=$(uname -m) menu() { clear echo -e "${Green}####################################################################${Font}" echo -e "${Green}# 欢迎使用 GitHub Webhook 一键安装卸载脚本 #${Font}" echo -e "${Green}# 本程序为 https://github.com/yezihack/github-webhook 开源项目 #${Font}" echo -e "${Green}####################################################################${Font}" echo -e "${Red}请注意: 脚本安装和卸载需在同一路径下执行${Font}" echo -e "${Green}请选择:${Font}" echo -e "1) 安装" echo -e "2) 卸载" read -p "请选择:" CHOICE_INPUT case "$CHOICE_INPUT" in 1) install_check ;; 2) uninstall_check ;; *) echo -e "${Red}输入错误,请重新执行脚本.${Font}" exit 0 ;; esac } install_check() { if [ -d ${WORK_PATH}/github-webhook ]; then echo -e "${Red}已存在 ${WORK_PATH}/github-webhook 目录${Font}" fi if [ -f /usr/local/sbin/github-webhook ]; then echo -e "${Red}已存在 /usr/local/sbin/github-webhook 文件${Font}" fi if [ -f /lib/systemd/system/github-webhook.service ]; then echo -e "${Red}已存在 /lib/systemd/system/github-webhook.service 文件${Font}" fi port_check=$(/usr/sbin/lsof -i :2020) if [ "$port_check" != "" ]; then echo -e "${Red}已存在 2020 端口${Font}" fi if [ -d ${WORK_PATH}/github-webhook ] || [ -f /usr/local/sbin/github-webhook ] || [ -f /lib/systemd/system/github-webhook.service ] || [ "$port_check" != "" ]; then echo -e "${Green}请先进行手动删除,或执行卸载程序后再次安装.${Font}" exit 0 else install fi } install() { echo -e "${Green}请输入用于验证的 Secret :${Font}" read -p "请输入:" SECRET echo -e "${Green}正在检测网络...${Font}" HTTP_CODE=$(curl -o /dev/null --connect-timeout 5 --max-time 8 -s --head -w "%{http_code}" "https://www.google.com") if [ "${HTTP_CODE}" == "200" ] && [ $UNAME == "x86_64" ]; then wget https://github.com/yezihack/github-webhook/releases/download/v${VERSION}/github-webhook${VERSION}.linux-amd64.tar.gz fi if [ "${HTTP_CODE}" == "200" ] && [ $UNAME == "aarch64" ]; then echo "github-webhook 暂不支持 ARM 架构" exit 0 # wget https:// fi if [ "${HTTP_CODE}" != "200" ] && [ $UNAME == "x86_64" ]; then wget ${GHPROXY}https://github.com/yezihack/github-webhook/releases/download/v${VERSION}/github-webhook${VERSION}.linux-amd64.tar.gz fi if [ "${HTTP_CODE}" != "200" ] && [ $UNAME == "aarch64" ]; then echo "github-webhook 暂不支持 ARM 架构" exit 0 # wget ${GHPROXY}https:// fi tar zxvf github-webhook${VERSION}.linux-amd64.tar.gz mv github-webhook /usr/local/sbin rm -rf github-webhook${VERSION}.linux-amd64.tar.gz chmod u+x /usr/local/sbin/github-webhook mkdir ${WORK_PATH}/github-webhook cat >${WORK_PATH}/github-webhook/hook.sh <<'EOF' #!/bin/bash echo "test $(date "+%Y-%m-%d %H:%M:%S")" >> test.log EOF chmod +x ${WORK_PATH}/github-webhook/hook.sh cat >/lib/systemd/system/github-webhook.service <