summaryrefslogtreecommitdiff
path: root/ezjail-admin
diff options
context:
space:
mode:
authorerdgeist <erdgeist@erdgeist.org>2006-04-24 14:31:55 +0000
committererdgeist <erdgeist@erdgeist.org>2006-04-24 14:31:55 +0000
commit93be17a3c05a0928418f504e8897b3cedf4c6572 (patch)
tree79164b14551dcd4d08dc6baf7fba101fb695cb4d /ezjail-admin
parent0377eb1c57d28b634f1b21764aafc7656e1c3aaa (diff)
HEADS UP: Common elements in update and install have been moved to a function. portsnap now is default way to maintain your copy of ports tree.
Diffstat (limited to 'ezjail-admin')
-rwxr-xr-xezjail-admin165
1 files changed, 82 insertions, 83 deletions
diff --git a/ezjail-admin b/ezjail-admin
index 0b99d4b..1fc8494 100755
--- a/ezjail-admin
+++ b/ezjail-admin
@@ -15,9 +15,10 @@ ezjail_jaildir=${ezjail_jaildir:-"/usr/jails"}
15ezjail_jailtemplate=${ezjail_jailtemplate:-"${ezjail_jaildir}/newjail"} 15ezjail_jailtemplate=${ezjail_jailtemplate:-"${ezjail_jaildir}/newjail"}
16ezjail_jailbase=${ezjail_jailbase:-"${ezjail_jaildir}/basejail"} 16ezjail_jailbase=${ezjail_jailbase:-"${ezjail_jaildir}/basejail"}
17ezjail_jailfull=${ezjail_jailfull:-"${ezjail_jaildir}/fulljail"} 17ezjail_jailfull=${ezjail_jailfull:-"${ezjail_jaildir}/fulljail"}
18ezjail_jailtemp=${ezjail_jaildir:-"${ezjail_jaildir}/ezjailtemp"}
18ezjail_flavours=${ezjail_flavours:-"${ezjail_jaildir}/flavours"} 19ezjail_flavours=${ezjail_flavours:-"${ezjail_jaildir}/flavours"}
19ezjail_sourcetree=${ezjail_sourcetree:-"/usr/src"}
20ezjail_portscvsroot=${ezjail_portscvsroot:-":pserver:anoncvs@anoncvs.at.FreeBSD.org:/home/ncvs"} 20ezjail_portscvsroot=${ezjail_portscvsroot:-":pserver:anoncvs@anoncvs.at.FreeBSD.org:/home/ncvs"}
21ezjail_sourcetree=${ezjail_sourcetree:-"/usr/src"}
21ezjail_uglyperlhack=${ezjail_uglyperlhack:-"YES"} 22ezjail_uglyperlhack=${ezjail_uglyperlhack:-"YES"}
22 23
23ezjail_mount_enable=${ezjail_mount_enable:-"YES"} 24ezjail_mount_enable=${ezjail_mount_enable:-"YES"}
@@ -28,6 +29,10 @@ ezjail_fdescfs_enable=${ezjail_fdescfs_enable:-"YES"}
28 29
29ezjail_dirlist="bin boot lib libexec rescue sbin usr/bin usr/games usr/include usr/lib usr/libdata usr/libexec usr/sbin usr/src usr/share" 30ezjail_dirlist="bin boot lib libexec rescue sbin usr/bin usr/games usr/include usr/lib usr/libdata usr/libexec usr/sbin usr/src usr/share"
30 31
32################################
33# End of variable initialization
34#
35
31# define our bail out shortcut 36# define our bail out shortcut
32exerr () { echo -e "$*"; exit 1; } 37exerr () { echo -e "$*"; exit 1; }
33 38
@@ -66,6 +71,67 @@ fetchjailinfo () {
66 ezjail_id=`jls | grep " ${ezjail_hostname} " | head -n 1 | awk {'print $1'}` 71 ezjail_id=`jls | grep " ${ezjail_hostname} " | head -n 1 | awk {'print $1'}`
67} 72}
68 73
74# fill the base jail - this function is used by install and update
75ezjail_splitworld() {
76 # Fill basejail from installed world
77 cd ${ezjail_jailfull} || exerr "Cant access temporary Jail directory."
78
79 # This mkdir is important, since cpio will create intermediate
80 # directories with permission 0700 which is bad
81 mkdir -p ${ezjail_jailbase}/usr
82 for dir in ${ezjail_dirlist}; do
83 find ${dir} | cpio -d -p -v ${ezjail_jailbase} || exerr "Installation of ${dir} failed."
84 chflags -R noschg ${dir}; rm -r ${dir}; ln -s /basejail/${dir} ${dir}
85 done
86 mkdir basejail
87
88 # Try to remove the old template jail
89 [ -d ${ezjail_jailtemplate} ] && chflags -R noschg ${ezjail_jailtemplate} && rm -rf ${ezjail_jailtemplate}
90 mv ${ezjail_jailfull} ${ezjail_jailtemplate}
91
92 # If the default flavour example has not yet been copied, do it now
93 [ -d ${ezjail_flavours}/default ] || mkdir -p ${ezjail_flavours} && cp -p -R ${ezjail_examples}/default ${ezjail_flavours}
94
95 # A ports collection inside jails is hardly useful w/o an appropriate
96 # /etc/make.conf. If we find basejail/usr/ports/Makefile, assume that
97 # the admin wants a working make.conf in new jails also a softlink to
98 # the ports in basejail is provided
99 if [ -f ${ezjail_jailbase}/usr/ports/Makefile ]; then
100 # no /usr/ports? link to /basejail/usr/ports
101 [ -e ${ezjail_jailtemplate}/usr/ports ] || ln -s /basejail/usr/ports ${ezjail_jailtemplate}/usr/ports
102
103 if [ -f ${ezjail_examples}/default/etc/make.conf -a ! -f ${ezjail_jailtemplate}/etc/make.conf ]; then
104 cp -p ${ezjail_examples}/default/etc/make.conf ${ezjail_jailtemplate}/etc/
105 echo "Note: a non-standard /etc/make.conf was copied to the template jail in order to get the ports collection running inside jails."
106 fi
107 fi
108
109 # The ugly perl hack[tm]. Note: we wont do such things for any given
110 # port :(
111 [ "${ezjail_uglyperlhack}" = "YES" -a ! -L ${ezjail_jailbase}/usr/bin/perl ] && ln -s /usr/local/bin/perl ${ezjail_jailbase}/usr/bin/perl
112}
113
114# The user may want to have a ports tree in basejail
115ezjail_updateports () {
116 # if /usr/ports/CVS exists, assume cvs up is safe
117 # this is legacy
118 if [ -f ${ezjail_jailbase}/usr/ports/CVS/Root ]; then
119 echo -n "Updating ports from "; cat ${ezjail_jailbase}/usr/ports/CVS/Root
120 echo "Warning: Upgrading legacy ports copy. Consider removing ${ezjail_jailbase}/usr/ports and use the new portsnap strategy instead."
121 echo "Gathering local information may take a while."
122 cd ${ezjail_jailbase}/usr/ports/ && cvs -d ${ezjail_portscvsroot} up -Pd
123 else
124 portsnap fetch
125 [ -d ${ezjail_jailbase}/usr/ports ] && ezjail_portsnapaction=update
126 portsnap ${ezjail_portsnapaction:-"extract"}
127 fi
128 [ $? = 0 ] || exerr "Updating ports failed."
129}
130
131#############################
132# End of function definitions
133#
134
69# check for command 135# check for command
70[ "$1" ] || exerr "Usage: `basename -- $0` [config|create|delete|install|list|update] {params}" 136[ "$1" ] || exerr "Usage: `basename -- $0` [config|create|delete|install|list|update] {params}"
71 137
@@ -326,7 +392,6 @@ setup|update)
326 392
327 # Clean variables, prevent polution 393 # Clean variables, prevent polution
328 unset ezjail_provideports 394 unset ezjail_provideports
329
330 ezjail_installaction="world" 395 ezjail_installaction="world"
331 396
332 set -- ${args} 397 set -- ${args}
@@ -354,64 +419,15 @@ setup|update)
354 [ -d "${ezjail_jailfull}" ] && chflags -R noschg ${ezjail_jailfull} && rm -rf ${ezjail_jailfull} 419 [ -d "${ezjail_jailfull}" ] && chflags -R noschg ${ezjail_jailfull} && rm -rf ${ezjail_jailfull}
355 mkdir -p ${ezjail_jailfull} || exerr "Cannot create temporary Jail directory." 420 mkdir -p ${ezjail_jailfull} || exerr "Cannot create temporary Jail directory."
356 421
357 # make our world 422 # make and setup our world, then split basejail and newjail
358 cd ${ezjail_sourcetree} && make ${ezjail_installaction} DESTDIR=${ezjail_jailfull} || exerr "make ${ezjail_installaction} failed." 423 cd ${ezjail_sourcetree} && make ${ezjail_installaction} DESTDIR=${ezjail_jailfull} || exerr "make ${ezjail_installaction} failed."
359
360 # setup world
361 cd ${ezjail_sourcetree}/etc && make distribution DESTDIR=${ezjail_jailfull} || exerr "make distribution failed." 424 cd ${ezjail_sourcetree}/etc && make distribution DESTDIR=${ezjail_jailfull} || exerr "make distribution failed."
362 425 ezjail_splitworld
363 # Fill basejail from installed world
364 cd ${ezjail_jailfull} || exerr "Cant access temporary Jail directory."
365 # This mkdir is important, since cpio will create intermediate
366 # directories with permission 0700 which is bad
367 mkdir -p ${ezjail_jailbase}/usr
368 for dir in ${ezjail_dirlist}; do
369 find ${dir} | cpio -d -p -v ${ezjail_jailbase} || exerr "Installation of ${dir} failed."
370 chflags -R noschg ${dir}; rm -r ${dir}; ln -s /basejail/${dir} ${dir}
371 done
372 mkdir basejail
373
374 # Try to remove the old template jail
375 [ -d ${ezjail_jailtemplate} ] && chflags -R noschg ${ezjail_jailtemplate} && rm -rf ${ezjail_jailtemplate}
376 mv ${ezjail_jailfull} ${ezjail_jailtemplate}
377
378 # If the default flavour example has not yet been copied, do it now
379 [ -d ${ezjail_flavours}/default ] || mkdir -p ${ezjail_flavours} && cp -p -R ${ezjail_examples}/default ${ezjail_flavours}
380 426
381 fi # installaction="none" 427 fi # installaction="none"
382 428
383 # The user may want to have a ports tree in basejail 429 # Provide a copy of ports tree in basejail
384 if [ "${ezjail_provideports}" = "YES" ]; then 430 [ "${ezjail_provideports}" = "YES" ] && ezjail_updateports
385 # if /usr/ports/CVS exists, assume cvs up is safe
386 if [ -f ${ezjail_jailbase}/usr/ports/CVS/Root ]; then
387 echo -n "Updating ports from "; cat ${ezjail_jailbase}/usr/ports/CVS/Root
388 echo "Gathering local information may take a while."
389 cd ${ezjail_jailbase}/usr/ports/ && cvs -d ${ezjail_portscvsroot} up -Pd
390 else
391 echo "Checking out ports from ${ezjail_portscvsroot}"
392 mkdir -p ${ezjail_jailbase}/usr/ports/
393 cd ${ezjail_jailbase}/usr/ && cvs -d ${ezjail_portscvsroot} co ports
394 fi
395 [ $? = 0 ] || exerr "Updating ports failed."
396 fi
397
398 # A ports collection inside jails is hardly useful w/o an appropriate
399 # /etc/make.conf. If we find basejail/usr/ports/Makefile, assume that
400 # the admin wants a working make.conf in new jails also a softlink to
401 # the ports in basejail is provided
402 if [ -f ${ezjail_jailbase}/usr/ports/Makefile ]; then
403 # no /usr/ports? link to /basejail/usr/ports
404 [ -e ${ezjail_jailtemplate}/usr/ports ] || ln -s /basejail/usr/ports ${ezjail_jailtemplate}/usr/ports
405
406 if [ -f ${ezjail_examples}/default/etc/make.conf -a ! -f ${ezjail_jailtemplate}/etc/make.conf ]; then
407 cp -p ${ezjail_examples}/default/etc/make.conf ${ezjail_jailtemplate}/etc/
408 echo "Note: a non-standard /etc/make.conf was copied to the template jail in order to get the ports collection running inside jails."
409 fi
410 fi
411
412 # The ugly perl hack[tm]. Note: we wont do such things for any given
413 # port :(
414 [ "${ezjail_uglyperlhack}" = "YES" -a ! -L ${ezjail_jailbase}/usr/bin/perl ] && ln -s /usr/local/bin/perl ${ezjail_jailbase}/usr/bin/perl
415 431
416 ;; 432 ;;
417######################## ezjail-admin INSTALL ######################## 433######################## ezjail-admin INSTALL ########################
@@ -420,14 +436,14 @@ install)
420 args=`getopt mpsh:r: $*` || exerr "Usage: `basename -- $0` install [-mps] [-h host] [-r release]" 436 args=`getopt mpsh:r: $*` || exerr "Usage: `basename -- $0` install [-mps] [-h host] [-r release]"
421 437
422 # Clean variables, prevent polution 438 # Clean variables, prevent polution
423 unset ezjail_release ezjail_ftphost ezjail_installmanpages ezjail_installports ezjail_installsources ezjail_dir ezjail_reldir ezjail_temp 439 unset ezjail_release ezjail_ftphost ezjail_installmanpages ezjail_installports ezjail_installsources ezjail_dir ezjail_reldir
424 440
425 set -- ${args} 441 set -- ${args}
426 for arg do 442 for arg do
427 case ${arg} in 443 case ${arg} in
428 -m) ezjail_installmanpages=" manpages"; shift;; 444 -m) ezjail_installmanpages=" manpages"; shift;;
429 -p) ezjail_installports=" ports"; shift;;
430 -s) ezjail_installsources=" src"; shift;; 445 -s) ezjail_installsources=" src"; shift;;
446 -p) ezjail_installports="YES"; shift;;
431 -h) ezjail_ftphost="$2"; shift 2;; 447 -h) ezjail_ftphost="$2"; shift 2;;
432 -r) ezjail_release="$2"; shift 2;; 448 -r) ezjail_release="$2"; shift 2;;
433 --) shift; break;; 449 --) shift; break;;
@@ -439,8 +455,6 @@ install)
439 ezjail_ftphost=${ezjail_ftphost#ftp://} 455 ezjail_ftphost=${ezjail_ftphost#ftp://}
440 ezjail_dir=${ezjail_ftphost#file://} 456 ezjail_dir=${ezjail_ftphost#file://}
441 [ "${ezjail_dir%%[!/]*}" ] || ezjail_reldir=${PWD} 457 [ "${ezjail_dir%%[!/]*}" ] || ezjail_reldir=${PWD}
442 # XXX
443 ezjail_temp=${ezjail_jaildir}/ezjailtemp
444 458
445 # ftp servers normally wont provide CURRENT-builds 459 # ftp servers normally wont provide CURRENT-builds
446 if [ -z "${ezjail_release}" ]; then 460 if [ -z "${ezjail_release}" ]; then
@@ -459,15 +473,14 @@ install)
459 mkdir -p ${ezjail_jailfull} || exerr "Cannot create temporary Jail directory." 473 mkdir -p ${ezjail_jailfull} || exerr "Cannot create temporary Jail directory."
460 DESTDIR=${ezjail_jailfull} 474 DESTDIR=${ezjail_jailfull}
461 475
462 # XXX 476 rm -rf ${ezjail_jailtemp}
463 rm -rf ${ezjail_temp} 477 for pkg in base ${ezjail_installmanpages} ${ezjail_installsources}; do
464 for pkg in base ${ezjail_installmanpages} ${ezjail_installports} ${ezjail_installsources}; do
465 478
466 # The first case means, that a remote host has been specified. 479 # The first case means, that a remote host has been specified.
467 if [ "${ezjail_dir}" = "${ezjail_ftphost}" ]; then 480 if [ "${ezjail_dir}" = "${ezjail_ftphost}" ]; then
468 # Create and try to access temp dir 481 # Create and try to access temp dir
469 mkdir -p ${ezjail_temp} || exerr "Could not create temporary base jail directory ${ezjail_temp}." 482 mkdir -p ${ezjail_jailtemp} || exerr "Could not create temporary base jail directory ${ezjail_jailtemp}."
470 cd ${ezjail_temp} || exerr "Could not cd to ${ezjail_temp}." 483 cd ${ezjail_jailtemp} || exerr "Could not cd to ${ezjail_jailtemp}."
471 484
472 # Try all paths as stolen from sysinstall, break on success. 485 # Try all paths as stolen from sysinstall, break on success.
473 for ezjail_path in pub/FreeBSD/releases pub/FreeBSD/snapshot pub/FreeBSD releases snapshots NO; do 486 for ezjail_path in pub/FreeBSD/releases pub/FreeBSD/snapshot pub/FreeBSD releases snapshots NO; do
@@ -482,7 +495,7 @@ install)
482 [ -f install.sh ] && yes | . install.sh 495 [ -f install.sh ] && yes | . install.sh
483 # XXX error checking. 496 # XXX error checking.
484 497
485 rm -rf ${ezjail_temp} 498 rm -rf ${ezjail_jailtemp}
486 else 499 else
487 cd ${basejail_reldir}/${basejail_dir}/${pkg} || exerr "Could not cd to ${basejail_dir}." 500 cd ${basejail_reldir}/${basejail_dir}/${pkg} || exerr "Could not cd to ${basejail_dir}."
488 set -- all 501 set -- all
@@ -490,25 +503,11 @@ install)
490 fi 503 fi
491 done 504 done
492 505
493 # Fill basejail from installed world 506 # Split basejail and newjail
494 cd ${ezjail_jailfull} || exerr "Cant access temporary Jail directory." 507 ezjail_splitworld
495 # This mkdir is important, since cpio will create intermediate
496 # directories with permission 0700 which is bad
497 mkdir -p ${ezjail_jailbase}/usr
498 for dir in ${ezjail_dirlist}; do
499 find ${dir} | cpio -d -p -v ${ezjail_jailbase} || exerr "Installation of ${dir} failed."
500 chflags -R noschg ${dir}; rm -r ${dir}; ln -s /basejail/${dir} ${dir}
501 done
502 mkdir basejail
503
504 # Try to remove the old template jail
505 [ -d ${ezjail_jailtemplate} ] && chflags -R noschg ${ezjail_jailtemplate} && rm -rf ${ezjail_jailtemplate}
506 mv ${ezjail_jailfull} ${ezjail_jailtemplate}
507
508 # If the default flavour example has not yet been copied, do it now
509 [ -d ${ezjail_flavours}/default ] || mkdir -p ${ezjail_flavours} && cp -p -R ${ezjail_examples}/default ${ezjail_flavours}
510 508
511 # XXX ports stuff still missing 509 # Fill ports, if requested
510 [ "${ezjail_installports} = "YES" ] && ezjail_updateports
512 511
513 ;; 512 ;;
514######################## ezjail-admin CONFIG ######################## 513######################## ezjail-admin CONFIG ########################