summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xezjail-release.sh120
1 files changed, 120 insertions, 0 deletions
diff --git a/ezjail-release.sh b/ezjail-release.sh
new file mode 100755
index 0000000..5344a06
--- /dev/null
+++ b/ezjail-release.sh
@@ -0,0 +1,120 @@
1#!/bin/sh
2
3# ugly: this variable is set during port install time
4ezjail_prefix=/usr/local
5ezjail_etc=${ezjail_prefix}/etc
6ezjail_share=${ezjail_prefix}/share/ezjail
7ezjail_examples=${ezjail_prefix}/share/examples/ezjail
8ezjail_jailcfgs=${ezjail_etc}/ezjail
9
10# read user config
11[ -f ${ezjail_etc}/ezjail.conf ] && . ${ezjail_etc}/ezjail.conf
12
13# set defaults
14ezjail_jaildir=${ezjail_jaildir:-"/usr/jails"}
15ezjail_jailtemplate=${ezjail_jailtemplate:-"${ezjail_jaildir}/newjail"}
16ezjail_jailbase=${ezjail_jailbase:-"${ezjail_jaildir}/basejail"}
17ezjail_jailfull=${ezjail_jailfull:-"${ezjail_jaildir}/fulljail"}
18ezjail_flavours=${ezjail_flavours:-"${ezjail_jaildir}/flavours"}
19ezjail_sourcetree=${ezjail_sourcetree:-"/usr/src"}
20ezjail_portscvsroot=${ezjail_portscvsroot:-":pserver:anoncvs@anoncvs.at.FreeBSD.org:/home/ncvs"}
21
22# define our bail out shortcut
23exerr () { echo -e "$*"; exit 1; }
24
25# check for command
26[ "$1" ] || exerr "Usage: `basename -- $0` [create|delete|list|release|update] {params}"
27
28case "$1" in
29######################## ezjail-admin RELEASE ########################
30release)
31 shift
32 args=`getopt mpr:s: $*` || exerr "Usage: `basename -- $0` release [-m] [-p] [-r release] [-s server]"
33
34 basejail_release=
35 basejail_server=
36 basejail_manpages=
37 basejail_ports=
38 basejail_reldir=
39
40 set -- ${args}
41 for arg do
42 case ${arg} in
43 -m) basejail_manpages=" manpages"; shift;;
44 -m) basejail_ports=" ports"; shift;;
45 -r) basejail_release="$2"; shift 2;;
46 -s) basejail_server="$2"; shift 2;;
47 --) shift; break;;
48 esac
49 done
50
51 basejail_arch=`uname -p`
52 basejail_server=${basejail_server:-"ftp.freebsd.org:"}
53 basejail_server=${basejail_server#ftp://}
54 basejail_dir=${basejail_server#file://}
55 [ "${basejail_dir%%[!/]*}" ] || ${basejail_reldir}=${PWD}
56 basejail_tmp=${ezjail_jaildir}/tmp
57 basejail_fill="base ${basejail_manpages} ${basejail_ports}"
58
59 # ftp servers normally wont provide CURRENT-builds
60 if [ -z "{$basejail_release}" ]; then
61 ${basejail_release}=`uname -r`
62 if [ "${basejail_release%CURRENT}" != "${basejail_release}" -a "${basejail_dir}" != "${basejail_server}" ]; then
63 echo "Your system is ${basejail_release}. Normally FTP-servers don't provide CURRENT-builds."
64 echo -n "Release [ ${basejail_release} ]: "
65 read release_tmp
66 [ "$release_tmp" ] && basejail_release=${release_tmp}
67 fi
68 fi
69
70 # Normally fulljail should be renamed by past ezjail-admin commands.
71 # However those may have failed
72 [ -d ${ezjail_jailfull} ] && chflags -R noschg ${ezjail_jailfull}
73 rm -rf ${ezjail_jailfull}
74 mkdir -p ${ezjail_jailfull} || exerr "Could not create temporary base jail directory ${ezjail_jailfull}."
75 DESTDIR=${ezjail_jailfull}
76
77 rm -rf ${basejail_tmp}
78 for pkg in ${basejail_fill}; do
79 if [ "${basejail_dir}" = "${basejail_server}" ]; then
80 mkdir -p ${basejail_tmp} || exerr "Could not create temporary base jail directory ${basejail_tmp}."
81 cd ${basejail_tmp}
82 for basejail_path in /pub/FreeBSD/releases /pub/FreeBSD/snapshot /FreeBSD NO; do
83 [ "${basejail_path}" = "NO" ] && exerr "Could not fetch ${pkg} from ${basejail_server}."
84 ftp "${basejail_server}${basejail_path}/${basejail_arch}/${basejail_release}/${pkg}/*" > /dev/null && break
85 done
86 [ -f install.sh ] && yes | . install.sh
87 rm -rf ${basejail_tmp}
88 else
89 cd ${basejail_reldir}/${basejail_dir}/${pkg} || exerr "Could not change to ${basejail_dir}."
90 [ -f install.sh ] && yes | . install.sh
91 fi
92 done
93
94 # Fill basejail from installed world
95 cd ${ezjail_jailfull}
96 # This mkdir is important, since cpio will create intermediate
97 # directories with permission 0700 which is bad
98 mkdir -p ${ezjail_jailbase}/usr
99 for dir in bin boot lib libexec rescue sbin usr/bin usr/include usr/lib usr/libexec usr/sbin usr/src usr/share; do
100 find ${dir} | cpio -d -p -v ${ezjail_jailbase} || exerr "Installation of ${dir} failed."
101 chflags -R noschg ${dir}; rm -r ${dir}; ln -s /basejail/${dir} ${dir}
102 done
103 mkdir basejail
104
105 # Try to remove the old template jail
106 if [ -d ${ezjail_jailtemplate} ]; then
107 if [ -d ${ezjail_jailtemplate}_old ]; then
108 chflags -R noschg ${ezjail_jailtemplate}_old
109 rm -rf ${ezjail_jailtemplate}_old
110 fi
111 mv ${ezjail_jailtemplate} ${ezjail_jailtemplate}_old
112 fi
113 mv ${ezjail_jailfull} ${ezjail_jailtemplate}
114
115 ;;
116*)
117 exerr "Usage: `basename -- $0` [create|delete|list|update] {params}"
118 ;;
119esac
120