-
Notifications
You must be signed in to change notification settings - Fork 0
/
s_drive.sh
126 lines (92 loc) · 1.94 KB
/
s_drive.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
#!/bin/bash
export LANG=""
cd ~/setup/
WIZARD=$1
trap bashtrap INT
bashtrap()
{
bash ~/setup/setup.sh
}
function getDrive {
NUM=0
echo ""
for i in `sudo fdisk -l 2>/dev/null | grep "^Disk /" | sed "s/^Disk \([^:]*\): \([^ ]*\) \([^,]*\).*/\1;\2;\3/"`
do
NUM=$(($NUM+1))
DISK=`echo $i | sed "s/^\([^;]*\).*/\1/"`
SIZE=`echo $i | sed "s/^[^;]*;\([^;]*\);\(.*\)/\1 \2/"`
DISKS[$NUM]=$DISK
echo "$NUM) $DISK - $SIZE"
done
read -p "Choose disk: " DISKNUM
DISK=${DISKS[$DISKNUM]}
if [ -z "$DISK" ]
then
echo ""
echo "Sorry, $DISKNUM is not a valid answer"
fi
}
function formatDrive {
DISK=$1
PART=$DISK""1
echo "Formatting and parttitioning disk $DISK | $PART"
echo ""
sudo dd if=/dev/zero of=$DISK bs=512 count=1024 >/dev/null 2>&1
echo -e -n "n\np\n1\n\n\nw\n" | sudo fdisk $DISK >/dev/null 2>&1
RET=$?
if [ "$RET" != "0" ]
then
echo "Failed to partition disk."
exit 1
fi
sync
echo $DISK partitioned.
mkfs.ext4 -L DATA $PART >/dev/null 2>&1
RET=$?
if [ "$RET" != "0" ]
then
echo "Failed to initialise filesystem."
exit 1
fi
sync
echo $PART initialised.
mountDrive $PART
}
function mountDrive {
echo ""
echo "Mounting the drive to /media/data"
sudo mkdir /media/data
sudo mount $1 /media/data
LINE='LABEL=DATA /media/data ext4 defaults 0 2'
grep -q "^LABEL=DATA" /etc/fstab || sudo sh -c 'echo "$LINE" >>/etc/fstab'
finish
}
function finish {
echo "--- Done ---"
sleep 1
endfn
}
function endfn {
echo ""
echo ""
read -p "Press [Enter] key to continue..."
if [ -n "$WIZARD" ]; then
bash ./s_network.sh "$WIZARD"
else
bash ./setup.sh " - Drive & Partitions Done"
fi
}
clear
echo "Drive & Partitions"
echo "-----------------------------------------------"
echo ""
while [ -z "$DISK" ]
do
getDrive
done
read -e -p "Use drive $DISK. Warning all data will be lost on the drive. Continue?: " -i "y" goon
if [ $goon = "y" ]; then
formatDrive $DISK
else
getDrive
fi