forked from LlmKira/Openaibot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
195 lines (182 loc) · 5.79 KB
/
setup.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#!/bin/bash
# github author@sudoskys
# project:Openaibot
initVar() {
echoType='echo -e'
}
# 准备运行需要的软件包
_os=$(uname)
echo "use system: ${_os}"
if grep -Eqi "CentOS" /etc/issue || grep -Eq "CentOS" /etc/*-release; then
yum install -y git python3 python3-pip
yum install -y ffmpeg
elif grep -Eqi "Fedora" /etc/issue || grep -Eq "Fedora" /etc/*-release; then
yum install -y git python3 python3-pip
yum install -y ffmpeg
elif grep -Eqi "Rocky" /etc/issue || grep -Eq "Rocky" /etc/*-release; then
yum install -y git python3 python3-pip
yum install -y ffmpeg
elif grep -Eqi "AlmaLinux" /etc/issue || grep -Eq "AlmaLinux" /etc/*-release; then
yum install -y git python3 python3-pip
yum install -y ffmpeg
elif grep -Eqi "Amazon Linux" /etc/issue || grep -Eq "Amazon Linux" /etc/*-release; then
yum install -y git python3 python3-pip
yum install -y ffmpeg
elif grep -Eqi "Debian" /etc/issue || grep -Eq "Debian" /etc/*-release; then
apt update -y
apt install -y git python3 python3-pip
apt install -y ffmpeg
elif grep -Eqi "Ubuntu" /etc/issue || grep -Eq "Ubuntu" /etc/*-release; then
apt update -y
apt install -y git python3 python3-pip
apt install -y ffmpeg
else
OSNAME='unknow'
fi
initVar
echox() {
case $1 in
# 红色
"red")
# shellcheck disable=SC2154
${echoType} "\033[31m$2\033[0m"
;;
# 绿色
"green")
${echoType} "\033[32m$2\033[0m"
;;
# 黄色
"yellow")
${echoType} "\033[33m$2\033[0m"
;;
# 蓝色
"blue")
${echoType} "\033[34m$2\033[0m"
;;
# 紫色
"purple")
${echoType} "\033[35m$2\033[0m"
;;
# 天蓝色
"skyBlue")
${echoType} "\033[36m$2\033[0m"
;;
# 白色
"white")
${echoType} "\033[37m$2\033[0m"
;;
esac
}
Gitpull() {
git clone https://github.com/sudoskys/Openaibot.git || (
echox yellow "Git failed,try pull from mirror"
git clone https://gitclone.com/github.com/sudoskys/Openaibot.git
)
}
dependenceInit() {
cd Openaibot || (
echo "Cant find !?"
exit 1
)
pip3 install --upgrade pip
pip3 install -U llm-kira
pip3 install -r requirements.txt # -i https://pypi.tuna.tsinghua.edu.cn/simple
# while read -r requirement; do pip3 install "${requirement}" -i https://pypi.tuna.tsinghua.edu.cn/simple; done <requirements.txt || echox yellow "===pip install failed,please check it====="
echox yellow "========Down=========="
}
dataBack="$(pwd)/tmp"
dir="$(pwd)/Openaibot"
data="$(pwd)/Openaibot/Data"
config="$(pwd)/Openaibot/Config"
echo "=============Setup============"
run() {
# if [ -f "${dir}/project.info" ]; then
# Data=$(cat "${dir}/project.info")
# declare "$Data"
# # shellcheck disable=SC2154
# echox green "当前版本 ${version}"
# now=$version
# (curl -s https://raw.fastgit.org/sudoskys/Openaibot/main/project.info) && declare<(curl -s https://raw.fastgit.org/sudoskys/Openaibot/main/project.info)
# new=$version
# if [[ $new ]]; then
# if [[ $((new)) -gt $((now)) ]]; then
# echox yellow "仓库最新版本为${new}"
# fi
# else
# echox red "远程仓库出现错误或未连接"
# fi
# fi
if [ ! -d "$dir" ]; then
echox skyBlue "初始化:No found ${dir},init, setup..."
Gitpull
dependenceInit
else
# 初始化备份文件夹
if [ ! -d "$dataBack" ]; then
echox skyBlue "初始化备份文件夹:init ${dataBack}...."
mkdir "$dataBack"
fi
if [ ! -d "$config" ]; then
echox skyBlue "初始化配置文件夹:init ${config}...."
mkdir "$config"
fi
# 备份配置文件
if [ -f "${dir}/config.json" ]; then
echox skyBlue "移动配置文件:backup ${dir}/config.json to ${config} ...."
cp -f "${dir}/config.json" "$config"
fi
# 统计数据
if [ -f "${dir}/analysis.json" ]; then
echox skyBlue "备份统计数据:backup ${dir}/analysis.json to ${dataBack} ...."
cp -f "${dir}/analysis.json" "$dataBack"
fi
# 备份运行数据
if [ -d "$data" ]; then
echox skyBlue "备份运行数据:Copy run data to ${dataBack}...."
cp -rf "$data" "$dataBack" #文件夹目录 文件夹上级
fi
# 备份配置数据
if [ -d "$config" ]; then
echox skyBlue "备份运行数据:Copy Config to ${dataBack}...."
cp -rf "$config" "$dataBack" #文件夹目录 文件夹上级
fi
read -r -p "HELLO!请问,是否使用可能存在的上一次配置?Update your app with probably EXIST old data?${dir} y/n?[default=y]" input
if [ -z "${input}" ]; then
input=y
fi
case $input in
[nN][oO] | [nN])
echox red "Reinstalling A Pure APP....BUT IF YOU WANT TO RECOVER OLD DATA,PLEASE CHECK /tmp DIR"
rm -rf "${dir}"
Gitpull
dependenceInit
;;
[yY][eE][sS] | [yY])
rm -rf "${dir}"
Gitpull
# if [ -f "${dataBack}/Captcha.toml" ]; then
# echox green "恢复配置文件:Reuse the Captcha.toml from ${dataBack}...."
# cp -f "${dataBack}/Captcha.toml" "$dir" #文件夹目录 文件夹上级
# fi
if [ -f "${dataBack}/analysis.json" ]; then
echox green "恢复配置文件:Reuse the analysis.json from ${dataBack}...."
cp -f "${dataBack}/analysis.json" "$dir" #文件夹目录 文件夹上级
fi
if [ -d "${dataBack}/Config" ]; then
echox green "恢复配置库:Reuse the Config from ${dataBack}...."
cp -rf "${dataBack}/Config" "$dir" #文件夹目录 文件夹上级
fi
if [ -d "${dataBack}/Data" ]; then
echox green "恢复数据库:Reuse the run data from ${dataBack}...."
cp -rf "${dataBack}/Data" "$dir" #文件夹目录 文件夹上级
fi
dependenceInit || exit 1
;;
*)
echox skyBlue "Invalid input"
;;
esac
fi
}
run
cd "$(pwd)" && rm setup.sh