forked from 233boy/filebrowser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
filebrowser.sh
148 lines (123 loc) · 3.44 KB
/
filebrowser.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
#!/bin/bash
red='\e[91m'
green='\e[92m'
yellow='\e[93m'
none='\e[0m'
[[ $(id -u) != 0 ]] && echo -e " \n哎呀……请使用 ${red}root ${none}用户运行 ${yellow}~(^_^) ${none}\n" && exit 1
cmd="apt-get"
sys_bit=$(uname -m)
# 笨笨的检测方法
if [[ -f /usr/bin/apt-get || -f /usr/bin/yum ]] && [[ -f /bin/systemctl ]]; then
if [[ -f /usr/bin/yum ]]; then
cmd="yum"
fi
else
echo -e " \n哈哈……这个 ${red}辣鸡脚本${none} 不支持你的系统。 ${yellow}(-_-) ${none}\n" && exit 1
fi
if [[ $sys_bit == "i386" || $sys_bit == "i686" ]]; then
filebrowser="linux-386-filebrowser.tar.gz"
elif [[ $sys_bit == "x86_64" ]]; then
filebrowser="linux-386-filebrowser.tar.gz"
elif [[ $sys_bit == "aarch64" ]]; then
filebrowser="linux-arm64-filebrowser.tar.gz"
else
echo -e " \n$red毛支持你的系统....$none\n" && exit 1
fi
install() {
$cmd install wget -y
ver=$(curl -s https://api.github.com/repos/filebrowser/filebrowser/releases/latest | grep 'tag_name' | cut -d\" -f4)
Filebrowser_download_link="https://github.com/filebrowser/filebrowser/releases/download/$ver/$filebrowser"
mkdir -p /tmp/Filebrowser
if ! wget --no-check-certificate --no-cache -O "/tmp/Filebrowser.tar.gz" $Filebrowser_download_link; then
echo -e "$red 下载 Filebrowser 失败!$none" && exit 1
fi
tar zxf /tmp/Filebrowser.tar.gz -C /tmp/Filebrowser
cp -f /tmp/Filebrowser/filebrowser /usr/bin/filebrowser
chmod +x /usr/bin/filebrowser
if [[ -f /usr/bin/filebrowser ]]; then
cat >/lib/systemd/system/filebrowser.service <<-EOF
[Unit]
Description=Filebrowser Service
After=network.target
Wants=network.target
[Service]
Type=simple
PIDFile=/var/run/filebrowser.pid
ExecStart=/usr/bin/filebrowser -c /etc/filebrowser/filebrowser.json
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
mkdir -p /etc/filebrowser
cat >/etc/filebrowser/filebrowser.json <<-EOF
{
"port": 9184,
"baseURL": "",
"address": "",
"log": "stdout",
"database": "/etc/filebrowser/database.db",
"root": "/etc/filebrowser/"
}
EOF
get_ip
systemctl enable filebrowser
systemctl start filebrowser
clear
echo -e "
Filebrowser 安装完成啦!
预览地址: ${yellow}http://${ip}:9184/$none
用户名: ${green}admin$none
密码: ${green}admin$none
$red重要提示,大佬赶紧的打开预览地址登录 并修改密码啊啊啊啊啊$none
脚本帮助说明: https://233blog.com/post/26/
"
else
echo -e " \n$red安装失败...$none\n"
fi
rm -rf /tmp/Filebrowser
rm -rf /tmp/Filebrowser.tar.gz
}
uninstall() {
if [[ -f /usr/bin/filebrowser && -f /etc/filebrowser/filebrowser.json ]]; then
Filebrowser_pid=$(pgrep "filebrowser")
[ $Filebrowser_pid ] && systemctl stop filebrowser
systemctl disable filebrowser >/dev/null 2>&1
rm -rf /usr/bin/filebrowser
rm -rf /etc/filebrowser
rm -rf /lib/systemd/system/filebrowser.service
echo -e " \n$green卸载完成...$none\n" && exit 1
else
echo -e " \n$red大胸弟...你貌似毛有安装 Filebrowser ....卸载个鸡鸡哦...$none\n" && exit 1
fi
}
get_ip() {
ip=$(curl -s ipinfo.io/ip)
}
error() {
echo -e "\n$red 输入错误!$none\n"
}
while :; do
echo
echo "........... Filebrowser 快速一键安装 by 233blog.com .........."
echo
echo "帮助说明: https://233blog.com/post/26/"
echo
echo " 1. 安装"
echo
echo " 2. 卸载"
echo
read -p "请选择[1-2]:" choose
case $choose in
1)
install
break
;;
2)
uninstall
break
;;
*)
error
;;
esac
done