-
Notifications
You must be signed in to change notification settings - Fork 0
/
wipenode.sh
205 lines (173 loc) · 5 KB
/
wipenode.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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#!/bin/bash
# Author: Florian Gabriel (omniflow)
# https://github.com/fl0wm0ti0n
# Begin of the scripts:
# Load DRBL setting and functions
DRBL_SCRIPT_PATH="${DRBL_SCRIPT_PATH:-/usr/share/drbl}"
. $DRBL_SCRIPT_PATH/sbin/drbl-conf-functions
. /etc/drbl/drbl-ocs.conf
. $DRBL_SCRIPT_PATH/sbin/ocs-functions
# load the setting for clonezilla live.
[ -e /etc/ocs/ocs-live.conf ] && . /etc/ocs/ocs-live.conf
# Load language files. For English, use "en_US.UTF-8".
ask_and_load_lang_set en_US.UTF-8
# The above is almost necessary, it is recommended to include them in your own custom-ocs.
# From here, you can write your own scripts.
# functions
search_disks() {
name=$1[@]
listOfDisks=("${!name}")
for i in $(sudo lsblk | grep -E "sd[a-z]|hd[a-z]|nvm[a-z]|vd[a-z]" | cut -d' ' -f1); do listOfDisks+=("/dev/$i") ;done
if [ ${#listOfDisks[@]} -eq 0 ]; then
write_color "fail" "there is no qualified disk!"
termination
fi
}
wipe_disks() {
listOfDisks=()
search_disks listOfDisks
for disk in "${listOfDisks[@]}"; do
write_color "info" "trying to wipe disk $disk ..."
if [ "$g_test" = "false" ] ;then
if ! wipefs "$disk" -a ; then
write_color "fail" "something went wrong wiping the disk $disk!"
termination
else
write_color "successfully wiped disk $disk!"
fi
else
write_color "successfully wiped disk $disk!"
fi
done
}
wipe_disks_manually() {
listOfDisks=()
search_disks listOfDisks
wipe_disks_menu listOfDisks
}
wipe_disks_menu() {
name=$1[@]
listOfDisks=("${!name}")
for i in "${!listOfDisks[@]}"; do
write_color "warn" "Option $i: ${listOfDisks[i]}"
dfinfo=$(df -h "${listOfDisks[i]}")
write_color "info" "$dfinfo"
done
read -r -p "Enter the digit of given options (enter -1 to exit): " option ;
if [ "$option" -eq -1 ] ;then
exit 0
fi
if [ "${listOfDisks[$option]}" = "" ] ;then
write_color "warn" "entry doesnt exist, chose a different one"
wipe_disks_menu listOfDisks
fi
disk=${listOfDisks[$option]}
if [ "$g_test" = "false" ] ;then
write_color "info" "wiped disk $disk"
if ! wipefs "$disk" -a ; then
write_color "fail" "something went wrong wiping the disk $disk!"
termination
else
write_color "successfully wiped disk $disk!"
fi
remove_array_entry listOfDisks "$disk"
else
write_color "successfully wiped disk $disk!"
remove_array_entry listOfDisks "$disk"
fi
if [ ${#listOfDisks[@]} -eq 0 ] ;then
write_color "info" "all disks wiped!"
exit 0
fi
wipe_disks_menu listOfDisks
}
remove_array_entry() {
name=$1[@]
listOfDisks=("${!name}")
disk=$2
for i in "${!listOfDisks[@]}"; do
if [[ ${listOfDisks[i]} = "$disk" ]]; then
unset 'listOfDisks[i]'
fi
done
for i in "${!listOfDisks[@]}"; do
new_array+=( "${listOfDisks[i]}" )
done
listOfDisks=("${new_array[@]}")
unset new_array
}
write_help() {
[ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
echo "-------------------------------------------------------------------"
echo "Helptext of $0"
echo "Default: wipe all disks"
echo "Syntax: $0 [options]"
echo "OPTIONS:"
echo "h -> This helptext"
echo "m -> manual run, existing disks will be listed"
echo "t -> testrun, dont wipe disks for real"
echo "-------------------------------------------------------------------"
echo "made by omniflow [https://github.com/fl0wm0ti0n]"
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
}
termination() {
write_color "fail" "Program terminated!"
write_color "fail" "you can restart the script in the following window!"
exit 1
}
write_color() {
local level=$1
local text=$2
case $level in
"fail")
[ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE
echo "$text"
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
;;
"warn")
[ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
echo "$text"
[ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
;;
"info")
echo "$text"
;;
?)
echo "$text"
;;
esac
}
##################
###### MAIN ######
##################
echo "Starting up $0"
g_task="default"
g_test=false
while getopts 'mht' OPTION; do
case "$OPTION" in
m)
g_task="manually"
;;
t)
g_test=true
write_color "warn" "testrun, doesn't wipe disks for real"
;;
h)
write_help
;;
?)
write_help
;;
esac
done
shift "$((OPTIND -1))"
case "$g_task" in
"manually")
write_color "info" "Wipe by selecting the disk"
wipe_disks_manually
;;
"default")
write_color "info" "Wiping all disks"
wipe_disks
;;
esac