forked from lone-wind/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
incr.sh
108 lines (106 loc) · 2.95 KB
/
incr.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
#!/bin/bash
#Build by lone-wind
rm -rf incr.sh
#检测硬盘
hd_check () {
if [ ! $(df | grep mmcblk) ]; then
if [ ! $(df | grep sd) ]; then
echo -e '\e[91m无法识别硬盘,退出\e[0m' && exit;
else
hd_id=$(df | grep /dev/sd | tail -n1 | awk '{print substr($1, 6, length($1)-6)}') && part_id=${hd_id}3
fi
else
hd_id=$(df | grep /dev/mmcblk | tail -n1 | awk '{print substr($1, 6, length($1)-7)}') && part_id=${hd_id}p3
fi
part_check
}
#检测分区
part_check () {
if fdisk -l | grep -q /dev/${part_id}; then
echo -e '\e[92m分区正常\e[0m'
else
echo -e '\e[91m分区异常,开始修改\e[0m'
if lscpu | grep -i -q arm; then
part_incr_arm
else
part_incr_x86
fi
fi
}
#新建分区
part_incr_x86 () {
if [ ! $(echo ${part_id} | grep p) ]; then
block_num=$(fdisk -l | grep /dev/${hd_id}2 | awk '{print $3}')
else
block_num=$(fdisk -l | grep /dev/${hd_id}p2 | awk '{print $3}')
fi
fdisk /dev/${hd_id} <<EOF
n
3
$(($block_num+1))
w
EOF
}
part_incr_arm () {
if [ ! $(echo ${part_id} | grep p) ]; then
block_num=$(fdisk -l | grep /dev/${hd_id}2 | awk '{print $3}')
else
block_num=$(fdisk -l | grep /dev/${hd_id}p2 | awk '{print $3}')
fi
fdisk /dev/${hd_id} <<EOF
n
p
3
$(($block_num+1))
w
EOF
}
#检测文件
file_check () {
if cat /proc/mounts | grep -q /mnt/${part_id}\ ext4; then
echo -e '\e[92m新挂载点正常\e[0m'
continue;
else
echo -e '\e[91m新挂载点异常,开始修改\e[0m'
if opkg list | grep -q "docker"; then
if /etc/init.d/dockerd status | grep -q "running"; then
/etc/init.d/dockerd stop
fi
fi
if cat /proc/mounts | grep -q "/dev/${part_id}"; then
umount /dev/${part_id}
fi
mkfs.ext4 -F /dev/${part_id}
if [ ! -d /mnt/${part_id} ] && [ ! -d /mnt/${part_id}/docker ]; then
mkdir /mnt/${part_id}
mkdir /mnt/${part_id}/docker
fi
mount /dev/${part_id} /mnt/${part_id}
fi
}
#检测容器
docker_check () {
if opkg list | grep -q "docker"; then
if cat /etc/config/dockerd | grep -q "/mnt/${part_id}"; then
echo -e '\e[92mDocker根目录正常\e[0m'
continue;
else
echo -e '\e[91mDocker根目录异常,开始修改\e[0m'
docker_id=$(cat /etc/config/dockerd | grep data_root | awk '{print substr($3, 2, length($3)-10)}')
sed -i "s?${docker_id}?/mnt/${part_id}?" /etc/config/dockerd
if /etc/init.d/dockerd status | grep -q "inactive"; then
/etc/init.d/dockerd start
fi
fi
fi
}
#程序开始
incr_begin () {
hd_check
file_check
docker_check
sleep 5
echo -e '\e[92m脚本结束,请查看分区\e[0m'
df -h | grep /dev/${part_id}
}
incr_begin