-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathsetupbuildenv.sh
185 lines (174 loc) · 5.3 KB
/
setupbuildenv.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
# cp /root/.pydistutils.cfg /root/.pydistutils.cfg.bak
# cp /root/.pip/pip.conf /root/.pip/pip.conf.bak
gitrepo=$1
if [ "$gitrepo" == "" ]; then
echo "ERROR:未传入aquarhome仓库地址作为脚本参数"
exit 0
fi
echo '********清理被阿里云污染的源配置信息********'
/dev/null > /root/.pip/pip.conf
/dev/null > /root/.pydistutils.cfg
cp /etc/apt/sources.list /etc/apt/sources.list.bak
cat > /etc/apt/sources.list <<EOF
deb http://cn.archive.ubuntu.com/ubuntu/ jammy main restricted
deb http://cn.archive.ubuntu.com/ubuntu/ jammy-updates main restricted
deb http://cn.archive.ubuntu.com/ubuntu/ jammy universe
deb http://cn.archive.ubuntu.com/ubuntu/ jammy-updates universe
deb http://cn.archive.ubuntu.com/ubuntu/ jammy multiverse
deb http://cn.archive.ubuntu.com/ubuntu/ jammy-updates multiverse
deb http://cn.archive.ubuntu.com/ubuntu/ jammy-backports main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu jammy-security main restricted
deb http://security.ubuntu.com/ubuntu jammy-security universe
deb http://security.ubuntu.com/ubuntu jammy-security multiverse
EOF
echo '********开始初始化aquar环境********'
apt update
apt install -y vim
apt install -y git
apt install -y unzip
apt install -y lrzsz
apt install -y software-properties-common
apt update
echo '********安装python3及venv********'
apt install curl -y
apt install python3-pip -y
pip3 install virtualenv
pip3 install virtualenvwrapper
apt update
if ! grep -q '##\[aquar config start\]##' /root/.bashrc;
then
cp /root/.bashrc /root/.bashrc.bak
cat >> /root/.bashrc <<EOF
##[aquar config start]##
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
source /usr/local/bin/virtualenvwrapper.sh
##[aquar config end]##
EOF
else
echo '********探测到已配置成功,跳过/root/.bashrc的配置********'
fi
source /root/.bashrc
cat > /usr/local/bin/aqserv <<EOF
#!/bin/bash
cmd=\$1
if [ "\$cmd" != "start" ] && [ "\$cmd" != "stop" ] && [ "\$cmd" != "restart" ] && [ "\$cmd" != "ps" ]; then
echo "error: input parameter only accept 'start','stop','restart' or'ps'"
exit 0
fi
source /root/.bashrc
source /usr/local/bin/virtualenvwrapper.sh
workon aquar
cd /opt/aquar/src/docker-compose/
if [ "\$cmd" == "start" ]; then
echo "aquar docker services starting"
docker-compose up -d
elif [ "\$cmd" == "stop" ]; then
echo "aquar docker services stoping"
docker-compose stop
elif [ "\$cmd" == "restart" ]; then
echo "aquar docker services restarting"
docker-compose restart
else
docker-compose ps
fi
EOF
chmod +x /usr/local/bin/aqserv
echo '********安装docker********'
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
apt-get update
apt-get install docker-ce docker-ce-cli containerd.io -y
echo '********创建python环境aquar并安装docker-compose********'
source /root/.bashrc
source /usr/local/bin/virtualenvwrapper.sh
if ! grep -q 'source /usr/local/bin/virtualenvwrapper.sh' /root/.bashrc;
then
cat >> /root/.bashrc <<EOF
source /usr/local/bin/virtualenvwrapper.sh
##[aquar config end]##
EOF
fi
mkvirtualenv aquar
workon aquar
pip install docker-compose
echo '********配置docker-compose********'
mkdir -p /opt/aquar/src/docker-compose/
touch /opt/aquar/src/docker-compose/docker-compose.yml
cat > /opt/aquar/src/docker-compose/docker-compose.yml <<EOF
version: "3"
services:
aquarhome:
image: finetu/aquarhome:latest
container_name: aquarhome
environment:
- PUID=1000
- PGID=1000
- TZ=Asia/Shanghai
volumes:
- /opt/aquar/storages/apps/aquarhome/data:/var/aquardata
- /opt/aquar/storages/aquarpool:/opt/aquarpool
- /opt/aquar/storages/apps/aquarhome/logs:/root/.pm2/logs
ports:
- 8172:8172
- 10000-10100:10000-10100
restart: unless-stopped
EOF
mkdir -p /opt/aquar/src/docker-compose/mariadb.init.d
touch /opt/aquar/src/docker-compose/mariadb.init.d/init.sql
cat > /opt/aquar/src/docker-compose/mariadb.init.d/init.sql <<EOF
CREATE DATABASE IF NOT EXISTS nextcloud;
CREATE DATABASE IF NOT EXISTS piwigo;
CREATE DATABASE IF NOT EXISTS shinobi;
CREATE DATABASE IF NOT EXISTS ccio;
CREATE DATABASE IF NOT EXISTS photoprism;
CREATE DATABASE IF NOT EXISTS filerun;
CREATE USER 'root'@'localhost' IDENTIFIED BY 'root';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';
EOF
cat > /etc/docker/daemon.json <<EOF
{
"registry-mirrors": ["https://docker.mirrors.ustc.edu.cn"]
}
EOF
echo '********设置开机自启动docker-compose********'
cat > /lib/systemd/system/aquar.service <<EOF
[Unit]
Description=Aquar service
After=docker.service
Requires=docker.service
[Service]
Type=simple
User=root
Group=root
TimeoutStartSec=0
ExecStart=/usr/local/bin/aqserv start
SyslogIdentifier=aqserv
[Install]
WantedBy=multi-user.target
EOF
systemctl enable aquar
#
# 生产环境打包
echo <<COMMENT
cd /opt/aquar/src
git config --global http.sslverify false
git clone $gitrepo
cd /opt/aquar/src/aquar-home
./deploy_docker.sh
COMMENT
#
# 源码编译环境
<<COMMENT
git config --global http.sslverify false
git clone $gitrepo
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
source /root/.bashrc
nvm install 16
nvm alias default 16
nvm use 16
cd /root/aquar-home/aquar_home_server/
npm install
COMMENT