forked from cshczh/clouddrive2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcd2-termux.sh
executable file
·190 lines (174 loc) · 5.51 KB
/
cd2-termux.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
#!/data/data/com.termux/files/usr/bin/bash
#set -x
chmod +x "$0"
if [ ! -n "$2" ]; then
echo -e "\r\n${YELLOW_COLOR}非 Root 方式${RES}\r\n" 1>&2
CHECK_ROOT="notroot"
else
if [[ $2 == "root" ]]; then
echo -e "\r\n${YELLOW_COLOR}Root 方式${RES}\r\n" 1>&2
CHECK_ROOT="root"
pkg install tsu -y
else
echo -e "${RED_COLOR} 错误的命令${RES}"
exit 1
fi
fi
RED_COLOR='\e[1;31m'
GREEN_COLOR='\e[1;32m'
YELLOW_COLOR='\e[1;33m'
BLUE_COLOR='\e[1;34m'
PINK_COLOR='\e[1;35m'
SHAN='\e[1;33;5m'
RES='\e[0m'
# Get platform
if command -v uname >/dev/null 2>&1; then
platform=$(uname -m)
else
platform=$(arch)
fi
ARCH="UNKNOWN"
if [ "$platform" = "x86_64" ]; then
ARCH="x86_64"
elif [ "$platform" = "arm64" ]; then
ARCH="aarch64"
elif [ "$platform" = "aarch64" ]; then
ARCH="aarch64"
elif [ "$platform" = "armv7l" ]; then
ARCH="armv7"
else
echo -e "${RED_COLOR}不支持的架构${RES}"
exit 1
fi
pkg install termux-services -y
if [ $? -eq 0 ]; then
echo -e "下载完成"
else
echo -e "${RED_COLOR}网络中断,请检查网络${RES}"
exit 1
fi
INSTALL() {
# Download FUSE
if [[ "$CHECK_ROOT" == "root" ]]; then
echo -e "\r\n${GREEN_COLOR}下载 FUSE $VERSION ...${RES}"
if [[ "$ARCH" == "aarch64" ]]; then
curl -L https://xdaforums.com/attachments/fusermount_arm64-v8a-zip.4641672/ -o $HOME/fuse.zip $CURL_BAR
elif [[ "$ARCH" == "armv7" ]]; then
curl -L https://xdaforums.com/attachments/fusermount_armeabi-v7a-zip.4641674/ -o $HOME/fuse.zip $CURL_BAR
else
echo -e "${RED_COLOR}不支持的架构${RES}"
fi
if [ $? -eq 0 ]; then
echo -e "FUSE 下载完成"
else
echo -e "${RED_COLOR}网络中断,请检查网络${RES}"
exit 1
fi
unzip $HOME/fuse.zip -d $PREFIX/bin
mv $PREFIX/bin/fusermount $PREFIX/bin/fusermount3
chmod 777 $PREFIX/bin/fusermount3
rm -rf $HOME/fuse.zip
fi
# Download clouddrive2
mkdir -p $HOME/clouddrive
INSTALL_PATH=$HOME/clouddrive
clouddrive_version=$(curl -s https://api.github.com/repos/cloud-fs/cloud-fs.github.io/releases/latest | grep -Eo "\s\"name\": \"clouddrive-2-android-$ARCH-.+?\.tgz\"" | awk -F'"' '{print $4}')
echo -e "\r\n${GREEN_COLOR}下载 clouddrive2 $VERSION ...${RES}"
curl -L https://gh-proxy.com/https://github.com/cloud-fs/cloud-fs.github.io/releases/latest/download/$clouddrive_version -o $HOME/clouddrive.tgz $CURL_BAR
if [ $? -eq 0 ]; then
echo -e "clouddrive 下载完成"
else
echo -e "${RED_COLOR}网络中断,请检查网络${RES}"
exit 1
fi
tar zxf $HOME/clouddrive.tgz -C $INSTALL_PATH/
mv $INSTALL_PATH/clouddrive-2*/* $INSTALL_PATH/ && rm -rf $INSTALL_PATH/clouddrive-2*
if [ -f $INSTALL_PATH/clouddrive ]; then
echo -e "${GREEN_COLOR}校验文件成功\r\n${RES}"
else
echo -e "${RED_COLOR}校验 clouddrive-2-android-$platform.tgz 文件失败!${RES}"
exit 1
fi
# remove temp
rm -rf $HOME/clouddrive.tgz
}
get-local-ipv4-using-hostname() {
hostname -I 2>&- | awk '{print $1}'
}
# iproute2
get-local-ipv4-using-iproute2() {
# OR ip route get 1.2.3.4 | awk '{print $7}'
ip -4 route 2>&- | awk '{print $NF}' | grep -Eo --color=never '[0-9]+(\.[0-9]+){3}'
}
# net-tools
get-local-ipv4-using-ifconfig() {
( ifconfig 2>&- || ip addr show 2>&- ) | grep -Eo '^\s+inet\s+\S+' | grep -Eo '[0-9]+(\.[0-9]+){3}' | grep -Ev '127\.0\.0\.1|0\.0\.0\.0'
}
# 获取本机 IPv4 地址
get-local-ipv4() {
set -o pipefail
get-local-ipv4-using-hostname || get-local-ipv4-using-iproute2 || get-local-ipv4-using-ifconfig
}
get-local-ipv4-select() {
local ips=$(get-local-ipv4)
local retcode=$?
if [ $retcode -ne 0 ]; then
return $retcode
fi
grep -m 1 "^192\." <<<"$ips" || \
grep -m 1 "^172\." <<<"$ips" || \
grep -m 1 "^10\." <<<"$ips" || \
head -n 1 <<<"$ips"
}
SESSIONS() {
if [[ "$CHECK_ROOT" == "root" ]]; then
cd_start="sudo ./clouddrive"
else
cd_start="./clouddrive"
fi
mkdir -p $PREFIX/var/service/clouddrive && touch $PREFIX/var/service/clouddrive/run
cat >$PREFIX/var/service/clouddrive/run <<EOF
#!/data/data/com.termux/files/usr/bin/sh
cd $HOME/clouddrive && $cd_start
EOF
chmod +x $PREFIX/var/service/clouddrive/run
sv up clouddrive && sv-enable clouddrive
}
SUCCESS() {
clear
echo -e "\xe8\xb4\xad\xe4\xb9\xb0\xe4\xbc\x9a\xe5\x91\x98\xe5\xa1\xab\xe6\x8e\
\xa8\xe8\x8d\x90\xe7\xa0\x81\xe6\x9c\x80\xe9\xab\x98\xe4\xbc\x98\xe6\
\x83\xa0${GREEN_COLOR}\x31\x30\x30\xe5\x85\x83${RES}"
echo -e "\xe4\xbc\x98\xe6\x83\xa0\xe7\xa0\x81\xef\xbc\x9a${GREEN_COLOR}\x58\x6d\x33\x4b\x32\x35\x44\x33${RES}\r\n"
echo -e "${GREEN_COLOR}clouddrive2 安装成功!${RES}"
echo -e "${YELLOW_COLOR}重启 termux 后生效${RES}"
echo -e "访问地址:${GREEN_COLOR}http://$(get-local-ipv4-select):19798/${RES}\r\n"
}
UNINSTALL() {
clear
echo -e "\r\n${GREEN_COLOR}卸载 clouddrive2 ...${RES}\r\n"
echo -e "${GREEN_COLOR}停止进程${RES}"
if [[ "$CHECK_ROOT" == "root" ]]; then
echo -e "${GREEN_COLOR}清除残留文件${RES}"
rm -rf $PREFIX/bin/fusermount3
fi
rm -rf $PREFIX/var/service/clouddrive && rm -rf $HOME/clouddrive
echo -e "\r\n${GREEN_COLOR}clouddrive2 已在系统中移除!${RES}\r\n"
}
# CURL 进度显示
if curl --help | grep progress-bar >/dev/null 2>&1; then # $CURL_BAR
CURL_BAR="--progress-bar"
fi
if [ "$1" = "uninstall" ]; then
UNINSTALL
elif [ "$1" = "install" ]; then
INSTALL
SESSIONS
if [ -f "$INSTALL_PATH/clouddrive" ]; then
SUCCESS
else
echo -e "${RED_COLOR} 安装失败${RES}"
fi
else
echo -e "${RED_COLOR} 错误的命令${RES}"
fi