-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrun.sh
executable file
·120 lines (112 loc) · 3.17 KB
/
run.sh
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/bin/bash
host="abc"
project_path="/home/ubuntu/qqbot"
usage() {
echo "usage: $0 [start/stop/restart/tail/deploy/upload] [lagrange/napcat] [-d]"
echo ' start: 启动'
echo ' stop: 停止'
echo ' restart: 重启'
echo ' tail: 查看日志'
echo ' deploy: 部署到服务器'
echo ' upload|up: 将改动的文件上传到服务器'
echo ' upp: 将本地所有插件全部拷贝到服务器'
echo '--------- 指定 onebot ---------'
echo ' lagrange: lagrange.onebot'
echo ' napcat: napcat.onebot'
exit 0
}
copy_change() {
echo $0 $1 $2
git_status="`git status -s`"
i=0
for f in $git_status; do
((i++))
if [[ $((i % 2)) -eq 0 ]]; then
if [[ "$1" == "all" ]]; then
echo "scp $f $host:$project_path/$f"
scp $f $host:$project_path/$f
elif [[ "$1" == "no" ]]; then
echo "scp $f $host:$project_path/$f"
else
read -p "upload $f? [yes/no]: " scp_yes
if [[ "$scp_yes" == "yes" ]]; then
echo "scp $f $host:$project_path/$f"
scp $f $host:$project_path/$f
else
echo "[only echo] scp $f $host:$project_path/$f"
fi
fi
fi
done
if [[ "$1" == "no" ]]; then
exit 0
fi
read -p "是否重启服务?[yes/no]:" _yes
if [[ "$_yes" == "yes" ]]; then
read -p "请指定要重启的 onebot [lagrange/napcat]:" _onebot
ssh $host "cd $project_path && ./run.sh restart ${_onebot} -d"
fi
}
upload_plugins() {
for dir in ws/plugins/*
do
if [[ -f $dir ]]; then
continue
fi
if [[ "$dir" = "ws/plugins/__pycache__" ]]; then
continue
fi
if [[ "$1" == "abc" ]]; then
echo "scp -r abc:~/qqbot/$dir/* $dir/"
else
echo "scp -r $dir/* abc:~/qqbot/$dir/"
fi
sudo rm -rf $dir/__pycache__
if [[ "$1" == "all" ]]; then
scp -r $dir/* abc:~/qqbot/$dir/
fi
done
}
case "$1" in
start)
if [[ $# -lt 2 ]]; then
echo '请指定要启动的 onebot [lagrange/napcat]'
usage
fi
echo "docker compose --profile $2 up $3"
docker compose --profile $2 up $3
;;
stop)
if [[ $# -lt 2 ]]; then
echo '请指定要关闭的 onebot [lagrange/napcat]'
usage
fi
echo "docker compose --profile $2 down"
docker compose --profile $2 down
;;
restart)
if [[ $# -lt 2 ]]; then
echo '请指定要重启的 onebot [lagrange/napcat]'
usage
fi
docker compose --profile $2 down
docker compose --profile $2 up $3
;;
tail)
docker compose logs -f $2
;;
deploy)
ssh $host "cd $project_path && git pull origin main && ./run.sh restart $2 -d"
;;
upload|up)
shift
copy_change "$@"
;;
upp)
shift
upload_plugins "$@"
;;
*)
usage
;;
esac