262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin#!/bin/bash
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin#
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin# template script for generating altlinux container for LXC
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin#
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin#
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin# lxc: linux Container library
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin# Authors:
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin# Alexey Shabalin <shaba@altlinux.org>
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin# This library is free software; you can redistribute it and/or
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin# modify it under the terms of the GNU Lesser General Public
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin# License as published by the Free Software Foundation; either
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin# version 2.1 of the License, or (at your option) any later version.
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin# This library is distributed in the hope that it will be useful,
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin# but WITHOUT ANY WARRANTY; without even the implied warranty of
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin# Lesser General Public License for more details.
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin# You should have received a copy of the GNU Lesser General Public
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin# 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
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin
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
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin#Configurations
ed4616b1cfbc84dd01caa8546d813e8c5d482921Christian Bühlerarch=$(uname -m)
e29bf450cafa2ce2564aeb0b64d2014c17228407Dwight Engencache_base=@LOCALSTATEDIR@/cache/lxc/altlinux/$arch
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalindefault_path=@LXCPATH@
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalindefault_profile=default
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalinprofile_dir=/etc/lxc/profiles
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalinlxc_network_type=veth
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalinlxc_network_link=virbr0
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin# is this altlinux?
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin[ -f /etc/altlinux-release ] && is_altlinux=true
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalinconfigure_altlinux()
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin{
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin # disable selinux in altlinux
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin mkdir -p $rootfs_path/selinux
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin echo 0 > $rootfs_path/selinux/enforce
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin
5c60f9903768b49d329e20e3fdb333753f719502Denis Pynkin mkdir -p ${rootfs_path}/etc/net/ifaces/eth0
5c60f9903768b49d329e20e3fdb333753f719502Denis Pynkin cat <<EOF > ${rootfs_path}/etc/net/ifaces/eth0/options
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey ShabalinBOOTPROTO=${BOOTPROTO}
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey ShabalinONBOOT=yes
5c60f9903768b49d329e20e3fdb333753f719502Denis PynkinNM_CONTROLLED=yes
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey ShabalinTYPE=eth
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey ShabalinEOF
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalinif [ ${BOOTPROTO} != "dhcp" ]; then
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalin # ip address
5c60f9903768b49d329e20e3fdb333753f719502Denis Pynkin cat <<EOF > ${rootfs_path}/etc/net/ifaces/eth0/ipv4address
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalin${ipv4}
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey ShabalinEOF
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalin
5c60f9903768b49d329e20e3fdb333753f719502Denis Pynkin cat <<EOF > ${rootfs_path}/etc/net/ifaces/eth0/ipv4route
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalin${gw}
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey ShabalinEOF
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalin
5c60f9903768b49d329e20e3fdb333753f719502Denis Pynkin cat <<EOF > ${rootfs_path}/etc/net/ifaces/eth0/resolv.conf
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalinnameserver ${dns}
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey ShabalinEOF
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalin
5c60f9903768b49d329e20e3fdb333753f719502Denis Pynkin cat <<EOF > ${rootfs_path}/etc/net/ifaces/eth0/ipv6address
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalin${ipv6}
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey ShabalinEOF
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalin
5c60f9903768b49d329e20e3fdb333753f719502Denis Pynkin cat <<EOF > ${rootfs_path}/etc/net/ifaces/eth0/ipv6route
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalin${gw6}
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey ShabalinEOF
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalin
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalinfi
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalin
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin # set the hostname
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin cat <<EOF > ${rootfs_path}/etc/sysconfig/network
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey ShabalinNETWORKING=yes
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey ShabalinCONFMETHOD=etcnet
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey ShabalinHOSTNAME=${UTSNAME}
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey ShabalinRESOLV_MODS=yes
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey ShabalinEOF
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin # set minimal hosts
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin cat <<EOF > $rootfs_path/etc/hosts
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin127.0.0.1 localhost.localdomain localhost $name
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey ShabalinEOF
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin # Allow to login at virsh console. loginuid.so doen't work in the absence of auditd.
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalin# sed -i 's/^.*loginuid.so.*$/\#&/' ${rootfs_path}/etc/pam.d/common-login
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin # Allow root to login at virsh console
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin echo "pts/0" >> ${rootfs_path}/etc/securetty
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalin echo "console" >> ${rootfs_path}/etc/securetty
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin
05e61b82cff6c44621e7d23bf3cbb756f3ae681bDenis Pynkin # Enable services
5c60f9903768b49d329e20e3fdb333753f719502Denis Pynkin for service in network syslogd random NetworkManager
05e61b82cff6c44621e7d23bf3cbb756f3ae681bDenis Pynkin do
05e61b82cff6c44621e7d23bf3cbb756f3ae681bDenis Pynkin chroot ${rootfs_path} chkconfig $service --list &>/dev/null && chroot ${rootfs_path} chkconfig $service on || true
5c60f9903768b49d329e20e3fdb333753f719502Denis Pynkin # For systemd
5c60f9903768b49d329e20e3fdb333753f719502Denis Pynkin chroot ${rootfs_path} systemctl -q enable $service &>/dev/null|| true
05e61b82cff6c44621e7d23bf3cbb756f3ae681bDenis Pynkin done
05e61b82cff6c44621e7d23bf3cbb756f3ae681bDenis Pynkin # Disable services
05e61b82cff6c44621e7d23bf3cbb756f3ae681bDenis Pynkin for service in rawdevices fbsetfont
05e61b82cff6c44621e7d23bf3cbb756f3ae681bDenis Pynkin do
05e61b82cff6c44621e7d23bf3cbb756f3ae681bDenis Pynkin chroot ${rootfs_path} chkconfig $service --list &>/dev/null && chroot ${rootfs_path} chkconfig $service off || true
5c60f9903768b49d329e20e3fdb333753f719502Denis Pynkin chroot ${rootfs_path} systemctl -q disable $service &>/dev/null || true
05e61b82cff6c44621e7d23bf3cbb756f3ae681bDenis Pynkin done
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalin subst 's/^\([3-9]\+:[0-9]\+:respawn:\/sbin\/mingetty.*\)/#\1/' ${rootfs_path}/etc/inittab
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalin echo "c1:2345:respawn:/sbin/mingetty --noclear console" >> ${rootfs_path}/etc/inittab
05e61b82cff6c44621e7d23bf3cbb756f3ae681bDenis Pynkin
05e61b82cff6c44621e7d23bf3cbb756f3ae681bDenis Pynkin [ -f "${rootfs_path}/etc/syslog.conf" ] && \
05e61b82cff6c44621e7d23bf3cbb756f3ae681bDenis Pynkin subst 's,\/dev\/tty12,/var/log/syslog/console,' ${rootfs_path}/etc/syslog.conf
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin dev_path="${rootfs_path}/dev"
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalin rm -rf ${dev_path}
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalin mkdir -p ${dev_path}
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin mknod -m 666 ${dev_path}/null c 1 3
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin mknod -m 666 ${dev_path}/zero c 1 5
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin mknod -m 644 ${dev_path}/random c 1 8
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin mknod -m 644 ${dev_path}/urandom c 1 9
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin mkdir -m 755 ${dev_path}/pts
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin mkdir -m 1777 ${dev_path}/shm
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin mknod -m 666 ${dev_path}/tty c 5 0
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalin chown root:tty ${dev_path}/tty
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalin mknod -m 600 ${dev_path}/tty0 c 4 0
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalin mknod -m 600 ${dev_path}/tty1 c 4 1
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalin mknod -m 600 ${dev_path}/tty2 c 4 2
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalin mknod -m 600 ${dev_path}/tty3 c 4 3
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalin mknod -m 600 ${dev_path}/tty4 c 4 4
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin mknod -m 600 ${dev_path}/console c 5 1
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin mknod -m 666 ${dev_path}/full c 1 7
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin mknod -m 600 ${dev_path}/initctl p
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin mknod -m 666 ${dev_path}/ptmx c 5 2
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalin chown root:tty ${dev_path}/ptmx
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalin ln -s /proc/self/fd ${dev_path}/fd
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalin ln -s /proc/kcore ${dev_path}/core
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalin mkdir -m 755 ${dev_path}/mapper
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalin mknod -m 600 ${dev_path}/mapper/control c 10 236
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalin mkdir -m 755 ${dev_path}/net
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalin mknod -m 666 ${dev_path}/net/tun c 10 200
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin
8c7dddc25c47f9f060b91e0a39f7218aa433755cEvgeni Golov if [ -n "${root_password}" ]; then
8c7dddc25c47f9f060b91e0a39f7218aa433755cEvgeni Golov echo "setting root passwd to $root_password"
8c7dddc25c47f9f060b91e0a39f7218aa433755cEvgeni Golov echo "root:$root_password" | chroot $rootfs_path chpasswd
8c7dddc25c47f9f060b91e0a39f7218aa433755cEvgeni Golov fi
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin return 0
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin}
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalindownload_altlinux()
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin{
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin # check the mini altlinux was not already downloaded
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin INSTALL_ROOT=$cache/partial
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin mkdir -p $INSTALL_ROOT
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin if [ $? -ne 0 ]; then
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber echo "Failed to create '$INSTALL_ROOT' directory"
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber return 1
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin fi
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin # download a mini altlinux into a cache
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin echo "Downloading altlinux minimal ..."
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin APT_GET="apt-get -o RPM::RootDir=$INSTALL_ROOT -y"
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin PKG_LIST="$(grep -hs '^[^#]' "$profile_dir/$profile")"
a9ae28a05a65f2bd0dc6695ab5cdfb723ee8b226Denis Pynkin # if no configuration file $profile -- fall back to default list of packages
3d5658d167db8866d5cd3b4b89f0e4becc735719Denis Pynkin [ -z "$PKG_LIST" ] && PKG_LIST="interactivesystem apt apt-conf etcnet-full openssh-server systemd-sysvinit systemd-units systemd NetworkManager-daemon"
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin mkdir -p $INSTALL_ROOT/var/lib/rpm
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin rpm --root $INSTALL_ROOT --initdb
a9ae28a05a65f2bd0dc6695ab5cdfb723ee8b226Denis Pynkin
a9ae28a05a65f2bd0dc6695ab5cdfb723ee8b226Denis Pynkin # some scripts want to have /dev/null at least
a9ae28a05a65f2bd0dc6695ab5cdfb723ee8b226Denis Pynkin dev_path="$INSTALL_ROOT/dev"
a9ae28a05a65f2bd0dc6695ab5cdfb723ee8b226Denis Pynkin if [ ! -c "${dev_path}/null" ]; then
a9ae28a05a65f2bd0dc6695ab5cdfb723ee8b226Denis Pynkin mkdir -p "${dev_path}"
a9ae28a05a65f2bd0dc6695ab5cdfb723ee8b226Denis Pynkin mknod -m 666 "${dev_path}/null" c 1 3
a9ae28a05a65f2bd0dc6695ab5cdfb723ee8b226Denis Pynkin fi
a9ae28a05a65f2bd0dc6695ab5cdfb723ee8b226Denis Pynkin
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin $APT_GET install $PKG_LIST
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin if [ $? -ne 0 ]; then
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber echo "Failed to download the rootfs, aborting."
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber return 1
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin fi
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin mv "$INSTALL_ROOT" "$cache/rootfs"
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin echo "Download complete."
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin return 0
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin}
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalincopy_altlinux()
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin{
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin # make a local copy of the minialtlinux
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin echo -n "Copying rootfs to $rootfs_path ..."
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin #cp -a $cache/rootfs-$arch $rootfs_path || return 1
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin # i prefer rsync (no reason really)
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin mkdir -p $rootfs_path
44d397891e691ab994a69766cc72e57265b62da1Serge Hallyn rsync -Ha $cache/rootfs/ $rootfs_path/
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin return 0
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin}
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalinupdate_altlinux()
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin{
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin chroot $cache/rootfs apt-get update
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin chroot $cache/rootfs apt-get -y dist-upgrade
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin}
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalininstall_altlinux()
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin{
e29bf450cafa2ce2564aeb0b64d2014c17228407Dwight Engen mkdir -p @LOCALSTATEDIR@/lock/subsys/
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin (
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 ... "
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber if [ ! -e "$cache/rootfs" ]; then
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber download_altlinux
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber if [ $? -ne 0 ]; then
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber echo "Failed to download 'altlinux base'"
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber return 1
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber fi
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin else
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber echo "Cache found. Updating..."
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin update_altlinux
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber if [ $? -ne 0 ]; then
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber echo "Failed to update 'altlinux base', continuing with last known good cache"
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin else
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin echo "Update finished"
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber fi
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber fi
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber echo "Copy $cache/rootfs to $rootfs_path ... "
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber copy_altlinux
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 return 0
17abf2784de1047fb2904ff130ee5efe4ea7b598Elan Ruusamäe ) 9>@LOCALSTATEDIR@/lock/subsys/lxc-altlinux
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin return $?
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin}
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalincopy_configuration()
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin{
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin mkdir -p $config_path
1881820ae4ff9004beef1bf7f04553580840441dSerge Hallyn grep -q "^lxc.rootfs" $config_path/config 2>/dev/null || echo "lxc.rootfs = $rootfs_path" >> $config_path/config
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin cat <<EOF >> $config_path/config
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalinlxc.utsname = $name
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalinlxc.tty = 4
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalinlxc.pts = 1024
eee3ba81c88e64b8a732694fc4843a39d5bde491Serge Hallynlxc.cap.drop = sys_module mac_admin mac_override sys_time
f02ce27d4b1a9d01b88d0ffaf626e5bafa671bf0Stéphane Graber
f02ce27d4b1a9d01b88d0ffaf626e5bafa671bf0Stéphane Graber# When using LXC with apparmor, uncomment the next line to run unconfined:
f02ce27d4b1a9d01b88d0ffaf626e5bafa671bf0Stéphane Graber#lxc.aa_profile = unconfined
f02ce27d4b1a9d01b88d0ffaf626e5bafa671bf0Stéphane Graber
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin#networking
5c60f9903768b49d329e20e3fdb333753f719502Denis Pynkin#lxc.network.type = $lxc_network_type
5c60f9903768b49d329e20e3fdb333753f719502Denis Pynkin#lxc.network.flags = up
5c60f9903768b49d329e20e3fdb333753f719502Denis Pynkin#lxc.network.link = $lxc_network_link
5c60f9903768b49d329e20e3fdb333753f719502Denis Pynkin#lxc.network.name = veth0
5c60f9903768b49d329e20e3fdb333753f719502Denis Pynkin#lxc.network.mtu = 1500
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey ShabalinEOF
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalinif [ ! -z ${ipv4} ]; then
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalin cat <<EOF >> $config_path/config
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalinlxc.network.ipv4 = $ipv4
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey ShabalinEOF
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalinfi
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalinif [ ! -z ${gw} ]; then
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalin cat <<EOF >> $config_path/config
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalinlxc.network.ipv4.gateway = $gw
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey ShabalinEOF
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalinfi
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalinif [ ! -z ${ipv6} ]; then
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalin cat <<EOF >> $config_path/config
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalinlxc.network.ipv6 = $ipv6
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey ShabalinEOF
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalinfi
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalinif [ ! -z ${gw6} ]; then
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalin cat <<EOF >> $config_path/config
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalinlxc.network.ipv6.gateway = $gw6
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey ShabalinEOF
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalinfi
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalin cat <<EOF >> $config_path/config
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin#cgroups
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalinlxc.cgroup.devices.deny = a
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin# /dev/null and zero
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalinlxc.cgroup.devices.allow = c 1:3 rwm
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalinlxc.cgroup.devices.allow = c 1:5 rwm
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin# consoles
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalinlxc.cgroup.devices.allow = c 5:1 rwm
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalinlxc.cgroup.devices.allow = c 5:0 rwm
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalinlxc.cgroup.devices.allow = c 4:0 rwm
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalinlxc.cgroup.devices.allow = c 4:1 rwm
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin# /dev/{,u}random
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalinlxc.cgroup.devices.allow = c 1:9 rwm
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalinlxc.cgroup.devices.allow = c 1:8 rwm
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalinlxc.cgroup.devices.allow = c 136:* rwm
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalinlxc.cgroup.devices.allow = c 5:2 rwm
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin# rtc
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalinlxc.cgroup.devices.allow = c 10:135 rwm
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin
f24a52d5f588ff4e4575046903fb9498c376d833Stéphane Graberlxc.mount.auto = cgroup:mixed proc:mixed sys:mixed
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey ShabalinEOF
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin if [ $? -ne 0 ]; then
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber echo "Failed to add configuration"
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber return 1
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin fi
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin return 0
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin}
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalinclean()
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin{
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin if [ ! -e $cache ]; then
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber exit 0
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin fi
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin # lock, so we won't purge while someone is creating a repository
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin (
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 for ALTLinux-$release..."
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-altlinux
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin}
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalinusage()
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin{
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin cat <<EOF
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalinusage:
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin $1 -n|--name=<container_name>
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin [-p|--path=<path>] [-c|--clean] [-R|--release=<ALTLinux_release>]
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalin [-4|--ipv4=<ipv4 address>] [-6|--ipv6=<ipv6 address>]
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalin [-g|--gw=<gw address>] [-d|--dns=<dns address>]
1897e3bcd36af9f3fe6d3649910a9adb93e5e988Serge Hallyn [-P|--profile=<name of the profile>] [--rootfs=<path>]
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin [-A|--arch=<arch of the container>]
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin [-h|--help]
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey ShabalinMandatory args:
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin -n,--name container name, used to as an identifier for that container from now on
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey ShabalinOptional args:
e29bf450cafa2ce2564aeb0b64d2014c17228407Dwight Engen -p,--path path to where the container rootfs will be created, defaults to @LXCPATH@. The container config will go under @LXCPATH@ in that case
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin -c,--clean clean the cache
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin -R,--release ALTLinux release for the new container. if the host is ALTLinux, then it will defaultto the host's release.
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalin -4,--ipv4 specify the ipv4 address to assign to the virtualized interface, eg. 192.168.1.123/24
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalin -6,--ipv6 specify the ipv6 address to assign to the virtualized interface, eg. 2003:db8:1:0:214:1234:fe0b:3596/64
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalin -g,--gw specify the default gw, eg. 192.168.1.1
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalin -G,--gw6 specify the default gw, eg. 2003:db8:1:0:214:1234:fe0b:3596
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalin -d,--dns specify the DNS server, eg. 192.168.1.2
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin -P,--profile Profile name is the file name in /etc/lxc/profiles contained packages name for install to cache.
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin -A,--arch NOT USED YET. Define what arch the container will be [i686,x86_64]
1897e3bcd36af9f3fe6d3649910a9adb93e5e988Serge Hallyn ---rootfs rootfs path
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin -h,--help print this help
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey ShabalinEOF
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin return 0
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin}
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin
a9ae28a05a65f2bd0dc6695ab5cdfb723ee8b226Denis Pynkinoptions=$(getopt -o hp:n:P:cR:4:6:g:d: -l help,rootfs:,path:,name:,profile:,clean,release:,ipv4:,ipv6:,gw:,dns: -- "$@")
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalinif [ $? -ne 0 ]; then
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin usage $(basename $0)
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin exit 1
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalinfi
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalineval set -- "$options"
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalinwhile true
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalindo
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin 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_path=$2; shift 2;;
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber -n|--name) name=$2; shift 2;;
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber -P|--profile) profile=$2; shift 2;;
217535de29d88d64ed3b8c7093e23d954b9545caMichael Adam -c|--clean) clean=1; shift 1;;
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber -R|--release) release=$2; shift 2;;
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber -4|--ipv4) ipv4=$2; shift 2;;
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber -6|--ipv6) ipv6=$2; shift 2;;
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber -g|--gw) gw=$2; shift 2;;
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber -d|--dns) dns=$2; shift 2;;
14d9c0f09d1a55d124ef210a4b4e205c9fe7596cStéphane Graber --) shift 1; break ;;
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin *) break ;;
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin esac
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalindone
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalinif [ ! -z "$clean" -a -z "$path" ]; then
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin clean || exit 1
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin exit 0
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalinfi
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalintype apt-get >/dev/null 2>&1
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalinif [ $? -ne 0 ]; then
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin echo "'apt-get' command is missing"
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin exit 1
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalinfi
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalinif [ -z "$path" ]; then
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin path=$default_path
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalinfi
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalinif [ -z "$profile" ]; then
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin profile=$default_profile
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalinfi
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalinif [ -z "$release" ]; then
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin if [ "$is_altlinux" ]; then
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin release=$(cat /etc/altlinux-release |awk '/^ALT/ {print $3}')
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin else
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin echo "This is not a ALTLinux host and release missing, use -R|--release to specify release"
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin exit 1
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin fi
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalinfi
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalinif [ -z "$ipv4" -a -z "$ipv6" ]; then
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalin BOOTPROTO="dhcp"
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalinelse
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalin BOOTPROTO="static"
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalinfi
b031f0d2ca1b40eab86286b82d3c5e8b379122e6Alexey Shabalin
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalinif [ "$(id -u)" != "0" ]; then
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin echo "This script should be run as 'root'"
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin exit 1
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalinfi
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin
1897e3bcd36af9f3fe6d3649910a9adb93e5e988Serge Hallyn# check for 'lxc.rootfs' passed in through default config by lxc-create
1897e3bcd36af9f3fe6d3649910a9adb93e5e988Serge Hallynif [ -z "$rootfs_path" ]; then
1897e3bcd36af9f3fe6d3649910a9adb93e5e988Serge Hallyn if grep -q '^lxc.rootfs' $path/config 2>/dev/null ; then
853d58fdf5af0960b7b6edc9dea0fadddb8535f1Elan Ruusamäe rootfs_path=$(awk -F= '/^lxc.rootfs =/{ print $2 }' $path/config)
1897e3bcd36af9f3fe6d3649910a9adb93e5e988Serge Hallyn else
44b430e2c5a11f792e21d3774b530f410ff5af75Serge Logvinov rootfs_path=$path/rootfs
1897e3bcd36af9f3fe6d3649910a9adb93e5e988Serge Hallyn fi
1897e3bcd36af9f3fe6d3649910a9adb93e5e988Serge Hallynfi
1897e3bcd36af9f3fe6d3649910a9adb93e5e988Serge Hallyn
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalinconfig_path=$default_path/$name
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalincache=$cache_base/$release/$profile
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalininstall_altlinux
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalinif [ $? -ne 0 ]; then
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin echo "failed to install altlinux"
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin exit 1
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalinfi
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalinconfigure_altlinux
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalinif [ $? -ne 0 ]; then
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin echo "failed to configure altlinux for a container"
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin exit 1
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalinfi
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalincopy_configuration
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalinif [ $? -ne 0 ]; then
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin echo "failed write configuration file"
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin exit 1
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalinfi
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin
4986f1c435636a69193ac90452b10075122d9005Michael Adamif [ ! -z "$clean" ]; then
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin clean || exit 1
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalin exit 0
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalinfi
262f4e48a51a55ad9cee06abbcfe4a6ad6166f49Alexey Shabalinecho "container rootfs and config created"
eba7df9ee0a1963984ef212e7ddfc0e0835af288Stéphane Graberecho "network configured as $lxc_network_type in the $lxc_network_link"