forked from 07031218/normal-shell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
overlay.sh
115 lines (111 loc) · 3.3 KB
/
overlay.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
#!/bin/bash
RED='\E[1;31m'
RED_W='\E[41;37m'
END='\E[0m'
red='\033[0;31m'
green='\033[0;32m'
yellow='\033[0;33m'
plain='\033[0m'
check_root(){
if [[ $EUID -ne 0 ]]; then
echo -e "${Red}本脚本必须root账号运行,请切换root用户后再执行本脚本!${END}"
exit 1
fi
}
check_root
if cat /etc/issue | grep -Eqi "debian"; then
release="debian"
elif cat /etc/issue | grep -Eqi "Armbian"; then
release="Armbian"
elif cat /etc/issue | grep -Eqi "Ubuntu"; then
release="ubuntu"
else
echo -e "${red}脚本仅在Debian和Ubuntu系统上测试通过,请使用 Debian或Ubuntu系统!\n${plain}" && exit 1
fi
echo -ne "${yellow}请输入GD网盘的初始挂载点路径:${plain}"
read lowerdir
if [[ $lowerdir == "" ]]; then
echo "${red}输入错误,程序退出。${plain}"
exit 1
fi
echo -ne "${yellow}请输入upperdir(削刮文件)的存放路径:${plain}"
read upperdir
if [[ $upperdir == "" ]]; then
echo -e "${red}输入错误,程序退出。${plain}"
exit 1
fi
if [[ ! -d ${upperdir} ]]; then
mkdir -p ${upperdir}
fi
echo -ne "${yellow}请输入workdir(overlay分层文件临时活动目录)的路径:${plain}"
read workdir
if [[ $workdir == "" ]]; then
echo -e "${red}输入错误,程序退出。${plain}"
exit 1
fi
if [[ ! -d ${workdir} ]]; then
mkdir -p ${workdir}
fi
echo -ne "${yellow}请输入merga目录(overlay分层文件顶端合并目录)的路径:${plain}"
read mountdir
if [[ $mountdir == "" ]]; then
echo -e "${red}输入错误,程序退出。${plain}"
exit 1
fi
if [[ ! -d ${mountdir} ]]; then
mkdir -p ${mountdir}
fi
$(which mount) -t overlay -o lowerdir=${lowerdir},upperdir=${upperdir},workdir=${workdir} overlay ${mountdir}
if [[ "$?" -eq 0 ]]; then
echo -e "${green}已经完成overlayFS文件系统挂载,开始将挂载写入开机自启动。${plain}"
if [[ ! -f /etc/rc.local ]]; then
cat > /etc/rc.local <<EOF
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
# bash /root/bindip.sh
sleep 30s
$(which mount) -t overlay -o lowerdir=${lowerdir},upperdir=${upperdir},workdir=${workdir} overlay ${mountdir}
exit 0
EOF
chmod +x /etc/rc.local
cat > /etc/systemd/system/rc-local.service <<EOF
[Unit]
Description=/etc/rc.local
After=network.target
ConditionPathExists=/etc/rc.local
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99
[Install]
WantedBy=multi-user.target
EOF
systemctl start rc-local
systemctl enable rc-local
if [[ "$?" -eq 0 ]]; then
echo -e "${green}将挂载写入开机自启动成功。${plain}"
fi
else
sed -i '$d' /etc/rc.local
echo -e "sleep 30s\n$(which mount) -t overlay -o lowerdir=${lowerdir},upperdir=${upperdir},workdir=${workdir} overlay ${mountdir}\nexit 0" >> /etc/rc.local
if [[ "$?" -eq 0 ]]; then
echo -e "${green}将挂载写入开机自启动成功。${plain}"
fi
fi
else
echo -e "${red}overlayFS文件系统挂载失败,程序退出。${plain}"
exit 1
fi