lxc-altlinux.in revision 262f4e48a51a55ad9cee06abbcfe4a6ad6166f49
e02a063b3d675678c3b08075d84f30e665d1d53and#!/bin/bash
e02a063b3d675678c3b08075d84f30e665d1d53and
e02a063b3d675678c3b08075d84f30e665d1d53and#
e02a063b3d675678c3b08075d84f30e665d1d53and# template script for generating altlinux container for LXC
e02a063b3d675678c3b08075d84f30e665d1d53and#
e02a063b3d675678c3b08075d84f30e665d1d53and
e02a063b3d675678c3b08075d84f30e665d1d53and#
e02a063b3d675678c3b08075d84f30e665d1d53and# lxc: linux Container library
e02a063b3d675678c3b08075d84f30e665d1d53and
e02a063b3d675678c3b08075d84f30e665d1d53and# Authors:
0662ed52e814f8f08ef0e09956413a792584eddffuankg# Alexey Shabalin <shaba@altlinux.org>
e02a063b3d675678c3b08075d84f30e665d1d53and
e02a063b3d675678c3b08075d84f30e665d1d53and# This library is free software; you can redistribute it and/or
e02a063b3d675678c3b08075d84f30e665d1d53and# modify it under the terms of the GNU Lesser General Public
e02a063b3d675678c3b08075d84f30e665d1d53and# License as published by the Free Software Foundation; either
e02a063b3d675678c3b08075d84f30e665d1d53and# version 2.1 of the License, or (at your option) any later version.
e02a063b3d675678c3b08075d84f30e665d1d53and
e02a063b3d675678c3b08075d84f30e665d1d53and# This library is distributed in the hope that it will be useful,
16b55a35cff91315d261d1baa776138af465c4e4fuankg# but WITHOUT ANY WARRANTY; without even the implied warranty of
16b55a35cff91315d261d1baa776138af465c4e4fuankg # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
e02a063b3d675678c3b08075d84f30e665d1d53and# Lesser General Public License for more details.
e02a063b3d675678c3b08075d84f30e665d1d53and
b387b9d37fc71c534f4718777454a8f5a1169017fuankg# You should have received a copy of the GNU Lesser General Public
e02a063b3d675678c3b08075d84f30e665d1d53and# License along with this library; if not, write to the Free Software
e02a063b3d675678c3b08075d84f30e665d1d53and# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
e02a063b3d675678c3b08075d84f30e665d1d53and
e02a063b3d675678c3b08075d84f30e665d1d53and#Configurations
e02a063b3d675678c3b08075d84f30e665d1d53andarch=$(arch)
e02a063b3d675678c3b08075d84f30e665d1d53andcache_base=/var/cache/lxc/altlinux/$arch
e02a063b3d675678c3b08075d84f30e665d1d53anddefault_path=/var/lib/lxc
e02a063b3d675678c3b08075d84f30e665d1d53anddefault_profile=default
e02a063b3d675678c3b08075d84f30e665d1d53andprofile_dir=/etc/lxc/profiles
e02a063b3d675678c3b08075d84f30e665d1d53androot_password=rooter
e02a063b3d675678c3b08075d84f30e665d1d53andlxc_network_type=veth
e02a063b3d675678c3b08075d84f30e665d1d53andlxc_network_link=virbr0
e02a063b3d675678c3b08075d84f30e665d1d53and
e02a063b3d675678c3b08075d84f30e665d1d53and# is this altlinux?
e02a063b3d675678c3b08075d84f30e665d1d53and[ -f /etc/altlinux-release ] && is_altlinux=true
e02a063b3d675678c3b08075d84f30e665d1d53and
e02a063b3d675678c3b08075d84f30e665d1d53andconfigure_altlinux()
e02a063b3d675678c3b08075d84f30e665d1d53and{
e02a063b3d675678c3b08075d84f30e665d1d53and
e02a063b3d675678c3b08075d84f30e665d1d53and # disable selinux in altlinux
e02a063b3d675678c3b08075d84f30e665d1d53and mkdir -p $rootfs_path/selinux
e02a063b3d675678c3b08075d84f30e665d1d53and echo 0 > $rootfs_path/selinux/enforce
e02a063b3d675678c3b08075d84f30e665d1d53and
e02a063b3d675678c3b08075d84f30e665d1d53and # configure the network using the dhcp
e02a063b3d675678c3b08075d84f30e665d1d53and mkdir -p ${rootfs_path}/etc/net/ifaces/eth0
e02a063b3d675678c3b08075d84f30e665d1d53and cat <<EOF > ${rootfs_path}/etc/net/ifaces/eth0/options
e02a063b3d675678c3b08075d84f30e665d1d53andBOOTPROTO=dhcp
e02a063b3d675678c3b08075d84f30e665d1d53andONBOOT=yes
e02a063b3d675678c3b08075d84f30e665d1d53andNM_CONTROLLED=no
e02a063b3d675678c3b08075d84f30e665d1d53andTYPE=eth
e02a063b3d675678c3b08075d84f30e665d1d53andEOF
e02a063b3d675678c3b08075d84f30e665d1d53and
e02a063b3d675678c3b08075d84f30e665d1d53and # set the hostname
e02a063b3d675678c3b08075d84f30e665d1d53and cat <<EOF > ${rootfs_path}/etc/sysconfig/network
e02a063b3d675678c3b08075d84f30e665d1d53andNETWORKING=yes
ac7985784d08a3655291f24f711812b4d8b1cbcffuankgCONFMETHOD=etcnet
e02a063b3d675678c3b08075d84f30e665d1d53andHOSTNAME=${UTSNAME}
e02a063b3d675678c3b08075d84f30e665d1d53andRESOLV_MODS=yes
e02a063b3d675678c3b08075d84f30e665d1d53andEOF
e02a063b3d675678c3b08075d84f30e665d1d53and
e02a063b3d675678c3b08075d84f30e665d1d53and # set minimal hosts
e02a063b3d675678c3b08075d84f30e665d1d53and cat <<EOF > $rootfs_path/etc/hosts
e02a063b3d675678c3b08075d84f30e665d1d53and127.0.0.1 localhost.localdomain localhost $name
e02a063b3d675678c3b08075d84f30e665d1d53andEOF
e02a063b3d675678c3b08075d84f30e665d1d53and # Allow to login at virsh console. loginuid.so doen't work in the absence of auditd.
e02a063b3d675678c3b08075d84f30e665d1d53and sed -i 's/^.*loginuid.so.*$/\#&/' ${rootfs_path}/etc/pam.d/common-login
e02a063b3d675678c3b08075d84f30e665d1d53and
e02a063b3d675678c3b08075d84f30e665d1d53and # Allow root to login at virsh console
e02a063b3d675678c3b08075d84f30e665d1d53and echo "pts/0" >> ${rootfs_path}/etc/securetty
ac7985784d08a3655291f24f711812b4d8b1cbcffuankg
e02a063b3d675678c3b08075d84f30e665d1d53and chroot ${rootfs_path} chkconfig network on
e02a063b3d675678c3b08075d84f30e665d1d53and chroot ${rootfs_path} chkconfig syslogd on
e02a063b3d675678c3b08075d84f30e665d1d53and chroot ${rootfs_path} chkconfig random on
e02a063b3d675678c3b08075d84f30e665d1d53and chroot ${rootfs_path} chkconfig rawdevices off
e02a063b3d675678c3b08075d84f30e665d1d53and chroot ${rootfs_path} chkconfig fbsetfont off
e02a063b3d675678c3b08075d84f30e665d1d53and# chroot ${rootfs_path} chkconfig keytable off
e02a063b3d675678c3b08075d84f30e665d1d53and
e02a063b3d675678c3b08075d84f30e665d1d53and subst 's/^\([0-9]\+:[0-9]\+:respawn:\/sbin\/mingetty.*\)/#\1/' ${rootfs_path}/etc/inittab
e02a063b3d675678c3b08075d84f30e665d1d53and subst 's,\/dev\/tty12,/var/log/syslog/console,' ${rootfs_path}/etc/syslog.conf
e02a063b3d675678c3b08075d84f30e665d1d53and
e02a063b3d675678c3b08075d84f30e665d1d53and dev_path="${rootfs_path}/dev"
e02a063b3d675678c3b08075d84f30e665d1d53and rm -rf $dev_path
e02a063b3d675678c3b08075d84f30e665d1d53and mkdir -p $dev_path
e02a063b3d675678c3b08075d84f30e665d1d53and mknod -m 666 ${dev_path}/null c 1 3
e02a063b3d675678c3b08075d84f30e665d1d53and mknod -m 666 ${dev_path}/zero c 1 5
e02a063b3d675678c3b08075d84f30e665d1d53and mknod -m 644 ${dev_path}/random c 1 8
e02a063b3d675678c3b08075d84f30e665d1d53and mknod -m 644 ${dev_path}/urandom c 1 9
e02a063b3d675678c3b08075d84f30e665d1d53and mkdir -m 755 ${dev_path}/pts
e02a063b3d675678c3b08075d84f30e665d1d53and mkdir -m 1777 ${dev_path}/shm
e02a063b3d675678c3b08075d84f30e665d1d53and mknod -m 666 ${dev_path}/tty c 5 0
e02a063b3d675678c3b08075d84f30e665d1d53and mknod -m 666 ${dev_path}/tty0 c 4 0
ac7985784d08a3655291f24f711812b4d8b1cbcffuankg mknod -m 666 ${dev_path}/tty1 c 4 1
e02a063b3d675678c3b08075d84f30e665d1d53and mknod -m 666 ${dev_path}/tty2 c 4 2
e02a063b3d675678c3b08075d84f30e665d1d53and mknod -m 666 ${dev_path}/tty3 c 4 3
ac7985784d08a3655291f24f711812b4d8b1cbcffuankg mknod -m 666 ${dev_path}/tty4 c 4 4
e02a063b3d675678c3b08075d84f30e665d1d53and mknod -m 600 ${dev_path}/console c 5 1
e02a063b3d675678c3b08075d84f30e665d1d53and mknod -m 666 ${dev_path}/full c 1 7
e02a063b3d675678c3b08075d84f30e665d1d53and mknod -m 600 ${dev_path}/initctl p
e02a063b3d675678c3b08075d84f30e665d1d53and mknod -m 666 ${dev_path}/ptmx c 5 2
e02a063b3d675678c3b08075d84f30e665d1d53and
e02a063b3d675678c3b08075d84f30e665d1d53and echo "setting root passwd to $root_password"
e02a063b3d675678c3b08075d84f30e665d1d53and echo "root:$root_password" | chroot $rootfs_path chpasswd
e02a063b3d675678c3b08075d84f30e665d1d53and
e02a063b3d675678c3b08075d84f30e665d1d53and return 0
e02a063b3d675678c3b08075d84f30e665d1d53and}
e02a063b3d675678c3b08075d84f30e665d1d53and
ac7985784d08a3655291f24f711812b4d8b1cbcffuankgdownload_altlinux()
0662ed52e814f8f08ef0e09956413a792584eddffuankg{
e02a063b3d675678c3b08075d84f30e665d1d53and
ac7985784d08a3655291f24f711812b4d8b1cbcffuankg # check the mini altlinux was not already downloaded
e02a063b3d675678c3b08075d84f30e665d1d53and INSTALL_ROOT=$cache/partial
e02a063b3d675678c3b08075d84f30e665d1d53and mkdir -p $INSTALL_ROOT
e02a063b3d675678c3b08075d84f30e665d1d53and if [ $? -ne 0 ]; then
e02a063b3d675678c3b08075d84f30e665d1d53and echo "Failed to create '$INSTALL_ROOT' directory"
e02a063b3d675678c3b08075d84f30e665d1d53and return 1
e02a063b3d675678c3b08075d84f30e665d1d53and fi
e02a063b3d675678c3b08075d84f30e665d1d53and
e02a063b3d675678c3b08075d84f30e665d1d53and # download a mini altlinux into a cache
e02a063b3d675678c3b08075d84f30e665d1d53and echo "Downloading altlinux minimal ..."
e02a063b3d675678c3b08075d84f30e665d1d53and APT_GET="apt-get -o RPM::RootDir=$INSTALL_ROOT -y"
0662ed52e814f8f08ef0e09956413a792584eddffuankg PKG_LIST="$(grep -hs '^[^#]' "$profile_dir/$profile")"
e02a063b3d675678c3b08075d84f30e665d1d53and# PKG_LIST="basesystem apt apt-conf-sisyphus etcnet openssh-server passwd sysklogd net-tools e2fsprogs"
e02a063b3d675678c3b08075d84f30e665d1d53and
e02a063b3d675678c3b08075d84f30e665d1d53and mkdir -p $INSTALL_ROOT/var/lib/rpm
e02a063b3d675678c3b08075d84f30e665d1d53and rpm --root $INSTALL_ROOT --initdb
0662ed52e814f8f08ef0e09956413a792584eddffuankg $APT_GET install $PKG_LIST
e02a063b3d675678c3b08075d84f30e665d1d53and
e02a063b3d675678c3b08075d84f30e665d1d53and if [ $? -ne 0 ]; then
e02a063b3d675678c3b08075d84f30e665d1d53and echo "Failed to download the rootfs, aborting."
e02a063b3d675678c3b08075d84f30e665d1d53and return 1
e02a063b3d675678c3b08075d84f30e665d1d53and fi
e02a063b3d675678c3b08075d84f30e665d1d53and
e02a063b3d675678c3b08075d84f30e665d1d53and mv "$INSTALL_ROOT" "$cache/rootfs"
e02a063b3d675678c3b08075d84f30e665d1d53and echo "Download complete."
e02a063b3d675678c3b08075d84f30e665d1d53and
0662ed52e814f8f08ef0e09956413a792584eddffuankg return 0
e02a063b3d675678c3b08075d84f30e665d1d53and}
e02a063b3d675678c3b08075d84f30e665d1d53and
ac7985784d08a3655291f24f711812b4d8b1cbcffuankgcopy_altlinux()
e02a063b3d675678c3b08075d84f30e665d1d53and{
e02a063b3d675678c3b08075d84f30e665d1d53and
e02a063b3d675678c3b08075d84f30e665d1d53and # make a local copy of the minialtlinux
ac7985784d08a3655291f24f711812b4d8b1cbcffuankg echo -n "Copying rootfs to $rootfs_path ..."
e02a063b3d675678c3b08075d84f30e665d1d53and #cp -a $cache/rootfs-$arch $rootfs_path || return 1
e02a063b3d675678c3b08075d84f30e665d1d53and # i prefer rsync (no reason really)
e02a063b3d675678c3b08075d84f30e665d1d53and mkdir -p $rootfs_path
e02a063b3d675678c3b08075d84f30e665d1d53and rsync -a $cache/rootfs/ $rootfs_path/
e02a063b3d675678c3b08075d84f30e665d1d53and return 0
e02a063b3d675678c3b08075d84f30e665d1d53and}
e02a063b3d675678c3b08075d84f30e665d1d53and
e02a063b3d675678c3b08075d84f30e665d1d53andupdate_altlinux()
e02a063b3d675678c3b08075d84f30e665d1d53and{
e02a063b3d675678c3b08075d84f30e665d1d53and chroot $cache/rootfs apt-get update
e02a063b3d675678c3b08075d84f30e665d1d53and chroot $cache/rootfs apt-get -y dist-upgrade
e02a063b3d675678c3b08075d84f30e665d1d53and}
e02a063b3d675678c3b08075d84f30e665d1d53and
e02a063b3d675678c3b08075d84f30e665d1d53andinstall_altlinux()
e02a063b3d675678c3b08075d84f30e665d1d53and{
e02a063b3d675678c3b08075d84f30e665d1d53and mkdir -p /var/lock/subsys/
e02a063b3d675678c3b08075d84f30e665d1d53and (
e02a063b3d675678c3b08075d84f30e665d1d53and flock -n -x 200
e02a063b3d675678c3b08075d84f30e665d1d53and if [ $? -ne 0 ]; then
e02a063b3d675678c3b08075d84f30e665d1d53and echo "Cache repository is busy."
e02a063b3d675678c3b08075d84f30e665d1d53and return 1
e02a063b3d675678c3b08075d84f30e665d1d53and fi
e02a063b3d675678c3b08075d84f30e665d1d53and
e02a063b3d675678c3b08075d84f30e665d1d53and echo "Checking cache download in $cache/rootfs ... "
e02a063b3d675678c3b08075d84f30e665d1d53and if [ ! -e "$cache/rootfs" ]; then
e02a063b3d675678c3b08075d84f30e665d1d53and download_altlinux
e02a063b3d675678c3b08075d84f30e665d1d53and if [ $? -ne 0 ]; then
cf7ca2f9eaa6523fefcccba4287b91637391fb51fuankg echo "Failed to download 'altlinux base'"
e02a063b3d675678c3b08075d84f30e665d1d53and return 1
e02a063b3d675678c3b08075d84f30e665d1d53and fi
e02a063b3d675678c3b08075d84f30e665d1d53and else
e02a063b3d675678c3b08075d84f30e665d1d53and echo "Cache found. Updating..."
e02a063b3d675678c3b08075d84f30e665d1d53and update_altlinux
e02a063b3d675678c3b08075d84f30e665d1d53and if [ $? -ne 0 ]; then
e02a063b3d675678c3b08075d84f30e665d1d53and echo "Failed to update 'altlinux base', continuing with last known good cache"
e02a063b3d675678c3b08075d84f30e665d1d53and else
e02a063b3d675678c3b08075d84f30e665d1d53and echo "Update finished"
e02a063b3d675678c3b08075d84f30e665d1d53and fi
e02a063b3d675678c3b08075d84f30e665d1d53and fi
e02a063b3d675678c3b08075d84f30e665d1d53and
e02a063b3d675678c3b08075d84f30e665d1d53and echo "Copy $cache/rootfs to $rootfs_path ... "
e02a063b3d675678c3b08075d84f30e665d1d53and copy_altlinux
e02a063b3d675678c3b08075d84f30e665d1d53and if [ $? -ne 0 ]; then
ac7985784d08a3655291f24f711812b4d8b1cbcffuankg echo "Failed to copy rootfs"
e02a063b3d675678c3b08075d84f30e665d1d53and return 1
e02a063b3d675678c3b08075d84f30e665d1d53and fi
e02a063b3d675678c3b08075d84f30e665d1d53and
e02a063b3d675678c3b08075d84f30e665d1d53and return 0
e02a063b3d675678c3b08075d84f30e665d1d53and
e02a063b3d675678c3b08075d84f30e665d1d53and ) 200>/var/lock/subsys/lxc
e02a063b3d675678c3b08075d84f30e665d1d53and
e02a063b3d675678c3b08075d84f30e665d1d53and return $?
e02a063b3d675678c3b08075d84f30e665d1d53and}
e02a063b3d675678c3b08075d84f30e665d1d53and
e02a063b3d675678c3b08075d84f30e665d1d53andcopy_configuration()
e02a063b3d675678c3b08075d84f30e665d1d53and{
e02a063b3d675678c3b08075d84f30e665d1d53and
e02a063b3d675678c3b08075d84f30e665d1d53and mkdir -p $config_path
8ffac2c334103c0336602aaede650cb578611151fuankg cat <<EOF >> $config_path/config
8ffac2c334103c0336602aaede650cb578611151fuankglxc.utsname = $name
e02a063b3d675678c3b08075d84f30e665d1d53andlxc.tty = 4
e02a063b3d675678c3b08075d84f30e665d1d53andlxc.pts = 1024
ac7985784d08a3655291f24f711812b4d8b1cbcffuankglxc.rootfs = $rootfs_path
ac7985784d08a3655291f24f711812b4d8b1cbcffuankglxc.mount = $config_path/fstab
e02a063b3d675678c3b08075d84f30e665d1d53and#networking
e02a063b3d675678c3b08075d84f30e665d1d53andlxc.network.type = $lxc_network_type
e02a063b3d675678c3b08075d84f30e665d1d53andlxc.network.flags = up
e02a063b3d675678c3b08075d84f30e665d1d53andlxc.network.link = $lxc_network_link
e02a063b3d675678c3b08075d84f30e665d1d53andlxc.network.name = eth0
ac7985784d08a3655291f24f711812b4d8b1cbcffuankglxc.network.mtu = 1500
ac7985784d08a3655291f24f711812b4d8b1cbcffuankg#cgroups
e02a063b3d675678c3b08075d84f30e665d1d53andlxc.cgroup.devices.deny = a
e02a063b3d675678c3b08075d84f30e665d1d53and# /dev/null and zero
e02a063b3d675678c3b08075d84f30e665d1d53andlxc.cgroup.devices.allow = c 1:3 rwm
e02a063b3d675678c3b08075d84f30e665d1d53andlxc.cgroup.devices.allow = c 1:5 rwm
ac7985784d08a3655291f24f711812b4d8b1cbcffuankg# consoles
e02a063b3d675678c3b08075d84f30e665d1d53andlxc.cgroup.devices.allow = c 5:1 rwm
e02a063b3d675678c3b08075d84f30e665d1d53andlxc.cgroup.devices.allow = c 5:0 rwm
e02a063b3d675678c3b08075d84f30e665d1d53andlxc.cgroup.devices.allow = c 4:0 rwm
e02a063b3d675678c3b08075d84f30e665d1d53andlxc.cgroup.devices.allow = c 4:1 rwm
e02a063b3d675678c3b08075d84f30e665d1d53and# /dev/{,u}random
e02a063b3d675678c3b08075d84f30e665d1d53andlxc.cgroup.devices.allow = c 1:9 rwm
e02a063b3d675678c3b08075d84f30e665d1d53andlxc.cgroup.devices.allow = c 1:8 rwm
e02a063b3d675678c3b08075d84f30e665d1d53andlxc.cgroup.devices.allow = c 136:* rwm
e02a063b3d675678c3b08075d84f30e665d1d53andlxc.cgroup.devices.allow = c 5:2 rwm
e02a063b3d675678c3b08075d84f30e665d1d53and# rtc
ac7985784d08a3655291f24f711812b4d8b1cbcffuankglxc.cgroup.devices.allow = c 254:0 rwm
0662ed52e814f8f08ef0e09956413a792584eddffuankgEOF
e02a063b3d675678c3b08075d84f30e665d1d53and
e02a063b3d675678c3b08075d84f30e665d1d53and cat <<EOF > $config_path/fstab
e02a063b3d675678c3b08075d84f30e665d1d53andproc $rootfs_path/proc proc nodev,noexec,nosuid 0 0
e02a063b3d675678c3b08075d84f30e665d1d53anddevpts $rootfs_path/dev/pts devpts defaults 0 0
e02a063b3d675678c3b08075d84f30e665d1d53andsysfs $rootfs_path/sys sysfs defaults 0 0
e02a063b3d675678c3b08075d84f30e665d1d53andEOF
e02a063b3d675678c3b08075d84f30e665d1d53and
e02a063b3d675678c3b08075d84f30e665d1d53and if [ $? -ne 0 ]; then
e02a063b3d675678c3b08075d84f30e665d1d53and echo "Failed to add configuration"
e02a063b3d675678c3b08075d84f30e665d1d53and return 1
e02a063b3d675678c3b08075d84f30e665d1d53and fi
e02a063b3d675678c3b08075d84f30e665d1d53and
0662ed52e814f8f08ef0e09956413a792584eddffuankg return 0
e02a063b3d675678c3b08075d84f30e665d1d53and}
ac7985784d08a3655291f24f711812b4d8b1cbcffuankg
clean()
{
if [ ! -e $cache ]; then
exit 0
fi
# lock, so we won't purge while someone is creating a repository
(
flock -n -x 200
if [ $? != 0 ]; then
echo "Cache repository is busy."
exit 1
fi
echo -n "Purging the download cache for ALTLinux-$release..."
rm --preserve-root --one-file-system -rf $cache && echo "Done." || exit 1
exit 0
) 200>/var/lock/subsys/lxc
}
usage()
{
cat <<EOF
usage:
$1 -n|--name=<container_name>
[-p|--path=<path>] [-c|--clean] [-R|--release=<ALTLinux_release>]
[-P|--profile=<name of the profile>]
[-A|--arch=<arch of the container>]
[-h|--help]
Mandatory args:
-n,--name container name, used to as an identifier for that container from now on
Optional args:
-p,--path path to where the container rootfs will be created, defaults to /var/lib/lxc. The container config will go under /var/lib/lxc in and case
-c,--clean clean the cache
-R,--release ALTLinux release for the new container. if the host is ALTLinux, then it will defaultto the host's release.
-P,--profile Profile name is the file name in /etc/lxc/profiles contained packages name for install to cache.
-A,--arch NOT USED YET. Define what arch the container will be [i686,x86_64]
-h,--help print this help
EOF
return 0
}
options=$(getopt -o hp:n:P:cR: -l help,path:,name:,profile:,clean,release: -- "$@")
if [ $? -ne 0 ]; then
usage $(basename $0)
exit 1
fi
eval set -- "$options"
while true
do
case "$1" in
-h|--help) usage $0 && exit 0;;
-p|--path) path=$2; shift 2;;
-n|--name) name=$2; shift 2;;
-P|--profile) profile=$2; shift 2;;
-c|--clean) clean=$2; shift 2;;
-R|--release) release=$2; shift 2;;
--) shift 1; break ;;
*) break ;;
esac
done
if [ ! -z "$clean" -a -z "$path" ]; then
clean || exit 1
exit 0
fi
type apt-get >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "'apt-get' command is missing"
exit 1
fi
if [ -z "$path" ]; then
path=$default_path
fi
if [ -z "$profile" ]; then
profile=$default_profile
fi
if [ -z "$release" ]; then
if [ "$is_altlinux" ]; then
release=$(cat /etc/altlinux-release |awk '/^ALT/ {print $3}')
else
echo "This is not a ALTLinux host and release missing, use -R|--release to specify release"
exit 1
fi
fi
if [ "$(id -u)" != "0" ]; then
echo "This script should be run as 'root'"
exit 1
fi
rootfs_path=$path/$name/rootfs
config_path=$default_path/$name
cache=$cache_base/$release/$profile
if [ -f $config_path/config ]; then
echo "A container with that name exists, chose a different name"
exit 1
fi
install_altlinux
if [ $? -ne 0 ]; then
echo "failed to install altlinux"
exit 1
fi
configure_altlinux
if [ $? -ne 0 ]; then
echo "failed to configure altlinux for a container"
exit 1
fi
copy_configuration
if [ $? -ne 0 ]; then
echo "failed write configuration file"
exit 1
fi
if [ ! -z $clean ]; then
clean || exit 1
exit 0
fi
echo "container rootfs and config created"
echo "container is configured for lxc.network.type=veth and lxc.network.link=virbr0 (which is default if you have libvirt runnig)"