-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathASM_format
More file actions
executable file
·198 lines (167 loc) · 5.94 KB
/
ASM_format
File metadata and controls
executable file
·198 lines (167 loc) · 5.94 KB
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
#!/bin/bash
function ctrl_c(){
printf "\n\n${r}[ - ]${e} Bye! ${r}<3${e}\n\n"
stty echo; exit 0
}
function helpPanel(){
printf "%125s\n\n" " " | tr " " "-"
cat <<-!
[ ! ] Posible things that you may know if you see this:
[ x ] You must run this script as a root.
[ x ] This script was made only for Solaris O.S
[ x ] You entered an invalid parameter or are missing one.
[ - ] This can be showed with the flag -h
`printf "%117s\n" " " | tr " " "-"`
HELP PANEL!
`printf "%117s\n" " " | tr " " "-"`
Execute this script as a bash or give it the right permissions to execute ./
USAGE:
-r You can specify a range for example: 10-50 or it work as a single number.
-d You must specify the nomenclature of device, for example: starts with c0d or c1d or c2d and so on..
to know what type of nomenclature of device has you, try to do an echo | format
Example output:
AVAILABLE DISK SELECTIONS:
0. c1d0 <QEMU HAR-QM0000-0001-20.00GB> # <- as you can see its start with c1d and 0 its the id of the disk.
/pci@0,0/pci-ide@1,1/ide@0/cmdk@0,0
EXAMPLES:
1. Format disk from 20 to 50 with nomenclature of device c0d
./ASM_format -r 20-50 -d c0d
2. Format a single disk with number 10 with nomenclature of device c2d
./ASM_format -r 10 -d c2d
!
printf "\n%125s\n" " " | tr " " "-"
}
function single_disk(){
while true; do
read -p "Are you sure to continue (y/n)?: " answer
case $answer in
y)
printf "${y}[!]${e} Starting to formatting disk(s). Please, wait...\n";
format -d ${disk} <<-! 2>&1 >/dev/null
${process[0]}
${process[1]}
${process[2]}
${process[3]}
${process[4]}
${process[5]}
${process[6]}
${process[7]}
${process[8]}
${process[9]}
${process[10]}
${process[11]}
${process[12]}
${process[13]}
${process[14]}
${process[15]}
${process[16]}
${process[17]}
${process[18]}
${process[19]}
${process[20]}${disk##${device}}
${process[21]}
${process[22]}
!
printf "${lg}[+]${e} ${cy}We're done!${e} ${r}<3${e}\n"; break ;;
n)
printf "\n\n${y}[!]Be aware!!!${e}\n\n"; break;;
*)
set -e; printf "${r}Please select a valid option!\n${e}" ;;
esac
done
}
function range_disks(){
while true; do
read -p "Are you sure to continue (y/n)?: " answer
case $answer in
y)
printf "${y}[!]${e} Starting to formatting disk(s). Please, wait...\n";
for d in ${arr[@]}; do
format -d ${d} <<-!
${process[0]}
${process[1]}
${process[2]}
${process[3]}
${process[4]}
${process[5]}
${process[6]}
${process[7]}
${process[8]}
${process[9]}
${process[10]}
${process[11]}
${process[12]}
${process[13]}
${process[14]}
${process[15]}
${process[16]}
${process[17]}
${process[18]}
${process[19]}
${process[20]}${d##${device}}
${process[21]}
${process[22]}
!
done 2>&1 >/dev/null;
printf "${lg}[+]${e} ${cy}We're done!${e} ${r}<3${e}\n"; break ;;
n)
printf "\n\n${y}[!]Be aware!!!${e}\n\n"; break;;
*)
set -e; printf "${r}Please select a valid option!\n${e}" ;;
esac
done
}
function checking_disk(){
read -d "" -ra num <<< ${range_disks//-/$'\n'}
[[ ${#num[@]} -eq 2 ]] && { \
for (( x=${num[0]}; x<=${num[1]}; x++ )){
declare disk="${device}${x}"
format -e ${disk} <<! 2>&1 >/dev/null
quit
!
[[ ! $? -eq 0 ]] && { printf "${r}[x]${e} Not disk ${disk} found.\n\n"; exit 1 ;}
declare -a arr+=(${disk})
}
printf "%s\n${y}%s${e}\n" "We're gonna formatting theses disks:" ${arr[*]}
range_disks
} || { \
declare disk="${device}${num}"
format -e ${disk} <<! 2>&1 >/dev/null
quit
!
[[ ! $? -eq 0 ]] && { \
printf "${r}[x]${e} Not disk found.\n\n"
} || { \
printf "%s\n${y}%s${e}\n" "We're gonna formatting this disk:" ${disk}
single_disk
}
}
}
function __main__(){
declare -g y="\e[33m"
declare -g r="\e[31m"
declare -g mg="\e[35m"
declare -g cy="\e[36m"
declare -g lg="\e[92m"
declare -g e="\e[0m"
declare -i count=0
declare -a process=("p" "p" "0" "" "" "0" "0" "1" "" "" "0" "0" "6" "" "" "9" "$" "p" "q" "volname" "ASM" "y" "q")
export PATH=/usr/bin:/usr/sbin
local OPTIND
shopt -s extglob
while getopts ":r:d:h:" args; do
case $args in
r) range_disks=($OPTARG); let count++ ;;
d) device=$OPTARG; let count++ ;;
h) helpPanel=$OPTARG ;;
esac
done
[[ $count -ne 2 || ! ${UID} -eq 0 || ! ${OSTYPE} =~ solaris* ]] && { \
printf ${y}; helpPanel ;printf ${e}
} || { \
trap ctrl_c SIGINT
checking_disk
shopt -u extglob
}
}
__main__ "$@"