-
Notifications
You must be signed in to change notification settings - Fork 0
/
rpi-image-tool
executable file
·160 lines (139 loc) · 3.21 KB
/
rpi-image-tool
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
#!/bin/bash
#
# rpi-image-tool
#
# Copyright 2017, Mike Ray, <[email protected]>
#
# This is free software; you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free
# Software Foundation; either version 3, or (at your option) any later
# version.
#
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this package; see the file COPYING. If not, write to the Free
# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
#
#--code--
export TEXTDOMAIN=rpi-image-tool
export TEXTDOMAINDIR=/usr/local/share/locale
. gettext.sh
. rpi-image-tool.lib
usage() {
USAGE=$(gettext "tool_usage")
echo -e "${USAGE}"
}
#-- Main code
if ! check_root ; then
PROGNAME=$0
echo $(eval_gettext "Script must be run as root, try: sudo \$PROGNAME") ; echo
exit 1
fi
WORKDIR=
IMAGEFILE=
FUNCTION=
SPLIT=64
BLOCKSIZE=1M
BLOCKCOUNT=
BOOTMOUNTPOINT=boot
ROOTMOUNTPOINT=root
while getopts ':C:D:F:I:M:N:c:hs:w:z:' flag ; do
case $flag in
h)
usage
exit 0
;;
C)
FUNCTION=cleanup
WORKDIR=${OPTARG}
break 2
;;
D)
FUNCTION=mountdevice
DEVICE=${OPTARG}
;;
F)
FUNCTION=fixpartuuids
WORKDIR=${OPTARG}
break 2
;;
I)
FUNCTION=installresize
WORKDIR=${OPTARG}
break 2
;;
M)
FUNCTION=mountimage
IMAGEFILE=${OPTARG}
;;
N)
FUNCTION=new
IMAGEFILE=${OPTARG}
;;
c)
BLOCKCOUNT=${OPTARG}
validate_blockcount ${BLOCKCOUNT}
;;
s)
SPLIT=${OPTARG}
validate_split ${SPLIT}
;;
w)
WORKDIR=${OPTARG}
;;
z)
BLOCKSIZE=${OPTARG}
validate_blocksize ${BLOCKSIZE}
;;
(?)
echo $(gettext "Invalid option") >&2
echo >&2
usage
exit 1
;;
:)
echo $(eval_gettext "Option - \$OPTARG requires an argument.") >&2
echo >&2
usage
exit 1
;;
esac
done
[ -z ${WORKDIR} ] && { echo $(gettext "Work directory not set") ; echo ; usage; exit 1 ; }
if [ ${FUNCTION} = 'mountimage' ] || [ $FUNCTION = 'new' ]; then
[ -z "${IMAGEFILE}" ] && { echo $(gettext "Image file name not set") ; echo ; usage; exit 1 ; }
fi
if [ ${FUNCTION} = 'mountdevice' ]; then
[ -z "${DEVICE}" ] && { echo $(gettext "Device name not set") ; echo ; usage ; exit 1 ; }
fi
if [ ${FUNCTION} = 'new' ]; then
[ -z ${BLOCKCOUNT} ] && { echo $(gettext "Block count not set") ; echo ; usage ; exit 1 ; }
[ -z ${BLOCKSIZE} ] && { echo $(gettext "Block size not set") ; echo ; usage ; exit 1 ; }
[ -z ${SPLIT} ] && { echo $(gettext "Split size not set") ; echo ; usage ; exit 1 ; }
fi
case ${FUNCTION} in
cleanup)
clean_up ${WORKDIR}
;;
fixpartuuids)
fix_partuuids ${WORKDIR}
;;
installresize)
install_init_resize_script ${WORKDIR} /usr/lib/raspi-config/init_resize.sh
;;
mountimage)
mount_image ${WORKDIR} ${IMAGEFILE} ${BOOTMOUNTPOINT} ${ROOTMOUNTPOINT}
;;
mountdevice)
mount_device ${WORKDIR} ${DEVICE} ${BOOTMOUNTPOINT} ${ROOTMOUNTPOINT}
;;
new)
new_image ${WORKDIR} ${IMAGEFILE} ${BOOTMOUNTPOINT} ${ROOTMOUNTPOINT} ${BLOCKCOUNT} ${BLOCKSIZE} ${SPLIT}
;;
esac
exit 0