-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathusb-iso-loader-clean.sh
More file actions
executable file
·145 lines (116 loc) · 3.84 KB
/
usb-iso-loader-clean.sh
File metadata and controls
executable file
·145 lines (116 loc) · 3.84 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
#!/bin/bash
####################################################################################################
# Color definations
####################################################################################################
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
CYAN='\033[0;46m'
LIGHT_RED='\e[1;31m'
LIGHT_BLUE='\033[1;34m'
LIGHT_GREEN='\033[1;32m'
NC='\033[0m' # No Color
####################################################################################################
# DEBUG
####################################################################################################
# set -x
####################################################################################################
# Functions
####################################################################################################
print_help () {
echo
echo -e "${CYAN}USB Iso Loader Cleaner${NC}"
echo
echo "Clears the usb"
echo "Usage: usb-iso-loader-clean.sh -d <DEV>"
echo
echo "-d, --device device"
echo "-n, --no-color no coloring"
echo "-h, --help help"
echo
echo -e "${RED}Attention:${NC} This script needs to root user privileges."
echo
}
print_help_success () {
print_help
exit
}
print_help_fail () {
print_help
exit 1
}
no_color () {
RED=''
GREEN=''
BLUE=''
CYAN=''
LIGHT_RED=''
LIGHT_BLUE=''
LIGHT_GREEN=''
NC=''
}
####################################################################################################
# Check the user whether it is root
####################################################################################################
if [[ $EUID -ne 0 ]]; then
echo -e "${RED}This script must be run as root${NC}" 1>&2
exit 1
fi
####################################################################################################
# Parse parameters
####################################################################################################
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-h|--help)
print_help_success
;;
-d|--device)
DEVICE="$2"
shift # past argument
shift # past value
;;
-n|--no-color)
no_color
shift
shift
;;
*) # unknown option
print_help_fail
;;
esac
done
####################################################################################################
# Parameter checks
####################################################################################################
if [[ -z $DEVICE ]]; then
print_help_fail
fi
####################################################################################################
# Unmounting partitions
####################################################################################################
echo -e "${LIGHT_BLUE}Unmounting Partitions...${NC}"
umount -f ${DEVICE}*
####################################################################################################
# Create partitions
####################################################################################################
echo -e "${LIGHT_GREEN}Creating Partitions...${NC}"
sgdisk \
--clear \
--mbrtogpt \
--new 1:: --typecode=1:0700 --change-name=1:'' \
"${DEVICE}"
####################################################################################################
# List harddisk partition table
####################################################################################################
echo -e "${LIGHT_GREEN}Partitions Created!${NC}"
gdisk -l "${DEVICE}"
####################################################################################################
# Format partitions
####################################################################################################
PARTITION=${DEVICE}1
echo -e "${LIGHT_BLUE}Formatting ${LIGHT_RED}${BOOT_PARTITION}${NC}"
mkfs.vfat $PARTITION
# Finished
echo -e "${LIGHT_GREEN}Finished!${NC}"