-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmakepersistence
executable file
·102 lines (90 loc) · 2.53 KB
/
makepersistence
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
#!/usr/bin/env bash
whereami=$(dirname $0)
if [[ -f "$whereami/makefreepto" ]]; then
source "${whereami}/makefreepto" source
elif [[ -f "/usr/bin/makefreepto" ]]; then
source './makefreepto' source
else
echo "Can't find makefreepto" >&2
exit 1
fi
#3 phases: make partition, randomfill, create
nphases=4
makepersistence_usage() {
cat <<EOF
$0 [options] PARTITION
where options can be:
-r skip random filling (use only if you know what you are doing)
-R DEV use DEV as random source instead of urandom (i.e.: /dev/frandom)
-p set password (defaul is "freepto")
-s set secure random password (default is "freepto")
-f set filesystem type: ext4 or btrfs (with lzo) (default is "ext4")
EOF
}
skip_random=0
password="freepto"
random_device="${random_device:-/dev/urandom}"
fs="ext4"
while getopts 'rf:R:p:si:' opt; do
case $opt in
r)
skip_random=1
nphases=$((nphases - 1))
;;
f)
fs=$OPTARG
;;
p)
password=$OPTARG
;;
R)
random_device=$OPTARG
;;
s)
password=`tr -dc 'a-zA-H0-9' < /dev/urandom | head -c 12`
_ok "Your LUKS random passphrase is: $LRED$password$Z"
;;
\?)
_error "Invalid option: -$OPTARG"
makepersistence_usage
exit 1
;;
esac
done
shift $((OPTIND-1))
if [ $# != 1 ];then
_error "Wrong argument number"
makepersistence_usage
exit 1
fi
partition="$1"
partnum="${partition:$((${#partition}-1)):1}"
device=${partition%?}
if ! [ $partnum -eq $partnum ]; then ### ugly trick
_fatal "$partition does not end with a number; are you giving a whole device as argument?"
fi
if [ $partnum -lt 2 ]; then
_fatal "$partition is the first partition on the disk; I don't believe this is a true partition"
fi
###TODO: create $partition
if [[ ! -b "$partition" ]]; then
_phase "Creating partition"
echo -e "n\np\n${partnum}\n\n\nw" | fdisk ${device}
sleep 1
partprobe
sleep 1
if [[ ! -b "$partition" ]]; then
_fatal "The creation of partition ${partition} on ${device} has
failed. Aborting"
fi
fi
# write random data on crypto partition:
if [[ $skip_random -eq 0 ]]; then
_phase "Writing random data on crypto partition!"
randomfill "${partition}"
sleep 2
fi
_phase "Create persistence"
persistence_create "${partition}" "${password}"
_ok "All done"
# vim: set ts=4 sw=4 et ft=sh fdm=marker: