share-copilot/install.sh
2023-09-09 07:38:19 +08:00

81 lines
2.1 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
START_SCRIPT_PATH="/usr/local/bin/scop"
cat > "$START_SCRIPT_PATH" <<EOF
#!/bin/bash
EXECUTABLE_DIR="$SCRIPT_DIR"
EXECUTABLE="\$EXECUTABLE_DIR/share-copilot"
VERSION_FILE="\$EXECUTABLE_DIR/version"
CONFIG_FILE="\$EXECUTABLE_DIR/config.json"
REMOTE_VERSION_URL="https://gitee.com/chuangxxt/share-copilot/raw/master/version"
# 检查是否需要更新
if [ "\$1" != "st" ]; then
if [ -f "\$VERSION_FILE" ]; then
LOCAL_VERSION=\$(cat "\$VERSION_FILE")
REMOTE_VERSION=\$(curl -sS "\$REMOTE_VERSION_URL")
if [ "\$LOCAL_VERSION" != "\$REMOTE_VERSION" ]; then
echo "A new version (\$REMOTE_VERSION) is available. Do you want to update? (y/n)"
read -r ANSWER
if [ "\$ANSWER" == "y" ]; then
echo "Updating to version \$REMOTE_VERSION..."
# 在这里执行更新操作,如 git clone
pkill -f "\$EXECUTABLE"
cp \$CONFIG_FILE /tmp/config.json.backup
rm -rf \$EXECUTABLE_DIR/*
git clone https://gitee.com/chuangxxt/share-copilot.git "\$EXECUTABLE_DIR"
mv /tmp/config.json.backup \$CONFIG_FILE
echo "Update complete."
else
echo "Skipping update."
fi
else
echo "version: (\$LOCAL_VERSION)"
fi
else
echo "Local version file not found. Checking for updates..."
# 如果本地没有版本文件,尝试下载
curl -sS "\$REMOTE_VERSION_URL" -o "\$VERSION_FILE"
fi
fi
case "\$1" in
r)
echo "Running share-copilot..."
"\$EXECUTABLE"
;;
rb)
echo "Running share-copilot in the background..."
"\$EXECUTABLE" >/dev/null 2>&1 &
;;
st)
echo "Stopping share-copilot..."
pkill -f "\$EXECUTABLE"
;;
v)
if pgrep -f "\$EXECUTABLE" >/dev/null; then
echo "share-copilot is running"
else
echo "share-copilot is not running"
fi
;;
*)
echo "Usage: \$0 {r|rb|st|v}"
exit 1
;;
esac
exit 0
EOF
chmod +x "$START_SCRIPT_PATH"
echo "-----------------
install success
-----------------
scop r --运行
scop rb --后台运行
scop st --停止
scop v --查看状态
-----------------"