source: src-sh/warden/linux-installs/gentoo-stage3-i486 @ 84e6670

releng/10.0
Last change on this file since 84e6670 was 84e6670, checked in by Kris Moore <kris@…>, 8 months ago

Fix bugs creating linux jails debian and gentoo via the Warden

This was a result of a merge with some FreeNAS changes which didn't apply to
our version of Warden

  • Property mode set to 100755
File size: 6.0 KB
Line 
1#!/bin/sh
2# Script to install gentoo i386 release into a jail
3# Author: Kris Moore <kris@pcbsd.org>
4
5JDIR="$1"
6SELF="gentoo-stage3-i486"
7SELFDIR="${JDIR}/.${SELF}"
8INDEXFILE="latest-stage3-i486.txt"
9ERRORFILE="/tmp/.${SELF}.error"
10
11get_gentoo_mirrors()
12{
13    local SUBDIR="releases/x86/autobuilds"
14
15    cat<<__EOF__
16    http://ftp.roedu.net/pub/mirrors/gentoo.org/$SUBDIR/
17    http://distro.ibiblio.org/pub/linux/distributions/gentoo/$SUBDIR/
18    http://gentoo.mirrors.pair.com/$SUBDIR/
19    http://gentoo.chem.wisc.edu/gentoo/$SUBDIR/
20    http://adelie.polymtl.ca/$SUBDIR/
21    http://mirrors.tds.net/gentoo/$SUBDIR/
22    ftp://ftp.mirrorservice.org/sites/www.ibiblio.org/gentoo/$SUBDIR/
23    http://ftp.belnet.be/mirror/rsync.gentoo.org/gentoo/$SUBDIR/
24    http://ftp.easynet.nl/mirror/gentoo/$SUBDIR/
25    http://ftp.snt.utwente.nl/pub/os/linux/gentoo/$SUBDIR/
26    http://trumpetti.atm.tut.fi/gentoo/$SUBDIR/
27    http://sunsite.cnlab-switch.ch/ftp/mirror/gentoo/$SUBDIR/
28    http://linux.rz.ruhr-uni-bochum.de/download/gentoo-mirror/$SUBDIR/
29    http://ftp.uni-erlangen.de/pub/mirrors/gentoo/$SUBDIR/
30    http://darkstar.ist.utl.pt/gentoo/$SUBDIR/
31    http://gentoo.inode.at/$SUBDIR/
32    http://ftp.rhnet.is/pub/gentoo/$SUBDIR/
33    http://gentoo.mirror.sdv.fr/$SUBDIR/
34    http://gentoo.gg3.net/$SUBDIR/
35    http://gentoo.kems.net/$SUBDIR/
36    ftp://ftp.gtlib.gatech.edu/pub/gentoo/$SUBDIR/
37    ftp://mirror.iawnet.sandia.gov/pub/gentoo/$SUBDIR/
38    ftp://ftp.ussg.iu.edu/pub/linux/gentoo/$SUBDIR/
39    ftp://ftp.ucsb.edu/pub/mirrors/linux/gentoo/$SUBDIR/
40    ftp://gentoo.mirrors.pair.com/$SUBDIR/
41    ftp://mirrors.tds.net/gentoo/$SUBDIR/
42    ftp://ftp.belnet.be/mirror/rsync.gentoo.org/gentoo/$SUBDIR/
43    ftp://ftp.easynet.nl/mirror/gentoo/$SUBDIR/
44    ftp://ftp.snt.utwente.nl/pub/os/linux/gentoo/$SUBDIR/
45    ftp://trumpetti.atm.tut.fi/gentoo/$SUBDIR/
46    ftp://sunsite.cnlab-switch.ch/mirror/gentoo/$SUBDIR/
47    ftp://ftp.join.uni-muenster.de/pub/linux/distributions/gentoo/$SUBDIR/
48    ftp://ftp6.uni-muenster.de/pub/linux/distributions/gentoo/$SUBDIR/
49    ftp://ftp.tu-clausthal.de/pub/linux/gentoo/$SUBDIR/
50    ftp://sunsite.informatik.rwth-aachen.de/pub/Linux/gentoo/$SUBDIR/
51    ftp://linux.rz.ruhr-uni-bochum.de/gentoo-mirror/$SUBDIR/
52    ftp://ftp.uni-erlangen.de/pub/mirrors/gentoo/$SUBDIR/
53    ftp://darkstar.ist.utl.pt/pub/gentoo/$SUBDIR/
54    ftp://gentoo.inode.at/source/$SUBDIR/
55    ftp://ftp.rhnet.is/pub/gentoo/$SUBDIR/
56    ftp://files.gentoo.gr/$SUBDIR/
57    ftp://ftp.ecc.u-tokyo.ac.jp/GENTOO/$SUBDIR/
58    ftp://gentoo.kems.net/pub/mirrors/gentoo/$SUBDIR/
59__EOF__
60}
61
62get_gentoo_mirror_list()
63{
64   local file="${1}"
65   local gentoo_mirrors="$(get_gentoo_mirrors)"
66
67   local mirrors=
68   for m in ${gentoo_mirrors}
69   do
70       mirrors="${mirrors} ${m}/${1}"
71   done
72
73   echo "${mirrors}"
74}
75
76get_linux_file()
77{
78   local _rf="${1}"
79   local _lf="${2}"
80
81   local aDir="$(dirname $_lf)"
82   local aFile="$(basename $_lf)"
83
84   local astatfile="${HOME}/.${SELF}-aria-stat-i386"
85   if [ -e "${astatfile}" ] ; then
86     local astat="--server-stat-of=${astatfile}
87        --server-stat-if=${astatfile}
88        --uri-selector=adaptive
89        --server-stat-timeout=864000"
90   else
91     local astat=" --server-stat-of=${astatfile} --uri-selector=adaptive "
92   fi
93   touch $astatfile
94
95   local mirrors="$(get_gentoo_mirror_list ${1})"
96
97   aria2c -k 5M \
98      ${astat} \
99      --check-certificate=false \
100      --file-allocation=none \
101      -d ${aDir} \
102      -o ${aFile} \
103      ${mirrors}
104
105   return $?
106}
107
108get_dlfile_name()
109{
110    local archivefile="`cat ${SELFDIR}/${INDEXFILE} | grep 'stage3'`"
111    local dlfile="`basename ${archivefile}`"
112
113    echo "${dlfile}"
114}
115
116get_distfiles()
117{
118    rm -f "${ERRORFILE}"
119
120    if [ ! -d "${SELFDIR}" ] ; then
121      mkdir -p "${SELFDIR}"
122    fi
123
124    if [ ! -f "${SELFDIR}/${INDEXFILE}" ] ; then
125      echo "Trying to fetch index: ${INDEXFILE}"
126      get_linux_file "${INDEXFILE}" "${SELFDIR}/${INDEXFILE}"
127    fi
128
129    local archivefile="`cat ${SELFDIR}/${INDEXFILE} | grep 'stage3'`"
130    local dlfile="`basename ${archivefile}`"
131
132    if [ -z "${archivefile}" ] ; then
133      echo "Failed to locate current archive"
134      touch "${ERRORFILE}"     
135      exit 1
136    fi
137
138    if [ ! -f "${SELFDIR}/${dlfile}" ] ; then
139      echo "Fetching archive: ${archivefile}"
140      get_linux_file "${archivefile}" "${SELFDIR}/${dlfile}"
141    fi
142
143    if [ ! -e "${SELFDIR}/${dlfile}" ] ; then
144      echo "Failed to download.."
145      touch "${ERRORFILE}"     
146      exit 1
147    fi
148}
149
150template_install()
151{
152    rm -f "${ERRORFILE}"
153
154    local TDIR="${1}"
155    if [ -z "${TDIR}" ] ; then
156      echo "TDIR is not defined"
157      exit 1
158    fi
159
160    get_distfiles "$@"
161
162    local dlfile="$(get_dlfile_name)"
163    if [ -z "${dlfile}" ] ; then
164      touch "${ERRORFILE}"     
165      exit 1
166    fi
167
168    echo "Extracting Gentoo base...Please wait..."
169    tar --exclude=./dev -xpy --exclude=./proc --exclude=./lib/udev \
170        --exclude=./lib/udev-state -C ${TDIR} -f "${SELFDIR}/${dlfile}"
171    err=$?
172
173    mkdir ${TDIR}/dev >/dev/null 2>/dev/null
174    mkdir ${TDIR}/dev/fd >/dev/null 2>/dev/null
175    mkdir ${TDIR}/proc >/dev/null 2>/dev/null
176    mkdir ${TDIR}/sys >/dev/null 2>/dev/null
177
178    umount -f ${TDIR}/dev/fd >/dev/null 2>/dev/null
179    umount -f ${TDIR}/dev >/dev/null 2>/dev/null
180    umount -f ${TDIR}/sys >/dev/null 2>/dev/null
181    umount -f ${TDIR}/proc >/dev/null 2>/dev/null
182
183    # Get rid of umount
184    mv ${TDIR}/bin/umount ${TDIR}/bin/umount.prev
185    ln -s /bin/true ${TDIR}/bin/umount
186
187    return $err
188}
189
190jail_configure()
191{
192    rm -f "${ERRORFILE}"
193
194    local JMETADIR="${1}"
195    if [ -z "${JMETADIR}" ] ; then
196      echo "JMETADIR is not defined"
197      touch "${ERRORFILE}"     
198      exit 1
199    fi
200
201    # Setup some custom start / stop stuff
202    echo "/sbin/rc default" > ${JMETADIR}/jail-start
203    echo "/sbin/rc shutdown" > ${JMETADIR}/jail-stop
204}
205
206error()
207{
208    if [ -f "${ERRORFILE}" ] ; then
209        rm "${ERRORFILE}"
210        return 1
211    fi
212
213    return 0
214}
215
216main()
217{
218    get_distfiles
219    template_install "$1"
220    jail_configure "$3"
221}
222
223# Arg1 = Directory # Arg2 = IP # Arg3 = Meta dir
224main "$@"
Note: See TracBrowser for help on using the repository browser.