summaryrefslogtreecommitdiff
path: root/ezjail-admin
diff options
context:
space:
mode:
authorerdgeist <erdgeist@erdgeist.org>2006-02-09 16:43:24 +0000
committererdgeist <erdgeist@erdgeist.org>2006-02-09 16:43:24 +0000
commitc1618f230d96677380e7b6044417b3f69b129630 (patch)
treefb6d0cbee406910d5e0715df9e5a5b90dcdc792b /ezjail-admin
parent7e4d3e19016aa78c8449e71d2cdda27ccb54cc97 (diff)
Cosmetics.
Diffstat (limited to 'ezjail-admin')
-rwxr-xr-xezjail-admin94
1 files changed, 42 insertions, 52 deletions
diff --git a/ezjail-admin b/ezjail-admin
index cf3ddf9..b5d2df0 100755
--- a/ezjail-admin
+++ b/ezjail-admin
@@ -35,8 +35,7 @@ case "$1" in
35######################## ezjail-admin CREATE ######################## 35######################## ezjail-admin CREATE ########################
36create) 36create)
37 shift 37 shift
38 args=`getopt xf:r: $*` 38 args=`getopt xf:r: $*` || exerr "Usage: `basename -- $0` create [-f flavour] [-r jailroot] [-x] jailname jailip"
39 [ $? = 0 ] || exerr "Usage: `basename -- $0` create [-f flavour] [-r jailroot] [-x] jailname jailip"
40 39
41 newjail_root= 40 newjail_root=
42 newjail_flavour= 41 newjail_flavour=
@@ -57,17 +56,16 @@ create)
57 # we need at least a name and an ip for new jail 56 # we need at least a name and an ip for new jail
58 [ "${newjail_name}" -a "${newjail_ip}" -a $# = 2 ] || exerr "Usage: `basename -- $0` create [-f flavour] [-r jailroot] [-x] jailname jailip" 57 [ "${newjail_name}" -a "${newjail_ip}" -a $# = 2 ] || exerr "Usage: `basename -- $0` create [-f flavour] [-r jailroot] [-x] jailname jailip"
59 58
60 # check, whether ezjail-update has been called. existence of 59 # check, whether ezjail-update has been called. existence of
61 # ezjail_jailbase is our indicator 60 # ezjail_jailbase is our indicator
62 [ -d ${ezjail_jailbase} ] || exerr "Error: base jail does not exist. Please run 'ezjail-admin update' first." 61 [ -d ${ezjail_jailbase} ] || exerr "Error: base jail does not exist. Please run 'ezjail-admin update' first."
63 62
64 # relative paths don't make sense in rc.scripts 63 # relative paths don't make sense in rc.scripts
65 [ "${ezjail_jaildir#/}" = "${ezjail_jaildir}" ] && exerr "Error: Need an absolute path in ezjail_jaildir, it currently is set to: ${ezjail_jaildir}." 64 [ ${ezjail_jaildir%%[!/]*} ] && exerr "Error: Need an absolute path in ezjail_jaildir, it currently is set to: ${ezjail_jaildir}."
66 65
67 # jail names must not irritate file systems, excluding dots 66 # jail names must not irritate file systems, excluding dots from this list
68 # from this list was done intentionally to permit foo.com 67 # was done intentionally to permit foo.com style directory names, however,
69 # style directory names, however, the jail name will be 68 # the jail name will be foo_com in most scripts
70 # foo_com in most scripts
71 69
72 newjail_name=`echo -n ${newjail_name} | tr /~ __` 70 newjail_name=`echo -n ${newjail_name} | tr /~ __`
73 newjail_nname=`echo -n "${newjail_name}" | tr -c [:alnum:] _` 71 newjail_nname=`echo -n "${newjail_name}" | tr -c [:alnum:] _`
@@ -77,24 +75,23 @@ create)
77 # so check, whether we might be running into problems 75 # so check, whether we might be running into problems
78 [ -e ${ezjail_jailcfgs}/${newjail_nname} ] && exerr "Error: an ezjail config already exists at ${ezjail_jailcfgs}/${newjail_nname}. Please rename the ezjail." 76 [ -e ${ezjail_jailcfgs}/${newjail_nname} ] && exerr "Error: an ezjail config already exists at ${ezjail_jailcfgs}/${newjail_nname}. Please rename the ezjail."
79 77
80 # if jail root specified on command line is not absolute, 78 # if jail root specified on command line is not absolute, make it absolute
81 # make it absolute inside our jail directory 79 # inside our jail directory
82 [ "${newjail_root#/}" = "${newjail_root}" ] && newjail_root=${ezjail_jaildir}/${newjail_root} 80 [ ${newjail_root%%[!/]*} ] && newjail_root=${ezjail_jaildir}/${newjail_root}
83 81
84 # if jail root specified on command line does not lie 82 # if jail root specified on command line does not lie within our jail
85 # within our jail directory, we need to create a softlink 83 # directory, we need to create a softlink
86 if [ "${newjail_root##${ezjail_jaildir}}" = "${newjail_root}" ]; then 84 if [ "${newjail_root##${ezjail_jaildir}}" = "${newjail_root}" ]; then
87 newjail_softlink=${ezjail_jaildir}/`basename -- ${newjail_root}` 85 newjail_softlink=${ezjail_jaildir}/`basename -- ${newjail_root}`
88 [ -e ${newjail_softlink} -a "${newjail_fill}" = "YES" ] && exerr "Error: an ezjail already exists at ${newjail_softlink}." 86 [ -e ${newjail_softlink} -a "${newjail_fill}" = "YES" ] && exerr "Error: an ezjail already exists at ${newjail_softlink}."
89 fi 87 fi
90 88
91 # do some sanity checks on the selected flavour (if any) 89 # do some sanity checks on the selected flavour (if any)
92 if [ ${newjail_flavour} ]; then 90 [ "${newjail_flavour}" -a ! -d ${ezjail_flavours}/${newjail_flavour} ] && exerr "Error: Flavour config directory ${ezjail_flavours}/${newjail_flavour} not found."
93 [ -d ${ezjail_flavours}/${newjail_flavour}/ ] || exerr "Error: Flavour config directory ${ezjail_flavours}/${newjail_flavour} not found."
94 fi
95 91
96 # All sanity checks that may lead to errors are hopefully 92 #
97 # passed here 93 # All sanity checks that may lead to errors are hopefully passed here
94 #
98 95
99 # now take a copy of our template jail 96 # now take a copy of our template jail
100 if [ "${newjail_fill}" = "YES" ]; then 97 if [ "${newjail_fill}" = "YES" ]; then
@@ -106,12 +103,12 @@ create)
106 # if a soft link is necessary, create it now 103 # if a soft link is necessary, create it now
107 [ ${newjail_softlink} ] && ln -s ${newjail_root} ${newjail_softlink} 104 [ ${newjail_softlink} ] && ln -s ${newjail_root} ${newjail_softlink}
108 105
109 # if the automount feature is not disabled, this 106 # if the automount feature is not disabled, this fstab entry for new jail
110 # fstab entry for new jail will be obeyed 107 # will be obeyed
111 echo ${ezjail_jailbase} ${newjail_root}/basejail nullfs ro 0 0 > /etc/fstab.${newjail_nname} 108 echo ${ezjail_jailbase} ${newjail_root}/basejail nullfs ro 0 0 > /etc/fstab.${newjail_nname}
112 109
113 # now, where everything seems to have gone right, 110 # now, where everything seems to have gone right, create control file in
114 # create control file in ezjails config dir 111 # ezjails config dir
115 mkdir -p ${ezjail_jailcfgs} 112 mkdir -p ${ezjail_jailcfgs}
116 echo export jail_${newjail_nname}_hostname=\"${newjail_name}\" > ${ezjail_jailcfgs}/${newjail_nname} 113 echo export jail_${newjail_nname}_hostname=\"${newjail_name}\" > ${ezjail_jailcfgs}/${newjail_nname}
117 echo export jail_${newjail_nname}_ip=\"${newjail_ip}\" >> ${ezjail_jailcfgs}/${newjail_nname} 114 echo export jail_${newjail_nname}_ip=\"${newjail_ip}\" >> ${ezjail_jailcfgs}/${newjail_nname}
@@ -125,20 +122,19 @@ create)
125 122
126 # Final steps for flavour installation 123 # Final steps for flavour installation
127 if [ ${newjail_flavour} ]; then 124 if [ ${newjail_flavour} ]; then
128 # install files, packages and config to new jail 125 # install files and config to new jail
129 # user creating, chown and package installation on jails startup
130 cd ${ezjail_flavours}/${newjail_flavour} 126 cd ${ezjail_flavours}/${newjail_flavour}
131 find * | cpio -p -v ${newjail_root} > /dev/null 127 find * | cpio -p -v ${newjail_root} > /dev/null
132 128
133 if [ -f ${ezjail_share}/ezjail.flavour ]; then 129 # If a config is found, make it auto run on jails startup
130 if [ -f ${newjail_root}/ezjail.flavour ]; then
134 ln -s /ezjail.flavour ${newjail_root}/etc/rc.d/ezjail-config.sh 131 ln -s /ezjail.flavour ${newjail_root}/etc/rc.d/ezjail-config.sh
135 chmod 0700 ${newjail_root}/etc/rc.d/ezjail-config.sh 132 chmod 0700 ${newjail_root}/etc/rc.d/ezjail-config.sh
136 echo "Note: Shell scripts installed, flavourizing on jails first startup." 133 echo "Note: Shell scripts installed, flavourizing on jails first startup."
137 fi 134 fi
138 fi 135 fi
139 136
140 # For user convenience, some scenarios commonly causing 137 # For user convenience some scenarios commonly causing headaches are checked
141 # headaches are checked
142 138
143 # check, whether IP is configured on a local interface, warn if it isnt 139 # check, whether IP is configured on a local interface, warn if it isnt
144 ping -c 1 -m 1 -t 1 -q ${newjail_ip} > /dev/null 140 ping -c 1 -m 1 -t 1 -q ${newjail_ip} > /dev/null
@@ -157,9 +153,8 @@ create)
157######################## ezjail-admin DELETE ######################## 153######################## ezjail-admin DELETE ########################
158delete) 154delete)
159 shift 155 shift
160 args=`getopt w $*` 156 args=`getopt w $*` || exerr "Usage: `basename -- $0` delete [-w] jailname"
161 [ $? = 0 ] || exerr "Usage: `basename -- $0` delete [-w] jailname" 157
162
163 oldjail_wipe= 158 oldjail_wipe=
164 159
165 set -- ${args} 160 set -- ${args}
@@ -180,19 +175,16 @@ delete)
180 # check for existence of jail in our records 175 # check for existence of jail in our records
181 [ -f ${ezjail_jailcfgs}/${oldjail_nname} ] || exerr "Error: Nothing known about jail ${oldjail_name}." 176 [ -f ${ezjail_jailcfgs}/${oldjail_nname} ] || exerr "Error: Nothing known about jail ${oldjail_name}."
182 177
183 # fetch information about the jail to be gone 178 # fetch information about the jail to be gone by parsing our records
184 # by parsing our records
185 . ${ezjail_jailcfgs}/${oldjail_nname} 179 . ${ezjail_jailcfgs}/${oldjail_nname}
186 eval oldjail_rootdir=\"\$jail_${oldjail_nname}_rootdir\" 180 eval oldjail_rootdir=\"\$jail_${oldjail_nname}_rootdir\"
187 181
188 # if jail is still running, refuse to go any further 182 # if jail is still running, refuse to go any further
189 [ -f /var/run/jail_${oldjail_nname}.id ] && exerr "Error: Jail appears to be still running, stop it first.\n(/var/run/jail_${oldjail_nname}.id exists)." 183 [ -f /var/run/jail_${oldjail_nname}.id ] && exerr "Error: Jail appears to be still running, stop it first.\n(/var/run/jail_${oldjail_nname}.id exists)."
190 184
191 # now we know everything we need to let the jail be gone 185 # now we know everything we need to let the jail be gone remove entry
192 # remove entry from ezjail resource structure 186 # from ezjail resource structure, delete fstab.JAILNAME
193 rm -f ${ezjail_jailcfgs}/${oldjail_nname} 187 rm -f ${ezjail_jailcfgs}/${oldjail_nname}
194
195 # delete fstab.JAILNAME
196 rm -f /etc/fstab.${oldjail_nname} 188 rm -f /etc/fstab.${oldjail_nname}
197 189
198 # if there is a soft link pointing to the jail root, remove it 190 # if there is a soft link pointing to the jail root, remove it
@@ -200,11 +192,11 @@ delete)
200 [ -L ${oldjail_softlink} ] && rm ${oldjail_softlink} 192 [ -L ${oldjail_softlink} ] && rm ${oldjail_softlink}
201 193
202 # if wiping the jail was requested, remove it 194 # if wiping the jail was requested, remove it
203 [ "${oldjail_wipe}" = "YES" ] && rm -rf ${oldjail_rootdir} 195 [ ${oldjail_wipe} ] && rm -rf ${oldjail_rootdir}
204 196
205 ;; 197 ;;
206######################## ezjail-admin LIST ######################## 198######################## ezjail-admin LIST ########################
207 list) 199list)
208 jail_list=`ls ${ezjail_jailcfgs}` 200 jail_list=`ls ${ezjail_jailcfgs}`
209 for jail in ${jail_list}; do 201 for jail in ${jail_list}; do
210 . ${ezjail_jailcfgs}/${jail} 202 . ${ezjail_jailcfgs}/${jail}
@@ -218,8 +210,7 @@ delete)
218######################## ezjail-admin UPDATE ######################## 210######################## ezjail-admin UPDATE ########################
219setup|update) 211setup|update)
220 shift 212 shift
221 args=`getopt ipPs: $*` 213 args=`getopt ipPs: $*` || exerr "Usage: `basename -- $0` update [-s sourcetree] [-i] [-pP]"
222 [ $? = 0 ] || exerr "Usage: `basename -- $0` update [-s sourcetree] [-i] [-pP]"
223 214
224 updatejail_installaction="world" 215 updatejail_installaction="world"
225 updatejail_provideports= 216 updatejail_provideports=
@@ -236,7 +227,7 @@ setup|update)
236 done 227 done
237 228
238 if [ "${updatejail_installaction}" = "none" ]; then 229 if [ "${updatejail_installaction}" = "none" ]; then
239 # check, whether ezjail-update has been called. existence of 230 # check, whether ezjail-update has been called. existence of
240 # ezjail_jailbase is our indicator 231 # ezjail_jailbase is our indicator
241 [ -d ${ezjail_jailbase} ] || exerr "Error: base jail does not exist. You cannot fill base jails ports tree before creating it. Please run 'ezjail-admin update' first." 232 [ -d ${ezjail_jailbase} ] || exerr "Error: base jail does not exist. You cannot fill base jails ports tree before creating it. Please run 'ezjail-admin update' first."
242 else 233 else
@@ -244,18 +235,17 @@ setup|update)
244 [ -d ${ezjail_sourcetree} ] || exerr "Cannot find your copy of the FreeBSD source tree in ${ezjail_sourcetree}." 235 [ -d ${ezjail_sourcetree} ] || exerr "Cannot find your copy of the FreeBSD source tree in ${ezjail_sourcetree}."
245 [ -e ${ezjail_sourcetree}/Makefile ] || exerr "Your source tree in ${ezjail_sourcetree} seems to be incomplete (Makefile missing)." 236 [ -e ${ezjail_sourcetree}/Makefile ] || exerr "Your source tree in ${ezjail_sourcetree} seems to be incomplete (Makefile missing)."
246 237
247 # Normally fulljail should be renamed by past ezjail-admin commands 238 # Normally fulljail should be renamed by past ezjail-admin commands.
248 # However those may have failed 239 # However those may have failed
249 rm -rf ${ezjail_jailfull}; mkdir -p ${ezjail_jailfull} 240 chflags -R noschg ${ezjail_jailfull}; rm -rf ${ezjail_jailfull};
241 mkdir -p ${ezjail_jailfull}
250 242
251 # make our world 243 # make our world
252 cd ${ezjail_sourcetree} 244 cd ${ezjail_sourcetree}
253 make ${updatejail_installaction} DESTDIR=${ezjail_jailfull} 245 make ${updatejail_installaction} DESTDIR=${ezjail_jailfull} || exerr "make ${updatejail_installaction} failed."
254 [ $? = 0 ] || exerr "make ${updatejail_installaction} failed."
255 246
256 # setup world 247 # setup world
257 make distribution DESTDIR=${ezjail_jailfull} 248 make distribution DESTDIR=${ezjail_jailfull} || exerr "make distribution failed."
258 [ $? = 0 ] || exerr "make distribution failed."
259 249
260 # Fill basejail from installed world 250 # Fill basejail from installed world
261 cd ${ezjail_jailfull} 251 cd ${ezjail_jailfull}
@@ -263,8 +253,7 @@ setup|update)
263 # directories with permission 0700 which is bad 253 # directories with permission 0700 which is bad
264 mkdir -p ${ezjail_jailbase}/usr 254 mkdir -p ${ezjail_jailbase}/usr
265 for dir in bin lib libexec sbin usr/bin usr/include usr/lib usr/libexec usr/sbin usr/src usr/share; do 255 for dir in bin lib libexec sbin usr/bin usr/include usr/lib usr/libexec usr/sbin usr/src usr/share; do
266 find ${dir} | cpio -d -p -v ${ezjail_jailbase} 256 find ${dir} | cpio -d -p -v ${ezjail_jailbase} || exerr "Installation of ${dir} failed."
267 [ $? = 0 ] || exerr "Installation of ${dir} failed."
268 chflags -R noschg ${dir}; rm -r ${dir}; ln -s /basejail/${dir} ${dir} 257 chflags -R noschg ${dir}; rm -r ${dir}; ln -s /basejail/${dir} ${dir}
269 done 258 done
270 mkdir basejail 259 mkdir basejail
@@ -299,9 +288,10 @@ setup|update)
299 [ $? = 0 ] || exerr "Updating ports failed." 288 [ $? = 0 ] || exerr "Updating ports failed."
300 fi 289 fi
301 290
302 # A ports collection inside jails is hardly useful w/o an appropriate /etc/make.conf 291 # A ports collection inside jails is hardly useful w/o an appropriate
303 # if we find basejail/usr/ports/Makefile, assume that the admin wants a working make.conf in new jails 292 # /etc/make.conf. If we find basejail/usr/ports/Makefile, assume that
304 # also a softlink to the ports in basejail is provided 293 # the admin wants a working make.conf in new jails also a softlink to
294 # the ports in basejail is provided
305 if [ -f ${ezjail_jailbase}/usr/ports/Makefile ]; then 295 if [ -f ${ezjail_jailbase}/usr/ports/Makefile ]; then
306 # no /usr/ports? link to /basejail/usr/ports 296 # no /usr/ports? link to /basejail/usr/ports
307 [ -e ${ezjail_jailtemplate}/usr/ports ] || ln -s /basejail/usr/ports ${ezjail_jailtemplate}/usr/ports 297 [ -e ${ezjail_jailtemplate}/usr/ports ] || ln -s /basejail/usr/ports ${ezjail_jailtemplate}/usr/ports