-
Notifications
You must be signed in to change notification settings - Fork 0
/
grow.sh
executable file
·80 lines (67 loc) · 1.67 KB
/
grow.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
#!/bin/zsh
PREFIX=/usr/lib/priv
source $PREFIX/colors.sh
source $PREFIX/conf.sh
if mountpoint -q $PRIV_MOUNT || [[ -b /dev/mapper/$PRIV_DEVICE ]]; then
red "Please unmount storage and close mapping before using this script!"
exit 1
fi
if [[ $UID -ne 0 ]]; then
red "Root access is needed"
exit -1
fi
function usage() {
echo "Usage: priv grow SIZE"
echo " SIZE blocks of 1 MB"
}
if [[ -z $1 ]]; then
red "missing size argument"
usage
exit 1
elif [[ $size =~ ^[0-9]+$ ]]; then
red "invalid size argument: must be a valid positive integer"
usage
exit 1
else
size=$1
fi
blue "We are trying to execute this possibly destructive command!"
red " dd if=/dev/zero bs=1M count=$size >> $PRIV_STORAGE"
bluen "Proceed? (y/N) "
if read -q; then
echo
blue " --> Appending zeros to image file..."
if ! dd if=/dev/zero bs=1M count=$size status=progress >> $PRIV_STORAGE; then
red " --> dd failed, exiting."
exit 3
fi
else
echo
red " --> Aborted."
exit 4
fi
blue "Opening private space..."
if ! [[ -b /dev/mapper/$PRIV_DEVICE ]]; then
if ! cryptsetup open --key-file $PRIV_KEY_FILE $PRIV_STORAGE $PRIV_DEVICE; then
red " --> Failed to open /dev/mapper/$PRIV_DEVICE!"
exit 2
fi
else
blue " --> /dev/mapper/$PRIV_DEVICE already open"
fi
blue "Checking filesystem..."
if e2fsck -f /dev/mapper/$PRIV_DEVICE; then
green " --> Done"
else
red " --> Filesystem checking failed."
exit 5
fi
blue "Actual resize..."
if resize2fs /dev/mapper/$PRIV_DEVICE; then
green " --> Done"
else
red " --> Failed!"
fi
bluen "Closing mapping..."
cryptsetup close $PRIV_DEVICE
greenc " Done"