Skip to content

Commit dc18658

Browse files
committed
beta script
1 parent 971eabf commit dc18658

File tree

3 files changed

+327
-10
lines changed

3 files changed

+327
-10
lines changed

docs/.vuepress/public/beta.sh

Lines changed: 251 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,251 @@
1+
#!/bin/bash
2+
3+
# INSTALL_PATH='/opt/alist'
4+
VERSION='beta'
5+
6+
URL_PREFIX='https://github.com/alist-org/alist/releases/download/beta/'
7+
8+
if [ ! -n "$2" ]; then
9+
INSTALL_PATH='/opt/alist'
10+
else
11+
if [[ $2 == */ ]]; then
12+
INSTALL_PATH=${2%?}
13+
else
14+
INSTALL_PATH=$2
15+
fi
16+
if ! [[ $INSTALL_PATH == */alist ]]; then
17+
INSTALL_PATH="$INSTALL_PATH/alist"
18+
fi
19+
fi
20+
21+
RED_COLOR='\e[1;31m'
22+
GREEN_COLOR='\e[1;32m'
23+
YELLOW_COLOR='\e[1;33m'
24+
BLUE_COLOR='\e[1;34m'
25+
PINK_COLOR='\e[1;35m'
26+
SHAN='\e[1;33;5m'
27+
RES='\e[0m'
28+
clear
29+
30+
# Get platform
31+
if command -v arch >/dev/null 2>&1; then
32+
platform=$(arch)
33+
else
34+
platform=$(uname -m)
35+
fi
36+
37+
ARCH="UNKNOWN"
38+
39+
if [ "$platform" = "x86_64" ]; then
40+
ARCH=amd64
41+
elif [ "$platform" = "aarch64" ]; then
42+
ARCH=arm64
43+
fi
44+
45+
GH_PROXY='https://mirror.ghproxy.com/'
46+
47+
if [ "$(id -u)" != "0" ]; then
48+
echo -e "\r\n${RED_COLOR}出错了,请使用 root 权限重试!${RES}\r\n" 1>&2
49+
exit 1
50+
elif [ "$ARCH" == "UNKNOWN" ]; then
51+
echo -e "\r\n${RED_COLOR}出错了${RES},一键安装目前仅支持 x86_64和arm64 平台。\r\n其它平台请参考:${GREEN_COLOR}https://alist.nn.ci${RES}\r\n"
52+
exit 1
53+
elif ! command -v systemctl >/dev/null 2>&1; then
54+
echo -e "\r\n${RED_COLOR}出错了${RES},无法确定你当前的 Linux 发行版。\r\n建议手动安装:${GREEN_COLOR}https://alist.nn.ci${RES}\r\n"
55+
exit 1
56+
else
57+
if command -v netstat >/dev/null 2>&1; then
58+
check_port=$(netstat -lnp | grep 5244 | awk '{print $7}' | awk -F/ '{print $1}')
59+
else
60+
echo -e "${GREEN_COLOR}端口检查 ...${RES}"
61+
if command -v yum >/dev/null 2>&1; then
62+
yum install net-tools -y >/dev/null 2>&1
63+
check_port=$(netstat -lnp | grep 5244 | awk '{print $7}' | awk -F/ '{print $1}')
64+
else
65+
apt-get update >/dev/null 2>&1
66+
apt-get install net-tools -y >/dev/null 2>&1
67+
check_port=$(netstat -lnp | grep 5244 | awk '{print $7}' | awk -F/ '{print $1}')
68+
fi
69+
fi
70+
fi
71+
72+
CHECK() {
73+
if [ -f "$INSTALL_PATH/alist" ]; then
74+
echo "此位置已经安装,请选择其他位置,或使用更新命令"
75+
exit 0
76+
fi
77+
if [ $check_port ]; then
78+
kill -9 $check_port
79+
fi
80+
if [ ! -d "$INSTALL_PATH/" ]; then
81+
mkdir -p $INSTALL_PATH
82+
else
83+
rm -rf $INSTALL_PATH && mkdir -p $INSTALL_PATH
84+
fi
85+
}
86+
87+
INSTALL() {
88+
# 下载 Alist 程序
89+
echo -e "\r\n${GREEN_COLOR}下载 Alist $VERSION ...${RES}"
90+
curl -L ${GH_PROXY}${URL_PREFIX}alist-linux-musl-$ARCH.tar.gz -o /tmp/alist.tar.gz $CURL_BAR
91+
tar zxf /tmp/alist.tar.gz -C $INSTALL_PATH/
92+
93+
if [ -f $INSTALL_PATH/alist ]; then
94+
echo -e "${GREEN_COLOR} 下载成功 ${RES}"
95+
else
96+
echo -e "${RED_COLOR}下载 alist-linux-musl-$ARCH.tar.gz 失败!${RES}"
97+
exit 1
98+
fi
99+
100+
# 删除下载缓存
101+
rm -f /tmp/alist*
102+
}
103+
104+
INIT() {
105+
if [ ! -f "$INSTALL_PATH/alist" ]; then
106+
echo -e "\r\n${RED_COLOR}出错了${RES},当前系统未安装 Alist\r\n"
107+
exit 1
108+
else
109+
rm -f $INSTALL_PATH/alist.db
110+
fi
111+
112+
# 创建 systemd
113+
cat >/etc/systemd/system/alist.service <<EOF
114+
[Unit]
115+
Description=Alist service
116+
Wants=network.target
117+
After=network.target network.service
118+
119+
[Service]
120+
Type=simple
121+
WorkingDirectory=$INSTALL_PATH
122+
ExecStart=$INSTALL_PATH/alist server
123+
KillMode=process
124+
125+
[Install]
126+
WantedBy=multi-user.target
127+
EOF
128+
129+
# 添加开机启动
130+
systemctl daemon-reload
131+
systemctl enable alist >/dev/null 2>&1
132+
}
133+
134+
SUCCESS() {
135+
clear
136+
echo "Alist Beta安装成功!"
137+
echo -e "\r\n访问地址:${GREEN_COLOR}http://YOUR_IP:5244/${RES}\r\n"
138+
139+
echo -e "配置文件路径:${GREEN_COLOR}$INSTALL_PATH/data/config.json${RES}"
140+
141+
# sleep 1s
142+
# cd $INSTALL_PATH
143+
# get_password=$(./alist password 2>&1)
144+
# echo -e "初始管理密码:${GREEN_COLOR}$(echo $get_password | awk -F'your password: ' '{print $2}')${RES}"
145+
echo -e "---------如何获取密码?--------"
146+
echo -e "先cd到alist所在目录:"
147+
echo -e "${GREEN_COLOR}cd $INSTALL_PATH${RES}"
148+
echo -e "随机设置新密码:"
149+
echo -e "${GREEN_COLOR}./alist admin random${RES}"
150+
echo -e "或者手动设置新密码:"
151+
echo -e "${GREEN_COLOR}./alist admin set ${RES}${RED_COLOR}NEW_PASSWORD${RES}"
152+
echo -e "----------------------------"
153+
154+
echo -e "启动服务中"
155+
systemctl restart alist
156+
157+
echo
158+
echo -e "查看状态:${GREEN_COLOR}systemctl status alist${RES}"
159+
echo -e "启动服务:${GREEN_COLOR}systemctl start alist${RES}"
160+
echo -e "重启服务:${GREEN_COLOR}systemctl restart alist${RES}"
161+
echo -e "停止服务:${GREEN_COLOR}systemctl stop alist${RES}"
162+
echo -e "\r\n温馨提示:如果端口无法正常访问,请检查 \033[36m服务器安全组、本机防火墙、Alist状态\033[0m"
163+
echo
164+
}
165+
166+
UNINSTALL() {
167+
echo -e "\r\n${GREEN_COLOR}卸载 Alist ...${RES}\r\n"
168+
echo -e "${GREEN_COLOR}停止进程${RES}"
169+
systemctl disable alist >/dev/null 2>&1
170+
systemctl stop alist >/dev/null 2>&1
171+
echo -e "${GREEN_COLOR}清除残留文件${RES}"
172+
rm -rf $INSTALL_PATH /etc/systemd/system/alist.service
173+
# 兼容之前的版本
174+
rm -f /lib/systemd/system/alist.service
175+
systemctl daemon-reload
176+
echo -e "\r\n${GREEN_COLOR}Alist 已在系统中移除!${RES}\r\n"
177+
}
178+
179+
UPDATE() {
180+
if [ ! -f "$INSTALL_PATH/alist" ]; then
181+
echo -e "\r\n${RED_COLOR}出错了${RES},当前系统未安装 Alist\r\n"
182+
exit 1
183+
else
184+
config_content=$(cat $INSTALL_PATH/data/config.json)
185+
if [[ "${config_content}" == *"assets"* ]]; then
186+
echo -e "\r\n${RED_COLOR}出错了${RES},V3与V2不兼容,请先卸载V2或更换位置安装V3\r\n"
187+
exit 1
188+
fi
189+
190+
echo
191+
echo -e "${GREEN_COLOR}停止 Alist 进程${RES}\r\n"
192+
systemctl stop alist
193+
# 备份 alist 二进制文件,供下载更新失败回退
194+
cp $INSTALL_PATH/alist /tmp/alist.bak
195+
echo -e "${GREEN_COLOR}下载 Alist $VERSION ...${RES}"
196+
curl -L ${GH_PROXY}${URL_PREFIX}alist-linux-musl-$ARCH.tar.gz -o /tmp/alist.tar.gz $CURL_BAR
197+
tar zxf /tmp/alist.tar.gz -C $INSTALL_PATH/
198+
if [ -f $INSTALL_PATH/alist ]; then
199+
echo -e "${GREEN_COLOR} 下载成功 ${RES}"
200+
else
201+
echo -e "${RED_COLOR}下载 alist-linux-musl-$ARCH.tar.gz 出错,更新失败!${RES}"
202+
echo "回退所有更改 ..."
203+
mv /tmp/alist.bak $INSTALL_PATH/alist
204+
systemctl start alist
205+
exit 1
206+
fi
207+
echo -e "---------如何获取密码?--------"
208+
echo -e "先cd到alist所在目录:"
209+
echo -e "${GREEN_COLOR}cd $INSTALL_PATH${RES}"
210+
echo -e "随机设置新密码:"
211+
echo -e "${GREEN_COLOR}./alist admin random${RES}"
212+
echo -e "或者手动设置新密码:"
213+
echo -e "${GREEN_COLOR}./alist admin set ${RES}${RED_COLOR}NEW_PASSWORD${RES}"
214+
echo -e "----------------------------"
215+
echo -e "\r\n${GREEN_COLOR}启动 Alist 进程${RES}"
216+
systemctl start alist
217+
echo -e "\r\n${GREEN_COLOR}Alist 已更新到最新稳定版!${RES}\r\n"
218+
# 删除临时文件
219+
rm -f /tmp/alist*
220+
fi
221+
}
222+
223+
# CURL 进度显示
224+
if curl --help | grep progress-bar >/dev/null 2>&1; then # $CURL_BAR
225+
CURL_BAR="--progress-bar"
226+
fi
227+
228+
# The temp directory must exist
229+
if [ ! -d "/tmp" ]; then
230+
mkdir -p /tmp
231+
fi
232+
233+
# Fuck bt.cn (BT will use chattr to lock the php isolation config)
234+
chattr -i -R $INSTALL_PATH >/dev/null 2>&1
235+
236+
if [ "$1" = "uninstall" ]; then
237+
UNINSTALL
238+
elif [ "$1" = "update" ]; then
239+
UPDATE
240+
elif [ "$1" = "install" ]; then
241+
CHECK
242+
INSTALL
243+
INIT
244+
if [ -f "$INSTALL_PATH/alist" ]; then
245+
SUCCESS
246+
else
247+
echo -e "${RED_COLOR} 安装失败${RES}"
248+
fi
249+
else
250+
echo -e "${RED_COLOR} 错误的命令${RES}"
251+
fi

docs/guide/install/script.md

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,49 @@ star: true
2020

2121
Only for Linux-x86_64/arm64 platform.
2222

23-
### **Install**
23+
::: tabs
2424

25+
@tab Latest
26+
**Install**
2527
```bash
2628
curl -fsSL "https://alist.nn.ci/v3.sh" | bash -s install
2729
```
2830

29-
### **update**
30-
31+
**Update**
3132
```bash
3233
curl -fsSL "https://alist.nn.ci/v3.sh" | bash -s update
3334
```
3435

35-
### **Uninstall**
36-
36+
**Uninstall**
3737
```bash
3838
curl -fsSL "https://alist.nn.ci/v3.sh" | bash -s uninstall
3939
```
4040

41+
@tab Beta
42+
**Install**
43+
```bash
44+
curl -fsSL "https://alist.nn.ci/beta.sh" | bash -s install
45+
```
46+
47+
**Update**
48+
```bash
49+
curl -fsSL "https://alist.nn.ci/beta.sh" | bash -s update
50+
```
51+
52+
**Uninstall**
53+
```bash
54+
curl -fsSL "https://alist.nn.ci/beta.sh" | bash -s uninstall
55+
```
56+
57+
:::
58+
4159
### **Custom path**
4260

4361
The default installation is in `/opt/alist`. To customize the installation path, add the installation path as the second parameter, which must be an absolute path (if the path ends in alist, install directly to the given path, otherwise it will be installed in the given path alist Directory), such as installing to `/root`:
4462

63+
:::tabs
64+
65+
@tab Latest
4566
```bash
4667
# Install
4768
curl -fsSL "https://alist.nn.ci/v3.sh" | bash -s install /root
@@ -51,7 +72,17 @@ curl -fsSL "https://alist.nn.ci/v3.sh" | bash -s update /root
5172
curl -fsSL "https://alist.nn.ci/v3.sh" | bash -s uninstall /root
5273
```
5374

75+
@tab Beta
76+
```bash
77+
# Install
78+
curl -fsSL "https://alist.nn.ci/beta.sh" | bash -s install /root
79+
# update
80+
curl -fsSL "https://alist.nn.ci/beta.sh" | bash -s update /root
81+
# Uninstall
82+
curl -fsSL "https://alist.nn.ci/beta.sh" | bash -s uninstall /root
83+
```
5484

85+
:::
5586

5687
- Start: `systemctl start alist`
5788
- Shut down: `systemctl stop alist`

0 commit comments

Comments
 (0)