-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathprep-storage.sh.wip
283 lines (254 loc) · 6.21 KB
/
prep-storage.sh.wip
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
#!/bin/bash
EXTMEDIA=`ls -la /mnt/*`
MMC0=`ls /dev | grep mmcblk0 | wc | awk '{print $1}'`
MMC1=`ls /dev | grep mmcblk1 | wc | awk '{print $1}'`
USB=`ls /dev | grep sd | wc | awk '{print $1}'`
function warn()
{
echo "######################################################"
echo ""
echo ""
echo "WARNING external SD-card or hard-disk NOT detected"
echo "Please insert SD-card or connect your external hard"
echo "disk before running bootsrap-xo"
echo ""
echo ""
echo "#####################################################"
echo ""
read -p "Press [Enter] key to shutdown"
echo ""
echo ""
echo "shutting down in 5 seconds"
sleep 5
shutdown now
exit 1
}
function unsupported()
{
echo "#####################################################"
echo ""
echo ""
echo "WARNING detected external media partition layout is"
echo "unsuppoted. Please try a different SD-card or usbkey"
echo ""
echo ""
echo "#####################################################"
echo ""
read -p "Press [Enter] key to shutdown"
echo ""
echo ""
echo "shutting down in 5 seconds"
sleep 5
shutdown now
exit 1
}
function library_1st()
{
echo "#####################################################"
echo ""
echo ""
echo "WARNING detected 2 USB storage units. In order to"
echo "protect the data on the one that will not become a"
echo "permanent part of the XS server, please ensure the"
echo "premanent drive is inserted in a slot when turning."
echo "on your XO. Please insert the usb drive containing"
echo "the XSCE installaton media before typing 'bootstrap-xo'"
echo ""
echo ""
echo "#####################################################"
echo ""
echo ""
read -p "Press [Enter] key to shutdown"
echo ""
echo ""
echo "shutting down in 5 seconds"
sleep 5
shutdown now
exit 1
}
function get_devices()
{
FOUNDDEVS=
BLKID=`blkid | awk '{split($0,a,":"); print a[1]}'`
for blk in $BLKID; do
FOUNDDEVS="$FOUNDDEVS $blk"
done
}
function get_root_device()
{
ROOTDEV=
BLKID=`blkid | awk '{split($0,a,":"); print a[1]}'`
for blk in $BLKID; do
ROOTDEV=`echo $blk | grep root`
done
}
function find_repo()
{
MNT=`mount | grep dev/sdb | awk '{print $3}'`
if ! [ -d $MNT/xs-repo ]; then
library_1st
fi
}
function togglepart()
{
cat <<EOF | fdisk /dev/mmcblk0
t
83
w
EOF
partprobe $MEDIADEV
mkfs.ext4 -L library $MEDIADEV
MEDIADEV2=$MEDIADEV
MEDIAMNT=/library
}
function togglepart-usb()
{
cat <<EOF | fdisk /dev/sda
t
83
w
EOF
partprobe $MEDIADEV2
mkfs.ext4 -L library $MEDIADEV2
MEDIAMNT=/mnt/usb0
}
function partition_usb_hd()
{
cat <<EOF | fdisk /dev/sda
n
t
83
w
EOF
partprobe $MEDIADEV2
mkfs.ext4 -L library $MEDIADEV2
MEDIAMNT=/mnt/usb0
}
function find_repo2()
{
echo "findrepo2"
maybe=""
for parts in `ls -la /dev/sd*1`; do
maybe=`findmnt -n -o TARGET -S $parts`
echo "maybe is $maybe"
if ! [ -d $maybe/xs-repo ]; then
MEDIADEV2="/dev/$parts"
break
fi
done
}
##### routine starts here #####
get_devices
DEVS=`echo $FOUNDDEVS | wc | awk '{print $1}'`
echo "found block devices $FOUNDDEVS"
echo "found $MMC0 character devices for mmcblk0"
echo "found $MMC1 character devices for mmcblk1"
if [ $MMC0 = 5 ]; then
if [ $MMC1 = 1 ]; then
unsupported
elif ! [ -b /dev/mmcblk1p1 ]; then
unsupported
fi
if ! [ -n $MMC0 ]; then
MEDIADEV=/dev/mmcblk1p1
fi
fi
if [ $MMC1 = 5 ]; then
if [ $MMC0 = 1 ]; then
unsupported
elif ! [ -b /dev/mmcblk0p1 ]; then
unsupported
fi
if ! [ -n $MMC1 ]; then
MEDIADEV=/dev/mmcblk0p1
fi
fi
MEDIASTRING=`blkid | grep $MEDIADEV`
echo "found $MEDIASTRING"
for i in $MEDIASTRING; do
test=`echo $i | awk '{split($0,a,"="); print a[1]}'`
test2=`echo $i | awk '{split($0,a,"="); print a[2]}' | sed -e 's/"//' | sed -e 's/"//'`
echo "test $test"
echo "test2 $test2"
case $test in
"UUID")
echo "$MEDIADEV is $i"
;;
"TYPE")
if [ $test2 = "vfat" ]; then
MNT=`mount | grep $MEDIADEV | awk '{print $3}'`
echo "unmounting $MNT"
if [ x$MNT != x ]; then
umount $MNT
fi
echo "calling togglepart"
togglepart
break
else
ext_ver=`echo $test2 | grep ext`
echo "test ext_mmc $test2 $ext_ver"
if ! [ -z $ext_ver ];then
echo "found ext2|3|4 filesystem on external SD-card"
MEDIAMNT=/library
MEDIADEV2=$MEDIADEV
break
else
echo "ext2|3|4 not found"
fi
fi
;;
esac
done
echo "usb is $USB "
if [ $USB = 0 ];then
echo "no external usb media found"
elif [ $USB -g 2 ]; then
find_repo2
else
MEDIAMNT=/mnt/usb0
MEDIADEV2=/dev/sda1
fi
if [ -z $MEDIADEV2 ];then
echo "DONE - nothing to do"
warn
else
echo "media dev is: $MEDIADEV2"
fi
if ! [ -c $MEDIADEV2 ];then
# TODO check parts on parent
# then call partition_usb_hd
warn
fi
echo "cleaning fstab"
sed -i '/swap/d' /etc/fstab
sed -i '/usb0/d' /etc/fstab
sed -i '/library/d' /etc/fstab
if [ -d /library ]; then
echo "saving old /library as /library.save"
mv /library /library.save
fi
label=`e2label $MEDIADEV2`
if [ -z $label ];then
e2label $MEDIADEV2 library
fi
if [ $MEDIADEV2 = /dev/sda1 ];then
ln -s /mnt/usb0 /library
else
mkdir /library
fi
uuid=`blkid -s UUID $MEDIADEV2 | gawk '{print $2}'`
echo UUID is $uuid
echo "populating fstab for $MEDIADEV2 using $uuid"
echo "$uuid $MEDIAMNT auto defaults,noatime 0 0" >> /etc/fstab
echo "mounting $uuid at $MEDIAMNT"
mount -a
if ! [ -d $MEDIAMNT/swap ]; then
mkdir $MEDIAMNT/swap
fi
echo "creating swap.img"
dd if=/dev/zero of=$MEDIAMNT/swap/swap.img bs=1024 count=10480
mkswap $MEDIAMNT/swap/swap.img
chown root:root $MEDIAMNT/swap/swap.img
echo "$MEDIAMNT/swap/swap.img swap swap defaults 0 0" >> /etc/fstab
swapon $MEDIAMNT/swap/swap.img
exit 0