c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat#!/bin/bash
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat#
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfield# template script for generating OpenSUSE container for LXC
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat#
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat#
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat# lxc: linux Container library
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat# Authors:
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat# Daniel Lezcano <daniel.lezcano@free.fr>
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat# Frederic Crozat <fcrozat@suse.com>
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfield# Michael H. Warfield <mhw@WittsEnd.com>
0ce7569856cc7a366f58688f6b6a71610167fc76Johannes Kastl# Johannes Kastl <mail@ojkastl.de>
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat# This library is free software; you can redistribute it and/or
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat# modify it under the terms of the GNU Lesser General Public
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat# License as published by the Free Software Foundation; either
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat# version 2.1 of the License, or (at your option) any later version.
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat# This library is distributed in the hope that it will be useful,
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat# but WITHOUT ANY WARRANTY; without even the implied warranty of
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat# Lesser General Public License for more details.
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat# You should have received a copy of the GNU Lesser General Public
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat# License along with this library; if not, write to the Free Software
250b1eec71b074acdff1c5f6b5a1f0d7d2c20b77Stéphane Graber# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat
8ec981fc8b0105da5f071e40811e0c2472a6c3c9Stéphane Graber# Detect use under userns (unsupported)
c63c04fcaf1c3a78c70500eae253d72fa9c8358aTAMUKI Shoichifor arg in "$@"; do
96283b546081e7ff709968378fca25cb44f1ab6cStéphane Graber [ "$arg" = "--" ] && break
96283b546081e7ff709968378fca25cb44f1ab6cStéphane Graber if [ "$arg" = "--mapped-uid" -o "$arg" = "--mapped-gid" ]; then
8ec981fc8b0105da5f071e40811e0c2472a6c3c9Stéphane Graber echo "This template can't be used for unprivileged containers." 1>&2
8ec981fc8b0105da5f071e40811e0c2472a6c3c9Stéphane Graber echo "You may want to try the \"download\" template instead." 1>&2
8ec981fc8b0105da5f071e40811e0c2472a6c3c9Stéphane Graber exit 1
8ec981fc8b0105da5f071e40811e0c2472a6c3c9Stéphane Graber fi
8ec981fc8b0105da5f071e40811e0c2472a6c3c9Stéphane Graberdone
8ec981fc8b0105da5f071e40811e0c2472a6c3c9Stéphane Graber
207bf0e475f1dc6e9a2dac2cee3a209b56427855Stéphane Graber# Make sure the usual locations are in PATH
207bf0e475f1dc6e9a2dac2cee3a209b56427855Stéphane Graberexport PATH=$PATH:/usr/sbin:/usr/bin:/sbin:/bin
207bf0e475f1dc6e9a2dac2cee3a209b56427855Stéphane Graber
a3ed64707fb71b6f2fcf603e755c5da07ab3aec5Evgeni Golovif [ -x /usr/bin/obs-build ]; then
a3ed64707fb71b6f2fcf603e755c5da07ab3aec5Evgeni Golov BUILD=/usr/bin/obs-build
a3ed64707fb71b6f2fcf603e755c5da07ab3aec5Evgeni Golov export BUILD_DIR=/usr/lib/obs-build
a3ed64707fb71b6f2fcf603e755c5da07ab3aec5Evgeni Golovelse
a3ed64707fb71b6f2fcf603e755c5da07ab3aec5Evgeni Golov BUILD=/usr/bin/build
a3ed64707fb71b6f2fcf603e755c5da07ab3aec5Evgeni Golov export BUILD_DIR=/usr/lib/build
a3ed64707fb71b6f2fcf603e755c5da07ab3aec5Evgeni Golovfi
a3ed64707fb71b6f2fcf603e755c5da07ab3aec5Evgeni Golov
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatconfigure_opensuse()
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat{
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat rootfs=$1
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat hostname=$2
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfield # set first network adapter as dhcp. This is the most common config.
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat cat <<EOF > $rootfs/etc/sysconfig/network/ifcfg-eth0
a7273db9f87f59815d36c3eca4d4501304ae84b2Frederic CrozatSTARTMODE='auto'
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. WarfieldBOOTPROTO='dhcp'
c840b37de865195a8742e219b4374d961a21d4d9Frederic CrozatEOF
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat # create empty fstab
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat touch $rootfs/etc/fstab
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat # set the hostname
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat cat <<EOF > $rootfs/etc/HOSTNAME
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat$hostname
c840b37de865195a8742e219b4374d961a21d4d9Frederic CrozatEOF
ba4c42597399c72fbb0b8f99e6ded79f738a6ac3Frederic Crozat # ensure /etc/hostname is available too
ba4c42597399c72fbb0b8f99e6ded79f738a6ac3Frederic Crozat ln -s -f HOSTNAME $rootfs/etc/hostname
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat # do not use hostname from HOSTNAME variable
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat cat <<EOF >> $rootfs/etc/sysconfig/cron
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatunset HOSTNAME
c840b37de865195a8742e219b4374d961a21d4d9Frederic CrozatEOF
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat # set minimal hosts
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat cat <<EOF > $rootfs/etc/hosts
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat127.0.0.1 localhost $hostname
c840b37de865195a8742e219b4374d961a21d4d9Frederic CrozatEOF
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat # disable yast->bootloader in container
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat cat <<EOF > $rootfs/etc/sysconfig/bootloader
c840b37de865195a8742e219b4374d961a21d4d9Frederic CrozatLOADER_TYPE=none
c840b37de865195a8742e219b4374d961a21d4d9Frederic CrozatLOADER_LOCATION=none
c840b37de865195a8742e219b4374d961a21d4d9Frederic CrozatEOF
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat
44ee8a102e3d8052631fbb119f58a55ce678d039Frederic Crozat # set /dev/console as securetty
44ee8a102e3d8052631fbb119f58a55ce678d039Frederic Crozat cat << EOF >> $rootfs/etc/securetty
44ee8a102e3d8052631fbb119f58a55ce678d039Frederic Crozatconsole
c840b37de865195a8742e219b4374d961a21d4d9Frederic CrozatEOF
44ee8a102e3d8052631fbb119f58a55ce678d039Frederic Crozat
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat cat <<EOF >> $rootfs/etc/sysconfig/boot
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat# disable root fsck
c840b37de865195a8742e219b4374d961a21d4d9Frederic CrozatROOTFS_FSCK="0"
c840b37de865195a8742e219b4374d961a21d4d9Frederic CrozatROOTFS_BLKDEV="/dev/null"
c840b37de865195a8742e219b4374d961a21d4d9Frederic CrozatEOF
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat # remove pointless services in a container
a7273db9f87f59815d36c3eca4d4501304ae84b2Frederic Crozat ln -s /dev/null $rootfs/etc/systemd/system/proc-sys-fs-binfmt_misc.automount
a7273db9f87f59815d36c3eca4d4501304ae84b2Frederic Crozat ln -s /dev/null $rootfs/etc/systemd/system/console-shell.service
a7273db9f87f59815d36c3eca4d4501304ae84b2Frederic Crozat ln -s /dev/null $rootfs/etc/systemd/system/systemd-vconsole-setup.service
e08c121b20ae60ec7ea434f210f3d534f2e2562cEvgeni Golov sed -e 's/ConditionPathExists=.*//' $rootfs/usr/lib/systemd/system/getty@.service > $rootfs/etc/systemd/system/getty@.service
36368228d286cd5c1492ae7aab92b4d78dbfb616Serge Hallyn ln -s getty@.service $rootfs/etc/systemd/system/getty@tty1.service
36368228d286cd5c1492ae7aab92b4d78dbfb616Serge Hallyn ln -s ../getty@.service $rootfs/etc/systemd/system/getty.target.wants/getty@console.service
36368228d286cd5c1492ae7aab92b4d78dbfb616Serge Hallyn ln -s -f ../getty@.service $rootfs/etc/systemd/system/getty.target.wants/getty@tty1.service
36368228d286cd5c1492ae7aab92b4d78dbfb616Serge Hallyn ln -s ../getty@.service $rootfs/etc/systemd/system/getty.target.wants/getty@tty2.service
36368228d286cd5c1492ae7aab92b4d78dbfb616Serge Hallyn ln -s ../getty@.service $rootfs/etc/systemd/system/getty.target.wants/getty@tty3.service
36368228d286cd5c1492ae7aab92b4d78dbfb616Serge Hallyn ln -s ../getty@.service $rootfs/etc/systemd/system/getty.target.wants/getty@tty4.service
36368228d286cd5c1492ae7aab92b4d78dbfb616Serge Hallyn
a7273db9f87f59815d36c3eca4d4501304ae84b2Frederic Crozat touch $rootfs/etc/sysconfig/kernel
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat echo "Please change root-password !"
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat return 0
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat}
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatdownload_opensuse()
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat{
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat cache=$1
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat arch=$2
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat
a3ed64707fb71b6f2fcf603e755c5da07ab3aec5Evgeni Golov if [ ! -x ${BUILD} ]; then
44ee8a102e3d8052631fbb119f58a55ce678d039Frederic Crozat echo "Could not create openSUSE template :"
44ee8a102e3d8052631fbb119f58a55ce678d039Frederic Crozat echo "you need to install \"build\" package"
44ee8a102e3d8052631fbb119f58a55ce678d039Frederic Crozat return 1
44ee8a102e3d8052631fbb119f58a55ce678d039Frederic Crozat fi
44ee8a102e3d8052631fbb119f58a55ce678d039Frederic Crozat
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat # check the mini opensuse was not already downloaded
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat mkdir -p "$cache/partial-$arch"
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat if [ $? -ne 0 ]; then
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber echo "Failed to create '$cache/partial-$arch' directory"
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber return 1
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat fi
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat # download a mini opensuse into a cache
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat echo "Downloading opensuse minimal ..."
44ee8a102e3d8052631fbb119f58a55ce678d039Frederic Crozat mkdir -p "$cache/partial-$arch-packages"
f4936bf19c56a688eec182e1916c8b660e3a0058Jiri Slaby zypper --quiet --root $cache/partial-$arch-packages --non-interactive ar http://download.opensuse.org/distribution/$DISTRO/repo/oss/ repo-oss || return 1
f2d63d7ac44cf8ebabf11cdc1a8b9ba39506167aTerzeus S. Dominguez # Leap update repos were rearranged
73fd697741d3fbe8ea9f0ee6ef303391e2c0cbb2Terzeus S. Dominguez if [[ $DISTRO == "leap/4"* ]]; then
f2d63d7ac44cf8ebabf11cdc1a8b9ba39506167aTerzeus S. Dominguez zypper --quiet --root $cache/partial-$arch-packages --non-interactive ar http://download.opensuse.org/update/$DISTRO/oss/ update || return 1
f2d63d7ac44cf8ebabf11cdc1a8b9ba39506167aTerzeus S. Dominguez else
f2d63d7ac44cf8ebabf11cdc1a8b9ba39506167aTerzeus S. Dominguez zypper --quiet --root $cache/partial-$arch-packages --non-interactive ar http://download.opensuse.org/update/$DISTRO/ update || return 1
f2d63d7ac44cf8ebabf11cdc1a8b9ba39506167aTerzeus S. Dominguez fi
f2d63d7ac44cf8ebabf11cdc1a8b9ba39506167aTerzeus S. Dominguez zypper --quiet --root $cache/partial-$arch-packages --non-interactive --gpg-auto-import-keys update || return 1
36368228d286cd5c1492ae7aab92b4d78dbfb616Serge Hallyn zypper --root $cache/partial-$arch-packages --non-interactive in --auto-agree-with-licenses --download-only zypper lxc patterns-openSUSE-base bash iputils sed tar rsyslog || return 1
44ee8a102e3d8052631fbb119f58a55ce678d039Frederic Crozat cat > $cache/partial-$arch-packages/opensuse.conf << EOF
44ee8a102e3d8052631fbb119f58a55ce678d039Frederic CrozatPreinstall: aaa_base bash coreutils diffutils
cc33e055dd047af7b4cc8a226bb54b3b9c450152Jiri SlabyPreinstall: filesystem fillup glibc grep insserv-compat perl-base
7638f5fd32d01475eb1a8f4014436b0ba75fc17eTerzeus S. DominguezPreinstall: libbz2-1 libncurses5 pam
36368228d286cd5c1492ae7aab92b4d78dbfb616Serge HallynPreinstall: permissions libreadline6 rpm sed tar libz1 libselinux1
a7273db9f87f59815d36c3eca4d4501304ae84b2Frederic CrozatPreinstall: liblzma5 libcap2 libacl1 libattr1
44ee8a102e3d8052631fbb119f58a55ce678d039Frederic CrozatPreinstall: libpopt0 libelf1 liblua5_1
a7273db9f87f59815d36c3eca4d4501304ae84b2Frederic CrozatPreinstall: libpcre1
44ee8a102e3d8052631fbb119f58a55ce678d039Frederic Crozat
44ee8a102e3d8052631fbb119f58a55ce678d039Frederic CrozatRunScripts: aaa_base
44ee8a102e3d8052631fbb119f58a55ce678d039Frederic Crozat
44ee8a102e3d8052631fbb119f58a55ce678d039Frederic CrozatSupport: zypper
44ee8a102e3d8052631fbb119f58a55ce678d039Frederic CrozatSupport: patterns-openSUSE-base
44ee8a102e3d8052631fbb119f58a55ce678d039Frederic CrozatSupport: lxc
a7273db9f87f59815d36c3eca4d4501304ae84b2Frederic CrozatSupport: ncurses-utils
a7273db9f87f59815d36c3eca4d4501304ae84b2Frederic CrozatSupport: iputils
a7273db9f87f59815d36c3eca4d4501304ae84b2Frederic CrozatSupport: udev
a7273db9f87f59815d36c3eca4d4501304ae84b2Frederic CrozatSupport: netcfg
f2d63d7ac44cf8ebabf11cdc1a8b9ba39506167aTerzeus S. DominguezSupport: hwinfo insserv-compat module-init-tools openSUSE-release openssh
36368228d286cd5c1492ae7aab92b4d78dbfb616Serge HallynSupport: pwdutils rpcbind sysconfig
a7273db9f87f59815d36c3eca4d4501304ae84b2Frederic Crozat
a7273db9f87f59815d36c3eca4d4501304ae84b2Frederic CrozatIgnore: rpm:suse-build-key,build-key
a7273db9f87f59815d36c3eca4d4501304ae84b2Frederic CrozatIgnore: systemd:systemd-presets-branding
44ee8a102e3d8052631fbb119f58a55ce678d039Frederic CrozatEOF
2e7a16a5a501acd1c1e270bd7b3c423b1aaa5d8bJohannes Kastl
2e7a16a5a501acd1c1e270bd7b3c423b1aaa5d8bJohannes Kastl if [ $DISTRO = "13.2" ]
2e7a16a5a501acd1c1e270bd7b3c423b1aaa5d8bJohannes Kastl then
2e7a16a5a501acd1c1e270bd7b3c423b1aaa5d8bJohannes Kastl echo "Support: python3-base" >> $cache/partial-$arch-packages/opensuse.conf
2e7a16a5a501acd1c1e270bd7b3c423b1aaa5d8bJohannes Kastl fi
2e7a16a5a501acd1c1e270bd7b3c423b1aaa5d8bJohannes Kastl
73fd697741d3fbe8ea9f0ee6ef303391e2c0cbb2Terzeus S. Dominguez # dhcpcd is not in the default repos since Leap 42.1
73fd697741d3fbe8ea9f0ee6ef303391e2c0cbb2Terzeus S. Dominguez if [[ $DISTRO != "leap/4"* ]]
f2d63d7ac44cf8ebabf11cdc1a8b9ba39506167aTerzeus S. Dominguez then
f2d63d7ac44cf8ebabf11cdc1a8b9ba39506167aTerzeus S. Dominguez echo "Support: dhcpcd" >> $cache/partial-$arch-packages/opensuse.conf
f2d63d7ac44cf8ebabf11cdc1a8b9ba39506167aTerzeus S. Dominguez fi
f2d63d7ac44cf8ebabf11cdc1a8b9ba39506167aTerzeus S. Dominguez
9a4fe12dc4944bb3a4d3a6c8b214c2d908206ae6Terzeus S. Dominguez # Leap doesn't seem to have iproute2 utils installed
73fd697741d3fbe8ea9f0ee6ef303391e2c0cbb2Terzeus S. Dominguez if [[ $DISTRO == "leap/4"* ]]
9a4fe12dc4944bb3a4d3a6c8b214c2d908206ae6Terzeus S. Dominguez then
9a4fe12dc4944bb3a4d3a6c8b214c2d908206ae6Terzeus S. Dominguez echo "Support: net-tools iproute2" >> $cache/partial-$arch-packages/opensuse.conf
9a4fe12dc4944bb3a4d3a6c8b214c2d908206ae6Terzeus S. Dominguez fi
9a4fe12dc4944bb3a4d3a6c8b214c2d908206ae6Terzeus S. Dominguez
17abf2784de1047fb2904ff130ee5efe4ea7b598Elan Ruusamäe if [ "$arch" = "i686" ]; then
a7273db9f87f59815d36c3eca4d4501304ae84b2Frederic Crozat mkdir -p $cache/partial-$arch-packages/var/cache/zypp/packages/repo-oss/suse/i686/
a7273db9f87f59815d36c3eca4d4501304ae84b2Frederic Crozat for i in "$cache/partial-$arch-packages/var/cache/zypp/packages/repo-oss/suse/i586/*" ; do
a7273db9f87f59815d36c3eca4d4501304ae84b2Frederic Crozat ln -s $i $cache/partial-$arch-packages/var/cache/zypp/packages/repo-oss/suse/i686/
a7273db9f87f59815d36c3eca4d4501304ae84b2Frederic Crozat done
a7273db9f87f59815d36c3eca4d4501304ae84b2Frederic Crozat mkdir -p $cache/partial-$arch-packages/var/cache/zypp/packages/update/i686
a7273db9f87f59815d36c3eca4d4501304ae84b2Frederic Crozat for i in "$cache/partial-$arch-packages/var/cache/zypp/packages/update/i586/*" ; do
a7273db9f87f59815d36c3eca4d4501304ae84b2Frederic Crozat ln -s $i $cache/partial-$arch-packages/var/cache/zypp/packages/update/i686/
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfield done
a7273db9f87f59815d36c3eca4d4501304ae84b2Frederic Crozat fi
44ee8a102e3d8052631fbb119f58a55ce678d039Frederic Crozat
2e7a16a5a501acd1c1e270bd7b3c423b1aaa5d8bJohannes Kastl # openSUSE 13.2 has no noarch directory in update
2e7a16a5a501acd1c1e270bd7b3c423b1aaa5d8bJohannes Kastl [ -d $cache/partial-$arch-packages/var/cache/zypp/packages/update/noarch ] || mkdir -p $cache/partial-$arch-packages/var/cache/zypp/packages/update/noarch
2e7a16a5a501acd1c1e270bd7b3c423b1aaa5d8bJohannes Kastl
a3ed64707fb71b6f2fcf603e755c5da07ab3aec5Evgeni Golov CLEAN_BUILD=1 BUILD_ARCH="$arch" BUILD_ROOT="$cache/partial-$arch" BUILD_DIST="$cache/partial-$arch-packages/opensuse.conf" PATH="$PATH:$BUILD_DIR" $BUILD_DIR/init_buildsystem --clean --configdir $BUILD_DIR/configs --cachedir $cache/partial-$arch-cache --repository $cache/partial-$arch-packages/var/cache/zypp/packages/repo-oss/suse/$arch --repository $cache/partial-$arch-packages/var/cache/zypp/packages/repo-oss/suse/noarch --repository $cache/partial-$arch-packages/var/cache/zypp/packages/update/$arch --repository $cache/partial-$arch-packages/var/cache/zypp/packages/update/noarch || return 1
f4936bf19c56a688eec182e1916c8b660e3a0058Jiri Slaby chroot $cache/partial-$arch /usr/bin/zypper --quiet --non-interactive ar http://download.opensuse.org/distribution/$DISTRO/repo/oss repo-oss || return 1
73fd697741d3fbe8ea9f0ee6ef303391e2c0cbb2Terzeus S. Dominguez
73fd697741d3fbe8ea9f0ee6ef303391e2c0cbb2Terzeus S. Dominguez if [[ $DISTRO == "leap/4"* ]]; then
6441f6ba7abd9fa29954104f57080707e3d5e942Terzeus S. Dominguez chroot $cache/partial-$arch /usr/bin/zypper --quiet --non-interactive ar http://download.opensuse.org/update/$DISTRO/oss update || return 1
6441f6ba7abd9fa29954104f57080707e3d5e942Terzeus S. Dominguez else
6441f6ba7abd9fa29954104f57080707e3d5e942Terzeus S. Dominguez chroot $cache/partial-$arch /usr/bin/zypper --quiet --non-interactive ar http://download.opensuse.org/update/$DISTRO/ update || return 1
6441f6ba7abd9fa29954104f57080707e3d5e942Terzeus S. Dominguez fi
73fd697741d3fbe8ea9f0ee6ef303391e2c0cbb2Terzeus S. Dominguez
44ee8a102e3d8052631fbb119f58a55ce678d039Frederic Crozat# really clean the image
44ee8a102e3d8052631fbb119f58a55ce678d039Frederic Crozat rm -fr $cache/partial-$arch/{.build,.guessed_dist,.srcfiles*,installed-pkg}
44ee8a102e3d8052631fbb119f58a55ce678d039Frederic Crozat rm -fr $cache/partial-$arch/dev
44ee8a102e3d8052631fbb119f58a55ce678d039Frederic Crozat# make sure we have a minimal /dev
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat mkdir -p "$cache/partial-$arch/dev"
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat mknod -m 666 $cache/partial-$arch/dev/null c 1 3
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat mknod -m 666 $cache/partial-$arch/dev/zero c 1 5
44ee8a102e3d8052631fbb119f58a55ce678d039Frederic Crozat# create mtab symlink
44ee8a102e3d8052631fbb119f58a55ce678d039Frederic Crozat rm -f $cache/partial-$arch/etc/mtab
44ee8a102e3d8052631fbb119f58a55ce678d039Frederic Crozat ln -sf /proc/self/mounts $cache/partial-$arch/etc/mtab
d696d21c2a7d5d15b3a456edd8ba742a5970d40aFrederic Crozat
d696d21c2a7d5d15b3a456edd8ba742a5970d40aFrederic Crozat# ensure /var/run and /run are symlinked
d696d21c2a7d5d15b3a456edd8ba742a5970d40aFrederic Crozat rm -fr $cache/partial-$arch/var/run
d696d21c2a7d5d15b3a456edd8ba742a5970d40aFrederic Crozat ln -s -f ../run $cache/partial-$arch/var/run
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat if [ $? -ne 0 ]; then
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber echo "Failed to download the rootfs, aborting."
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber return 1
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat fi
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat
44ee8a102e3d8052631fbb119f58a55ce678d039Frederic Crozat rm -fr "$cache/partial-$arch-packages"
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat mv "$1/partial-$arch" "$1/rootfs-$arch"
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat echo "Download complete."
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat return 0
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat}
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatcopy_opensuse()
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat{
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat cache=$1
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat arch=$2
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat rootfs=$3
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat # make a local copy of the mini opensuse
285ee6b8f120ebb8f37578081fb4bdc400538306Jiri Slaby echo "Copying rootfs to $rootfs ..."
6d8ac56b658a7aa35a46580c2df060c58ef02821Serge Hallyn mkdir -p $rootfs
44d397891e691ab994a69766cc72e57265b62da1Serge Hallyn rsync -Ha $cache/rootfs-$arch/ $rootfs/ || return 1
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat return 0
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat}
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatinstall_opensuse()
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat{
6dc6f80bfd7cb169948f2ef9a95dcf6d2edee853Kevin Carter # Allow the cache base to be set by environment variable
6dc6f80bfd7cb169948f2ef9a95dcf6d2edee853Kevin Carter cache="${LXC_CACHE_PATH:-@LOCALSTATEDIR@/cache/lxc/opensuse/$DISTRO}"
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat rootfs=$1
e29bf450cafa2ce2564aeb0b64d2014c17228407Dwight Engen mkdir -p @LOCALSTATEDIR@/lock/subsys/
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat (
17abf2784de1047fb2904ff130ee5efe4ea7b598Elan Ruusamäe flock -x 9
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber if [ $? -ne 0 ]; then
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber echo "Cache repository is busy."
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber return 1
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber fi
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber echo "Checking cache download in $cache/rootfs-$arch ... "
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber if [ ! -e "$cache/rootfs-$arch" ]; then
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber download_opensuse $cache $arch
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber if [ $? -ne 0 ]; then
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber echo "Failed to download 'opensuse base'"
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber return 1
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber fi
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber fi
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber echo "Copy $cache/rootfs-$arch to $rootfs ... "
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber copy_opensuse $cache $arch $rootfs
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber if [ $? -ne 0 ]; then
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber echo "Failed to copy rootfs"
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber return 1
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber fi
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber return 0
17abf2784de1047fb2904ff130ee5efe4ea7b598Elan Ruusamäe ) 9>@LOCALSTATEDIR@/lock/subsys/lxc-opensuse
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat return $?
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat}
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfield# Generate a random hardware (MAC) address composed of FE followed by
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfield# 5 random bytes...
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfieldcreate_hwaddr()
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfield{
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfield openssl rand -hex 5 | sed -e 's/\(..\)/:\1/g; s/^/fe/'
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfield}
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfield
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatcopy_configuration()
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat{
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat path=$1
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat rootfs=$2
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat name=$3
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfield grep -q "^lxc.rootfs" $path/config 2>/dev/null || echo "
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfieldlxc.rootfs = $rootfs_path
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfield" >> $path/config
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfield
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfield # The following code is to create static MAC addresses for each
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfield # interface in the container. This code will work for multiple
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfield # interfaces in the default config. It will also strip any
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfield # hwaddr stanzas out of the default config since we can not share
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfield # MAC addresses between containers.
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfield #
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfield # This code is largely mimiced from the Fedora Template.
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfield mv $path/config $path/config.def
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfield while read LINE
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfield do
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfield # This should catch variable expansions from the default config...
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfield if expr "${LINE}" : '.*\$' > /dev/null 2>&1
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfield then
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfield LINE=$(eval "echo \"${LINE}\"")
c01c25fcdd1e0cacad8075bcfcef4c8e8d4b8cb6Stéphane Graber fi
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfield
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfield # There is a tab and a space in the regex bracket below!
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfield # Seems that \s doesn't work in brackets.
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfield KEY=$(expr "${LINE}" : '\s*\([^ ]*\)\s*=')
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfield
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfield if [[ "${KEY}" != "lxc.network.hwaddr" ]]
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfield then
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfield echo "${LINE}" >> $path/config
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfield
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfield if [[ "${KEY}" == "lxc.network.link" ]]
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfield then
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfield echo "lxc.network.hwaddr = $(create_hwaddr)" >> $path/config
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfield fi
c01c25fcdd1e0cacad8075bcfcef4c8e8d4b8cb6Stéphane Graber fi
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfield done < $path/config.def
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfield
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfield rm -f $path/config.def
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfield
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfield if [ -e "@LXCTEMPLATECONFIG@/opensuse.common.conf" ]; then
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfield echo "
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfield# Include common configuration
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfieldlxc.include = @LXCTEMPLATECONFIG@/opensuse.common.conf
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfield" >> $path/config
a7273db9f87f59815d36c3eca4d4501304ae84b2Frederic Crozat fi
ba4c42597399c72fbb0b8f99e6ded79f738a6ac3Frederic Crozat
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfield # Append things which require expansion here...
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat cat <<EOF >> $path/config
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfieldlxc.arch = $arch
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatlxc.utsname = $name
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfield
f24a52d5f588ff4e4575046903fb9498c376d833Stéphane Graberlxc.mount.auto = cgroup:mixed proc:mixed sys:mixed
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat
f02ce27d4b1a9d01b88d0ffaf626e5bafa671bf0Stéphane Graber# When using LXC with apparmor, uncomment the next line to run unconfined:
da9ca6569a250f42c35292a0b5eb6731c89860e2Terzeus S. Dominguezlxc.aa_profile = unconfined
f02ce27d4b1a9d01b88d0ffaf626e5bafa671bf0Stéphane Graber
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfield# example simple networking setup, uncomment to enable
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfield#lxc.network.type = $lxc_network_type
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfield#lxc.network.flags = up
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfield#lxc.network.link = $lxc_network_link
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfield#lxc.network.name = eth0
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfield# Additional example for veth network type
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfield# static MAC address,
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfield#lxc.network.hwaddr = 00:16:3e:77:52:20
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfield# persistent veth device name on host side
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfield# Note: This may potentially collide with other containers of same name!
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfield#lxc.network.veth.pair = v-$name-e0
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfield
c840b37de865195a8742e219b4374d961a21d4d9Frederic CrozatEOF
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat if [ $? -ne 0 ]; then
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber echo "Failed to add configuration"
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber return 1
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat fi
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat return 0
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat}
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatclean()
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat{
6dc6f80bfd7cb169948f2ef9a95dcf6d2edee853Kevin Carter cache="${LXC_CACHE_PATH:-@LOCALSTATEDIR@/cache/lxc/opensuse}"
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat if [ ! -e $cache ]; then
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber exit 0
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat fi
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat # lock, so we won't purge while someone is creating a repository
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat (
17abf2784de1047fb2904ff130ee5efe4ea7b598Elan Ruusamäe flock -x 9
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber if [ $? != 0 ]; then
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber echo "Cache repository is busy."
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber exit 1
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber fi
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber echo -n "Purging the download cache..."
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber rm --preserve-root --one-file-system -rf $cache && echo "Done." || exit 1
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber exit 0
17abf2784de1047fb2904ff130ee5efe4ea7b598Elan Ruusamäe ) 9>@LOCALSTATEDIR@/lock/subsys/lxc-opensuse
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat}
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatusage()
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat{
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat cat <<EOF
0ce7569856cc7a366f58688f6b6a71610167fc76Johannes Kastl$1 -h|--help -p|--path=<path> -r|--release nn.n --clean
8f3a3cd80509d32443072b5f678fdebd04cbc882Johannes KastlPlease give the release as 13.1, 13.2 etc.
eef20f61f0d1851ed0c11a12c9dd1f086cf7b404Terzeus S. DominguezIf no release is given, openSUSE Leap 42.2 is installed.
c840b37de865195a8742e219b4374d961a21d4d9Frederic CrozatEOF
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat return 0
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat}
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfield# Make arch a global. This may become configurable?
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfieldarch=$(uname -m)
41cf1ac30de569888c70b1f1b40d29993950ff2eMichael H. Warfield
2e7a16a5a501acd1c1e270bd7b3c423b1aaa5d8bJohannes Kastloptions=$(getopt -o hp:n:r:c -l help,rootfs:,path:,name:,release:,clean -- "$@")
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatif [ $? -ne 0 ]; then
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat usage $(basename $0)
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat exit 1
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatfi
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozateval set -- "$options"
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatwhile true
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatdo
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat case "$1" in
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber -h|--help) usage $0 && exit 0;;
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber -p|--path) path=$2; shift 2;;
1897e3bcd36af9f3fe6d3649910a9adb93e5e988Serge Hallyn --rootfs) rootfs=$2; shift 2;;
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber -n|--name) name=$2; shift 2;;
1111674232c2e93ddc2c165f3d43df8fe050ac82Michael Adam -r|--release) DISTRO=$2; shift 2;;
eb4cd29636a136c867c43937670a1c6295cb18b0Michael Adam -c|--clean) clean=1; shift 1;;
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber --) shift 1; break ;;
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber *) break ;;
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat esac
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatdone
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatif [ ! -z "$clean" -a -z "$path" ]; then
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat clean || exit 1
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat exit 0
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatfi
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozattype zypper > /dev/null
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatif [ $? -ne 0 ]; then
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat echo "'zypper' command is missing"
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat exit 1
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatfi
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatif [ -z "$path" ]; then
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat echo "'path' parameter is required"
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat exit 1
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatfi
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat
de548c6055a6246804a8217e901c9272dbf699d4Johannes Kastlif grep -q Harlequin /etc/os-release || grep -q Tumbleweed /etc/os-release ; then
fe89217a880dafc8da0357fa1444e24d0bf9f202Jiri Slaby BVER=`rpm -q --qf '%{version}\n' build`
fe89217a880dafc8da0357fa1444e24d0bf9f202Jiri Slaby if [ $? -ne 0 -o "$BVER" -lt "20141120" ]; then
d3eccbbf805cb68522955519b0709853f6bc7bffJohannes Kastl echo "Building openSUSE containers with your version of the build package is broken. Please install the update to version 20141120 or newer."
d3eccbbf805cb68522955519b0709853f6bc7bffJohannes Kastl exit 1
d3eccbbf805cb68522955519b0709853f6bc7bffJohannes Kastl fi
f38788b405e6738bf3fbe6731e28c18967da71b2Johannes Kastlfi
f38788b405e6738bf3fbe6731e28c18967da71b2Johannes Kastl
2e7a16a5a501acd1c1e270bd7b3c423b1aaa5d8bJohannes Kastlif [ -z "$DISTRO" ]; then
3e892287baec47fe72116eba0f0246a505153045Johannes Kastl echo ""
eef20f61f0d1851ed0c11a12c9dd1f086cf7b404Terzeus S. Dominguez echo "No release selected, using openSUSE Leap 42.2"
6865ec3c97e17408fd09e386d291af5ff7b495b0Maxime Besson DISTRO="leap/42.2"
3e892287baec47fe72116eba0f0246a505153045Johannes Kastlelse
3e892287baec47fe72116eba0f0246a505153045Johannes Kastl echo ""
3e892287baec47fe72116eba0f0246a505153045Johannes Kastl case "$DISTRO" in
3e892287baec47fe72116eba0f0246a505153045Johannes Kastl 13.1)
3e892287baec47fe72116eba0f0246a505153045Johannes Kastl echo "Selected openSUSE 13.1"
3e892287baec47fe72116eba0f0246a505153045Johannes Kastl ;;
3e892287baec47fe72116eba0f0246a505153045Johannes Kastl
3e892287baec47fe72116eba0f0246a505153045Johannes Kastl 13.2)
3e892287baec47fe72116eba0f0246a505153045Johannes Kastl echo "Selected openSUSE 13.2"
3e892287baec47fe72116eba0f0246a505153045Johannes Kastl ;;
3e892287baec47fe72116eba0f0246a505153045Johannes Kastl
f2d63d7ac44cf8ebabf11cdc1a8b9ba39506167aTerzeus S. Dominguez 42.1|leap/42.1|leap)
f2d63d7ac44cf8ebabf11cdc1a8b9ba39506167aTerzeus S. Dominguez echo "Selected openSUSE Leap 42.1"
f2d63d7ac44cf8ebabf11cdc1a8b9ba39506167aTerzeus S. Dominguez DISTRO="leap/42.1"
f2d63d7ac44cf8ebabf11cdc1a8b9ba39506167aTerzeus S. Dominguez ;;
f2d63d7ac44cf8ebabf11cdc1a8b9ba39506167aTerzeus S. Dominguez
73fd697741d3fbe8ea9f0ee6ef303391e2c0cbb2Terzeus S. Dominguez 42.2|leap/42.2|422)
73fd697741d3fbe8ea9f0ee6ef303391e2c0cbb2Terzeus S. Dominguez echo "Selected openSUSE Leap 42.2"
73fd697741d3fbe8ea9f0ee6ef303391e2c0cbb2Terzeus S. Dominguez DISTRO="leap/42.2"
73fd697741d3fbe8ea9f0ee6ef303391e2c0cbb2Terzeus S. Dominguez ;;
73fd697741d3fbe8ea9f0ee6ef303391e2c0cbb2Terzeus S. Dominguez
3e892287baec47fe72116eba0f0246a505153045Johannes Kastl *)
3e892287baec47fe72116eba0f0246a505153045Johannes Kastl echo "You have chosen an invalid release, quitting..."
3e892287baec47fe72116eba0f0246a505153045Johannes Kastl exit 1
3e892287baec47fe72116eba0f0246a505153045Johannes Kastl ;;
3e892287baec47fe72116eba0f0246a505153045Johannes Kastl esac
2e7a16a5a501acd1c1e270bd7b3c423b1aaa5d8bJohannes Kastlfi
2e7a16a5a501acd1c1e270bd7b3c423b1aaa5d8bJohannes Kastl
2e7a16a5a501acd1c1e270bd7b3c423b1aaa5d8bJohannes Kastl
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatif [ "$(id -u)" != "0" ]; then
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat echo "This script should be run as 'root'"
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat exit 1
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatfi
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat
1881820ae4ff9004beef1bf7f04553580840441dSerge Hallyn# detect rootfs
1881820ae4ff9004beef1bf7f04553580840441dSerge Hallynconfig="$path/config"
1897e3bcd36af9f3fe6d3649910a9adb93e5e988Serge Hallynif [ -z "$rootfs" ]; then
1897e3bcd36af9f3fe6d3649910a9adb93e5e988Serge Hallyn if grep -q '^lxc.rootfs' $config 2>/dev/null ; then
853d58fdf5af0960b7b6edc9dea0fadddb8535f1Elan Ruusamäe rootfs=$(awk -F= '/^lxc.rootfs =/{ print $2 }' $config)
1897e3bcd36af9f3fe6d3649910a9adb93e5e988Serge Hallyn else
1897e3bcd36af9f3fe6d3649910a9adb93e5e988Serge Hallyn rootfs=$path/rootfs
1897e3bcd36af9f3fe6d3649910a9adb93e5e988Serge Hallyn fi
1881820ae4ff9004beef1bf7f04553580840441dSerge Hallynfi
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatinstall_opensuse $rootfs
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatif [ $? -ne 0 ]; then
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat echo "failed to install opensuse"
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat exit 1
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatfi
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatconfigure_opensuse $rootfs $name
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatif [ $? -ne 0 ]; then
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat echo "failed to configure opensuse for a container"
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat exit 1
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatfi
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatcopy_configuration $path $rootfs $name
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatif [ $? -ne 0 ]; then
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat echo "failed write configuration file"
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat exit 1
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatfi
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat
b5a285ea8fde10254f3b6d1743cec372a2d01605Michael Adamif [ ! -z "$clean" ]; then
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat clean || exit 1
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozat exit 0
c840b37de865195a8742e219b4374d961a21d4d9Frederic Crozatfi