mkjail.sh

Check-in [87a9ece2e6]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Reliability improvements Automatic release fetching if it's not already seeded
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | combined
Files: files | file ages | folders
SHA3-256:87a9ece2e6993c07e6de03e3e89121cb09ecedf6e3af6cbed8bfd77547113196
User & Date: feld 2018-10-02 21:11:52
Context
2018-10-02
21:24
Merge properly (I think) check-in: 2439df6e88 user: feld tags: master, trunk
21:11
Reliability improvements Automatic release fetching if it's not already seeded Leaf check-in: 87a9ece2e6 user: feld tags: combined
20:46
Standardize variables Introduce config file Architecture is now possible to override via an option flag check-in: cc5b2533c3 user: feld tags: combined
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/bin/mkjail.

20
21
22
23
24
25
26



27
28
29
30
31
32
33
..
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
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.




export PATH=/bin:/sbin:/usr/bin:/usr/sbin

if [ $(id -u) -ne 0 ]; then
    echo "Error: must run as root or with sudo."
    exit 1
fi
................................................................................

CMD=$1

MKJAILPATH=`realpath $0`
if [ "${MKJAILPATH%src/bin/mkjail}" != "${MKJAILPATH}" ]; then
        # It is running from src/bin/mkjail in checkout
        MKJAILPREFIX=${MKJAILPATH%/bin/*}
        LIBEXECPREFIX="${MKJAILPATH%/src/bin/mkjail}"
        set -a
        . ${MKJAILPREFIX}/etc/mkjail.conf
        set +a
elif [ "${MKJAILPATH%/bin/*}" = "${MKJAILPATH}" ]; then
        # It is running in a build directory or the source checkout as
        # ./mkjail.  Lookup VPATH to resolve to source checkout if in
        # build directory.
        [ -f Makefile ] && VPATH="$(make -V VPATH)"
        MKJAILPREFIX="${MKJAILPATH%/mkjail}${VPATH:+/${VPATH}}/src"
        [ -n "${VPATH}" ] && MKJAILPREFIX="$(realpath "${MKJAILPREFIX}")"
        LIBEXECPREFIX="${MKJAILPATH%/mkjail}"
        set -a
        . ${MKJAILPREFIX}/etc/mkjail.conf
        set +a
else
        # Running from PREFIX/bin/mkjail
        MKJAILPREFIX=${MKJAILPATH%/bin/*}
        LIBEXECPREFIX="${MKJAILPREFIX}/libexec/mkjail"
        set -a
        . ${MKJAILPREFIX}/etc/mkjail.conf
        set +a
fi

SCRIPTPREFIX=${MKJAILPREFIX}/share/mkjail
SCRIPTPATH="${SCRIPTPREFIX}/${CMD}.sh"

case "${CMD}" in
create|update|upgrade)
    ;;
*)
    echo "Unknown command '${CMD}'"







>
>
>







 







<










<






<





|







20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
..
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
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

set -e
set -u

export PATH=/bin:/sbin:/usr/bin:/usr/sbin

if [ $(id -u) -ne 0 ]; then
    echo "Error: must run as root or with sudo."
    exit 1
fi
................................................................................

CMD=$1

MKJAILPATH=`realpath $0`
if [ "${MKJAILPATH%src/bin/mkjail}" != "${MKJAILPATH}" ]; then
        # It is running from src/bin/mkjail in checkout
        MKJAILPREFIX=${MKJAILPATH%/bin/*}

        set -a
        . ${MKJAILPREFIX}/etc/mkjail.conf
        set +a
elif [ "${MKJAILPATH%/bin/*}" = "${MKJAILPATH}" ]; then
        # It is running in a build directory or the source checkout as
        # ./mkjail.  Lookup VPATH to resolve to source checkout if in
        # build directory.
        [ -f Makefile ] && VPATH="$(make -V VPATH)"
        MKJAILPREFIX="${MKJAILPATH%/mkjail}${VPATH:+/${VPATH}}/src"
        [ -n "${VPATH}" ] && MKJAILPREFIX="$(realpath "${MKJAILPREFIX}")"

        set -a
        . ${MKJAILPREFIX}/etc/mkjail.conf
        set +a
else
        # Running from PREFIX/bin/mkjail
        MKJAILPREFIX=${MKJAILPATH%/bin/*}

        set -a
        . ${MKJAILPREFIX}/etc/mkjail.conf
        set +a
fi

export SCRIPTPREFIX=${MKJAILPREFIX}/share/mkjail
SCRIPTPATH="${SCRIPTPREFIX}/${CMD}.sh"

case "${CMD}" in
create|update|upgrade)
    ;;
*)
    echo "Unknown command '${CMD}'"

Changes to src/share/mkjail/create.sh.

1


2
3
4
5
6
7
8
..
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/sh



: ${ARCH=$(uname -m)}

ip4int=$(route -4 get default | awk '/interface: / {print $2}')
ip6int=$(route -6 get default | awk '/interface: / {print $2}')
ip4guess=$(ifconfig ${ip4int} | awk '/inet / && !/127.0/ {print $2}' | head -n 1)
ip6guess=$(ifconfig ${ip6int} | awk '/inet6 / && !/(fe80| ::1)/ {print $2}' | head -n 1)
................................................................................
then
    exit_opts_req
fi

_build() {
# Make sure the release exists
if [ ! -d /var/db/mkjail/releases/${ARCH}/${VERSION} ]; then
    echo "Release ${VERSION} does not exist. Exiting."
    exit 1
fi

# Make sure target flavor exists
if [ x"${fflag}" = x1 ] && [ ! -d /var/db/mkjail/flavours/${FLAVOUR} ]; then
    echo "Error: flavour ${FLAVOUR} does not exist. Please create it first."
    exit 1
fi

>
>







 







|
|







1
2
3
4
5
6
7
8
9
10
..
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/sh
set -e
set -u

: ${ARCH=$(uname -m)}

ip4int=$(route -4 get default | awk '/interface: / {print $2}')
ip6int=$(route -6 get default | awk '/interface: / {print $2}')
ip4guess=$(ifconfig ${ip4int} | awk '/inet / && !/127.0/ {print $2}' | head -n 1)
ip6guess=$(ifconfig ${ip6int} | awk '/inet6 / && !/(fe80| ::1)/ {print $2}' | head -n 1)
................................................................................
then
    exit_opts_req
fi

_build() {
# Make sure the release exists
if [ ! -d /var/db/mkjail/releases/${ARCH}/${VERSION} ]; then
    echo "Release ${VERSION} does not exist. Attempting to fetch..."
    ${SCRIPTPREFIX}/getrelease.sh ${VERSION}
fi

# Make sure target flavor exists
if [ x"${fflag}" = x1 ] && [ ! -d /var/db/mkjail/flavours/${FLAVOUR} ]; then
    echo "Error: flavour ${FLAVOUR} does not exist. Please create it first."
    exit 1
fi

Changes to src/share/mkjail/getrelease.sh.

1


2
3
4
5
6


7
8

9
10




11

12
13
14
15
16
17
18
#!/bin/sh



if [ $(id -u) -ne 0 ]; then
    echo "Error: must run as root or with sudo."
    exit 1
fi



: ${ARCH=$(uname -m)}


dists="base.txz doc.txz lib32.txz"






mkdir -p /var/db/mkjail/releases/${ARCH}/${1}
cd /var/db/mkjail/releases/${ARCH}/${1}

for i in $dists; do 
   fetch https://download.freebsd.org/ftp/releases/${ARCH}/${1}/${i}
done


>
>

<
<
|
<
>
>

<
>
|
<
>
>
>
>
|
>
|
|

|
|

<
1
2
3
4


5

6
7
8

9
10

11
12
13
14
15
16
17
18
19
20
21
22

#!/bin/sh
set -u
trap _cleanup HUP INT QUIT KILL TERM ABRT



: ${ARCH=$(uname -m)}

RELEASE=${1}
: ${SETS="base doc lib32"}


_cleanup()
{

    echo ""
    echo "Error: could not fetch dists. Cleaning up."
    rm -rf /var/db/mkjail/releases/${ARCH}/${RELEASE}
    exit 1
}

mkdir -p /var/db/mkjail/releases/${ARCH}/${RELEASE}
cd /var/db/mkjail/releases/${ARCH}/${RELEASE}

for i in ${SETS}; do 
   fetch https://download.freebsd.org/ftp/releases/${ARCH}/${RELEASE}/${i}.txz || _cleanup
done

Changes to src/share/mkjail/update.sh.

1


2
3
4
5
6
7
8
#!/bin/sh



PAGER=cat

_alljails()
{
    echo "Updating all jails..."
    echo ""

>
>







1
2
3
4
5
6
7
8
9
10
#!/bin/sh
set -e
set -u

PAGER=cat

_alljails()
{
    echo "Updating all jails..."
    echo ""

Changes to src/share/mkjail/upgrade.sh.

1
2

3
4
5
6
7
8
9
#!/bin/sh
set -e

trap _cleanup HUP INT QUIT KILL TERM ABRT

aflag=0
jflag=0
PAGER=cat
SNAPNAME="mkjail-$(date '+%Y%m%d%H%M')"



>







1
2
3
4
5
6
7
8
9
10
#!/bin/sh
set -e
set -u
trap _cleanup HUP INT QUIT KILL TERM ABRT

aflag=0
jflag=0
PAGER=cat
SNAPNAME="mkjail-$(date '+%Y%m%d%H%M')"