lxc-plamo.in revision f24a52d5f588ff4e4575046903fb9498c376d833
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher#!/bin/bash -eu
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher#
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher# template script for generating Plamo Linux container for LXC
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher#
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher#
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher# lxc: linux Container library
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher# Authors:
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher# KATOH Yasufumi <karma@jazz.email.ne.jp>
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher# TAMUKI Shoichi <tamuki@linet.gr.jp>
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher# This library is free software; you can redistribute it and/or
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher# modify it under the terms of the GNU Lesser General Public
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher# License as published by the Free Software Foundation; either
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher# version 2.1 of the License, or (at your option) any later version.
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher# This library is distributed in the hope that it will be useful,
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher# but WITHOUT ANY WARRANTY; without even the implied warranty of
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher# Lesser General Public License for more details.
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher# You should have received a copy of the GNU Lesser General Public
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher# License along with this library; if not, write to the Free Software
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher# ref. https://github.com/Ponce/lxc-slackware/blob/master/lxc-slackware
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher# lxc-ubuntu script
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher# Detect use under userns (unsupported)
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagherfor arg in "$@"; do
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher [ "$arg" = "--" ] && break
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher if [ "$arg" = "--mapped-uid" -o "$arg" = "--mapped-gid" ]; then
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher echo "This template can't be used for unprivileged containers." 1>&2
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher echo "You may want to try the \"download\" template instead." 1>&2
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher exit 1
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher fi
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagherdone
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose# Make sure the usual locations are in PATH
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Boseexport PATH=$PATH:/usr/sbin:/usr/bin:/sbin:/bin
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose[ -r /etc/default/lxc ] && . /etc/default/lxc
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose
949fbc93defad394648b2651b43a7bbfa5bff42bSumit BoseDLSCHEME=${DLSCHEME:-"http"}
949fbc93defad394648b2651b43a7bbfa5bff42bSumit BoseMIRRORSRV=${MIRRORSRV:-"www.ring.gr.jp"}
949fbc93defad394648b2651b43a7bbfa5bff42bSumit BoseMIRRORPATH=${MIRRORPATH:-"/pub/linux/Plamo"}
949fbc93defad394648b2651b43a7bbfa5bff42bSumit BoseCATEGORIES=${CATEGORIES-"00_base 01_minimum"}
949fbc93defad394648b2651b43a7bbfa5bff42bSumit BoseEXTRACTGRS=${EXTRACTGRS-""}
949fbc93defad394648b2651b43a7bbfa5bff42bSumit BoseIGNOREPKGS=${IGNOREPKGS-"grub kernel lilo linux_firmware microcode_ctl
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose cpufreqd cpufrequtils gpm"}
949fbc93defad394648b2651b43a7bbfa5bff42bSumit BoseADDONPKGS=${ADDONPKGS-"`echo contrib/Hamradio/{morse,qrq}`"}
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bosedownload_plamo() {
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose # check the mini plamo was not already downloaded
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose if ! mkdir -p $ptcache ; then
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose echo "Failed to create '$ptcache' directory."
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose return 1
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose fi
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose # download a mini plamo into a cache
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose echo "Downloading Plamo-$release minimal..."
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose cd $ptcache
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose case $DLSCHEME in http) depth=2 ;; ftp) depth=3 ;; esac
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose rej=${IGNOREPKGS%% *} ; [ -n "$rej" ] && rej="$rej-*"
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose if [ `echo $IGNOREPKGS | wc -w` -gt 1 ] ; then
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose for p in ${IGNOREPKGS#* } ; do rej="$rej,$p-*" ; done
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose fi
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose for i in $CATEGORIES ; do
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose wget -nv -e robots=off -r -l $depth -nd -A .tgz,.txz -R "$rej" \
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose -I $MIRRORPATH/Plamo-$release/$arch/plamo/$i \
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose -X $MIRRORPATH/Plamo-$release/$arch/plamo/$i/old \
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose $DLSCHEME://$MIRRORSRV$MIRRORPATH/Plamo-$release/$arch/plamo/$i
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose if [ $? -ne 0 ] ; then
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose echo "Failed to download the rootfs, aborting."
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose return 1
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose fi
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose done
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose for i in $EXTRACTGRS ; do
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose wget -nv -e robots=off -r -l $depth -nd -A .tgz,.txz -R "$rej" \
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose -I $MIRRORPATH/Plamo-$release/$arch/contrib/$i \
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose -X $MIRRORPATH/Plamo-$release/$arch/contrib/$i/old \
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose $DLSCHEME://$MIRRORSRV$MIRRORPATH/Plamo-$release/$arch/contrib/$i
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose if [ $? -ne 0 ] ; then
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose echo "Failed to download the rootfs, aborting."
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose return 1
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose fi
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose done
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose for p in $ADDONPKGS ; do
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose wget -nv -e robots=off -r -l $depth -nd -A "`basename $p`-*" \
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose -I $MIRRORPATH/Plamo-$release/$arch/`dirname $p` \
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose -X $MIRRORPATH/Plamo-$release/$arch/`dirname $p`/old \
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose $DLSCHEME://$MIRRORSRV$MIRRORPATH/Plamo-$release/$arch/`dirname $p`
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose if [ $? -ne 0 ] ; then
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose echo "Failed to download the rootfs, aborting."
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose return 1
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose fi
bfb40893be20b45279a40188cf16ef0eec1f9423Sumit Bose done
bfb40893be20b45279a40188cf16ef0eec1f9423Sumit Bose mv $ptcache $dlcache
bfb40893be20b45279a40188cf16ef0eec1f9423Sumit Bose echo "Download complete."
bfb40893be20b45279a40188cf16ef0eec1f9423Sumit Bose return 0
bfb40893be20b45279a40188cf16ef0eec1f9423Sumit Bose}
bfb40893be20b45279a40188cf16ef0eec1f9423Sumit Bose
bfb40893be20b45279a40188cf16ef0eec1f9423Sumit Bosecopy_plamo() {
bfb40893be20b45279a40188cf16ef0eec1f9423Sumit Bose # make a local copy of the mini plamo
bfb40893be20b45279a40188cf16ef0eec1f9423Sumit Bose echo "Copying $rtcache to $rootfs..."
bfb40893be20b45279a40188cf16ef0eec1f9423Sumit Bose mkdir -p $rootfs
bfb40893be20b45279a40188cf16ef0eec1f9423Sumit Bose find $rtcache -mindepth 1 -maxdepth 1 -exec cp -a {} $rootfs \; || return 1
bfb40893be20b45279a40188cf16ef0eec1f9423Sumit Bose return 0
bfb40893be20b45279a40188cf16ef0eec1f9423Sumit Bose}
bfb40893be20b45279a40188cf16ef0eec1f9423Sumit Bose
bfb40893be20b45279a40188cf16ef0eec1f9423Sumit Boseinstall_plamo() {
bfb40893be20b45279a40188cf16ef0eec1f9423Sumit Bose mkdir -p @LOCALSTATEDIR@/lock/subsys
bfb40893be20b45279a40188cf16ef0eec1f9423Sumit Bose (
bfb40893be20b45279a40188cf16ef0eec1f9423Sumit Bose if ! flock -n 9 ; then
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher echo "Cache repository is busy."
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher return 1
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher fi
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher echo "Checking cache download in $dlcache..."
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher if [ ! -d $dlcache ] ; then
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher if ! download_plamo ; then
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher echo "Failed to download plamo $release base packages."
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher return 1
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher fi
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher fi
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher # install "installpkg" command temporarily with static linked tar
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher # command into the lxc cache directory to keep the original uid/
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher # gid of files/directories.
46222e5191473f9a46aec581273eb2eef22e23beMichal Zidek echo "Installing 'installpkg' command into $dlcache/sbin..."
46222e5191473f9a46aec581273eb2eef22e23beMichal Zidek ( cd $dlcache ; tar xpJf hdsetup-*.txz ; rm -rf tmp usr var )
46222e5191473f9a46aec581273eb2eef22e23beMichal Zidek sed -i "/ldconfig/!s@/sbin@$dlcache&@g" $dlcache/sbin/installpkg*
46222e5191473f9a46aec581273eb2eef22e23beMichal Zidek PATH=$dlcache/sbin:$PATH
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher echo "Installing packages to $rtcache..."
df0596ec12bc5091608371e2977f3111241e8cafSimo Sorce if [ ! -d $rtcache ] ; then
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher mkdir -p $rtcache
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher for p in `ls -cr $dlcache/*.t?z` ; do
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher installpkg -root $rtcache -priority ADD $p
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher done
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher fi
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher echo "Copy $rtcache to $rootfs..."
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher if ! copy_plamo ; then
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher echo "Failed to copy rootfs."
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher return 1
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher fi
bfb40893be20b45279a40188cf16ef0eec1f9423Sumit Bose return 0
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher ) 9> @LOCALSTATEDIR@/lock/subsys/lxc-plamo
46222e5191473f9a46aec581273eb2eef22e23beMichal Zidek}
46222e5191473f9a46aec581273eb2eef22e23beMichal Zidek
46222e5191473f9a46aec581273eb2eef22e23beMichal Zidekconfigure_plamo() {
46222e5191473f9a46aec581273eb2eef22e23beMichal Zidek # create /dev
46222e5191473f9a46aec581273eb2eef22e23beMichal Zidek chmod 666 $rootfs/dev/null
46222e5191473f9a46aec581273eb2eef22e23beMichal Zidek mknod -m 666 $rootfs/dev/zero c 1 5
46222e5191473f9a46aec581273eb2eef22e23beMichal Zidek chmod 666 $rootfs/dev/random
46222e5191473f9a46aec581273eb2eef22e23beMichal Zidek mknod -m 666 $rootfs/dev/urandom c 1 9
46222e5191473f9a46aec581273eb2eef22e23beMichal Zidek mkdir -m 755 $rootfs/dev/pts
46222e5191473f9a46aec581273eb2eef22e23beMichal Zidek mkdir -m 755 $rootfs/dev/shm
46222e5191473f9a46aec581273eb2eef22e23beMichal Zidek chmod 666 $rootfs/dev/tty
46222e5191473f9a46aec581273eb2eef22e23beMichal Zidek chmod 600 $rootfs/dev/console
46222e5191473f9a46aec581273eb2eef22e23beMichal Zidek mknod -m 666 $rootfs/dev/tty0 c 4 0
46222e5191473f9a46aec581273eb2eef22e23beMichal Zidek mknod -m 666 $rootfs/dev/tty1 c 4 1
bfdb2eeed95bde6cd065a9a47a7cb1773990ccfbOndrej Kos mknod -m 666 $rootfs/dev/tty2 c 4 2
46222e5191473f9a46aec581273eb2eef22e23beMichal Zidek mknod -m 666 $rootfs/dev/tty3 c 4 3
46222e5191473f9a46aec581273eb2eef22e23beMichal Zidek mknod -m 666 $rootfs/dev/tty4 c 4 4
46222e5191473f9a46aec581273eb2eef22e23beMichal Zidek mknod -m 666 $rootfs/dev/full c 1 7
bfdb2eeed95bde6cd065a9a47a7cb1773990ccfbOndrej Kos mknod -m 600 $rootfs/dev/initctl p
46222e5191473f9a46aec581273eb2eef22e23beMichal Zidek mknod -m 666 $rootfs/dev/ptmx c 5 2
46222e5191473f9a46aec581273eb2eef22e23beMichal Zidek # suppress log level output for udev
46222e5191473f9a46aec581273eb2eef22e23beMichal Zidek sed -i 's/="err"/=0/' $rootfs/etc/udev/udev.conf
46222e5191473f9a46aec581273eb2eef22e23beMichal Zidek # /etc/fstab
46222e5191473f9a46aec581273eb2eef22e23beMichal Zidek cat <<- "EOF" > $rootfs/etc/fstab
46222e5191473f9a46aec581273eb2eef22e23beMichal Zidek none /proc proc defaults 0 0
46222e5191473f9a46aec581273eb2eef22e23beMichal Zidek none /sys sysfs defaults 0 0
46222e5191473f9a46aec581273eb2eef22e23beMichal Zidek none /dev tmpfs defaults 0 0
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher none /tmp tmpfs defaults 0 0
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher none /dev/pts devpts gid=5,mode=620 0 0
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher none /proc/bus/usb usbfs noauto 0 0
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher none /var/lib/nfs/rpc_pipefs rpc_pipefs defaults 0 0
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher EOF
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher # /etc/inittab
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher cat <<- "EOF" | patch $rootfs/etc/inittab
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher 32,33c32,33
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher < # What to do when power fails (shutdown to single user).
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher < pf::powerfail:/sbin/shutdown -f +5 "THE POWER IS FAILING"
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher ---
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher > # What to do when power fails (shutdown).
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher > pf::powerfail:/sbin/shutdown -h +0 "THE POWER IS FAILING"
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher 47a48
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher > 1:1235:respawn:/sbin/agetty 38400 console
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher 52,53d52
46222e5191473f9a46aec581273eb2eef22e23beMichal Zidek < c5:1235:respawn:/sbin/agetty 38400 tty5 linux
46222e5191473f9a46aec581273eb2eef22e23beMichal Zidek < c6:12345:respawn:/sbin/agetty 38400 tty6 linux
46222e5191473f9a46aec581273eb2eef22e23beMichal Zidek EOF
46222e5191473f9a46aec581273eb2eef22e23beMichal Zidek # set the hostname
46222e5191473f9a46aec581273eb2eef22e23beMichal Zidek echo "$name" > $rootfs/etc/HOSTNAME
46222e5191473f9a46aec581273eb2eef22e23beMichal Zidek # set minimal hosts
46222e5191473f9a46aec581273eb2eef22e23beMichal Zidek echo "127.0.0.1 localhost $name" > $rootfs/etc/hosts
46222e5191473f9a46aec581273eb2eef22e23beMichal Zidek # configure the network using the dhcp
46222e5191473f9a46aec581273eb2eef22e23beMichal Zidek echo "DHCP" > $rootfs/var/run/inet1-scheme
46222e5191473f9a46aec581273eb2eef22e23beMichal Zidek # localtime (JST)
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose ln -s ../usr/share/zoneinfo/Asia/Tokyo $rootfs/etc/localtime
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose # disable pam_loginuid.so in /etc/pam.d/login (for libvirt's lxc driver)
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose sed -i '/pam_loginuid/s/^/#/' $rootfs/etc/pam.d/login
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose # glibc configure
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose mv $rootfs/etc/ld.so.conf{.new,}
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose chroot $rootfs ldconfig
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose # root password
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose echo "Setting root password to 'root'..."
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose echo "root:root" | chroot $rootfs chpasswd
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose echo "Please change root password!"
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose # /etc/rc.d/rc.S
949fbc93defad394648b2651b43a7bbfa5bff42bSumit Bose ed - $rootfs/etc/rc.d/rc.S <<- "EOF"
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher /^mount -w -n -t proc/;/^# ln -s \/bin\/true/-1d
9a7b6d3248c5aac460e164f2246b26131cfbc055Simo Sorce /^mknod \/dev\/unikey/;/^# Clean \/etc\/mtab/-2d
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher /^# copy the rules/;/^# Set the hostname/-1d
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher /^# Check the integrity/;/^# Clean up temporary/-1d
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher w
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher EOF
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher # /etc/rc.d/rc.M
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher ed - $rootfs/etc/rc.d/rc.M <<- "EOF"
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher /^# Screen blanks/;/^# Initialize ip6tables/-1d
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher /^# Initialize sysctl/;/^echo "Starting services/-1d
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher /^sync/;/^# All done/-1d
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher w
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher EOF
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher # /etc/rc.d/rc.inet1.tradnet
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher head -n-93 $rootfs/sbin/netconfig.tradnet > /tmp/netconfig.rconly
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher cat <<- EOF >> /tmp/netconfig.rconly
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher PCMCIA=n
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher RC=$rootfs/etc/rc.d/rc.inet1.tradnet
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher IFCONFIG=sbin/ifconfig
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher ROUTE=sbin/route
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher INET1SCHEME=var/run/inet1-scheme
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher IPADDR=127.0.0.1
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher NETWORK=127.0.0.0
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher DHCPCD=usr/sbin/dhclient
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher LOOPBACK=y
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher make_config_file
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher EOF
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher rm -f $rootfs/etc/rc.d/rc.inet1.tradnet
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher sh /tmp/netconfig.rconly
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher rm -f /tmp/netconfig.rconly
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher sed -i '/cmdline/s/if/& false \&\&/' $rootfs/etc/rc.d/rc.inet1.tradnet
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher return 0
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher}
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallaghercopy_configuration() {
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher ret=0
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher cat <<- EOF >> $path/config || let ret++
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher lxc.utsname = $name
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher lxc.arch = $arch
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher EOF
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher if [ -f "@LXCTEMPLATECONFIG@/plamo.common.conf" ] ; then
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher cat <<- "EOF" >> $path/config || let ret++
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher lxc.include = @LXCTEMPLATECONFIG@/plamo.common.conf
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher EOF
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher fi
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher if [ $ret -ne 0 ] ; then
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher echo "Failed to add configuration."
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher return 1
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher fi
4f3fd1fb264a7eaf3a9d062d49e071b0d17e4debStephen Gallagher return 0
4f3fd1fb264a7eaf3a9d062d49e071b0d17e4debStephen Gallagher}
4f3fd1fb264a7eaf3a9d062d49e071b0d17e4debStephen Gallagher
4f3fd1fb264a7eaf3a9d062d49e071b0d17e4debStephen Gallagherpost_process() {
4f3fd1fb264a7eaf3a9d062d49e071b0d17e4debStephen Gallagher # nothing do in Plamo Linux
4f3fd1fb264a7eaf3a9d062d49e071b0d17e4debStephen Gallagher true
4f3fd1fb264a7eaf3a9d062d49e071b0d17e4debStephen Gallagher}
4f3fd1fb264a7eaf3a9d062d49e071b0d17e4debStephen Gallagher
4f3fd1fb264a7eaf3a9d062d49e071b0d17e4debStephen Gallagherdo_bindhome() {
4f3fd1fb264a7eaf3a9d062d49e071b0d17e4debStephen Gallagher # bind-mount the user's path into the container's /home
4f3fd1fb264a7eaf3a9d062d49e071b0d17e4debStephen Gallagher h=`getent passwd $bindhome | cut -d: -f6`
4f3fd1fb264a7eaf3a9d062d49e071b0d17e4debStephen Gallagher mkdir -p $rootfs/$h
4f3fd1fb264a7eaf3a9d062d49e071b0d17e4debStephen Gallagher echo "lxc.mount.entry = $h $rootfs/$h none bind 0 0" >> $path/config
4f3fd1fb264a7eaf3a9d062d49e071b0d17e4debStephen Gallagher # copy /etc/passwd, /etc/shadow, and /etc/group entries into container
4f3fd1fb264a7eaf3a9d062d49e071b0d17e4debStephen Gallagher if ! pwd=`getent passwd $bindhome` ; then
4f3fd1fb264a7eaf3a9d062d49e071b0d17e4debStephen Gallagher echo "Warning: failed to copy password entry for $bindhome."
4f3fd1fb264a7eaf3a9d062d49e071b0d17e4debStephen Gallagher else
4f3fd1fb264a7eaf3a9d062d49e071b0d17e4debStephen Gallagher echo $pwd >> $rootfs/etc/passwd
4f3fd1fb264a7eaf3a9d062d49e071b0d17e4debStephen Gallagher fi
4f3fd1fb264a7eaf3a9d062d49e071b0d17e4debStephen Gallagher echo `getent shadow $bindhome` >> $rootfs/etc/shadow
4f3fd1fb264a7eaf3a9d062d49e071b0d17e4debStephen Gallagher}
4f3fd1fb264a7eaf3a9d062d49e071b0d17e4debStephen Gallagher
4f3fd1fb264a7eaf3a9d062d49e071b0d17e4debStephen Gallaghercleanup() {
4f3fd1fb264a7eaf3a9d062d49e071b0d17e4debStephen Gallagher [ -d $dlcache -a -d $rtcache ] || return 0
4f3fd1fb264a7eaf3a9d062d49e071b0d17e4debStephen Gallagher # lock, so we won't purge while someone is creating a repository
4f3fd1fb264a7eaf3a9d062d49e071b0d17e4debStephen Gallagher (
4f3fd1fb264a7eaf3a9d062d49e071b0d17e4debStephen Gallagher if ! flock -n 9 ; then
4f3fd1fb264a7eaf3a9d062d49e071b0d17e4debStephen Gallagher echo "Cache repository is busy."
5dedd73d90f0c1f23299f0c613f384ef902c3653Stephen Gallagher return 1
5dedd73d90f0c1f23299f0c613f384ef902c3653Stephen Gallagher fi
5dedd73d90f0c1f23299f0c613f384ef902c3653Stephen Gallagher echo "Purging the download cache..."
5dedd73d90f0c1f23299f0c613f384ef902c3653Stephen Gallagher rm -rf --one-file-system $dlcache $rtcache || return 1
4f3fd1fb264a7eaf3a9d062d49e071b0d17e4debStephen Gallagher echo "Done."
4f3fd1fb264a7eaf3a9d062d49e071b0d17e4debStephen Gallagher return 0
4f3fd1fb264a7eaf3a9d062d49e071b0d17e4debStephen Gallagher ) 9> @LOCALSTATEDIR@/lock/subsys/lxc-plamo
4f3fd1fb264a7eaf3a9d062d49e071b0d17e4debStephen Gallagher}
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagherusage() {
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher cat <<- EOF
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher $prog [-h|--help] -p|--path=<path> -n|--name=<name> --rootfs=<rootfs>
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher [-c|--clean] [-r|--release=<release>] [-a|--arch=<arch>]
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher [-b|--bindhome=<user>]
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher release: $release
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher arch: x86 or x86_64: defaults to host arch
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher bindhome: bind <user>'s home into the container
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher EOF
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher}
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagherprog=`basename $0`
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagherpath="" ; name="" ; rootfs=""
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagherclean=0
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagherrelease=${release:-5.x}
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagherarch=`uname -m | sed 's/i.86/x86/'` ; hostarch=$arch
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagherbindhome=""
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallaghersopts=hp:n:cr:a:b:
46222e5191473f9a46aec581273eb2eef22e23beMichal Zideklopts=help,path:,name:,rootfs:,clean,release:,arch:,bindhome:
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagherif ! options=`getopt -o $sopts -l $lopts -- "$@"` ; then
46222e5191473f9a46aec581273eb2eef22e23beMichal Zidek usage
46222e5191473f9a46aec581273eb2eef22e23beMichal Zidek exit 1
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagherfi
46222e5191473f9a46aec581273eb2eef22e23beMichal Zidekeval set -- "$options"
46222e5191473f9a46aec581273eb2eef22e23beMichal Zidekwhile true ; do
46222e5191473f9a46aec581273eb2eef22e23beMichal Zidek case "$1" in
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher -h|--help) usage && exit 0 ;;
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher -p|--path) path=$2 ; shift 2 ;;
46222e5191473f9a46aec581273eb2eef22e23beMichal Zidek -n|--name) name=$2 ; shift 2 ;;
46222e5191473f9a46aec581273eb2eef22e23beMichal Zidek --rootfs) rootfs=$2 ; shift 2 ;;
46222e5191473f9a46aec581273eb2eef22e23beMichal Zidek -c|--clean) clean=1 ; shift 1 ;;
46222e5191473f9a46aec581273eb2eef22e23beMichal Zidek -r|--release) release=$2 ; shift 2 ;;
46222e5191473f9a46aec581273eb2eef22e23beMichal Zidek -a|--arch) arch=$2 ; shift 2 ;;
46222e5191473f9a46aec581273eb2eef22e23beMichal Zidek -b|--bindhome) bindhome=$2 ; shift 2 ;;
46222e5191473f9a46aec581273eb2eef22e23beMichal Zidek --) shift 1 ; break ;;
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher *) break ;;
5aad10b49e193ee14a86e1277146a223005a2d6bJakub Hrozek esac
5aad10b49e193ee14a86e1277146a223005a2d6bJakub Hrozekdone
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagherif [ $clean -eq 1 -a -z "$path" ] ; then
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher cleanup || exit 1
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher exit 0
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagherfi
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagherif [ $hostarch == "x86" -a $arch == "x86_64" ] ; then
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher echo "Can't create x86_64 container on x86."
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher exit 1
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagherfi
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagherif [ -z "$path" ] ; then
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher echo "'path' parameter is required."
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher exit 1
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagherfi
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagherif [ -z "$name" ] ; then
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher echo "'name' parameter is required."
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher exit 1
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagherfi
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagherif [ `id -u` -ne 0 ] ; then
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher echo "This script should be run as 'root'."
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher exit 1
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagherfi
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallaghercache=@LOCALSTATEDIR@/cache/lxc
df0596ec12bc5091608371e2977f3111241e8cafSimo Sorceptcache=$cache/partial-${prog##*-}-$release-$arch
9a7b6d3248c5aac460e164f2246b26131cfbc055Simo Sorcedlcache=$cache/cache-${prog##*-}-$release-$arch
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagherrtcache=$cache/rootfs-${prog##*-}-$release-$arch
46222e5191473f9a46aec581273eb2eef22e23beMichal Zidekif [ -z "$rootfs" ] ; then
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher if grep -q "^lxc.rootfs" $path/config ; then
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher rootfs=`awk -F= '/^lxc.rootfs =/{ print $2 }' $path/config`
505e75ba28b42bb3de7a6d55de825091b70cc2b2Stephen Gallagher else
45f75fc8e98092fa48faa3d180fd42f7efd51486Stephen Gallagher rootfs=$path/rootfs
45f75fc8e98092fa48faa3d180fd42f7efd51486Stephen Gallagher fi
45f75fc8e98092fa48faa3d180fd42f7efd51486Stephen Gallagherfi
45f75fc8e98092fa48faa3d180fd42f7efd51486Stephen Gallagherif ! install_plamo ; then
45f75fc8e98092fa48faa3d180fd42f7efd51486Stephen Gallagher echo "Failed to install plamo $release."
45f75fc8e98092fa48faa3d180fd42f7efd51486Stephen Gallagher exit 1
45f75fc8e98092fa48faa3d180fd42f7efd51486Stephen Gallagherfi
45f75fc8e98092fa48faa3d180fd42f7efd51486Stephen Gallagherif ! configure_plamo ; then
45f75fc8e98092fa48faa3d180fd42f7efd51486Stephen Gallagher echo "Failed to configure plamo $release for a container."
45f75fc8e98092fa48faa3d180fd42f7efd51486Stephen Gallagher exit 1
45f75fc8e98092fa48faa3d180fd42f7efd51486Stephen Gallagherfi
45f75fc8e98092fa48faa3d180fd42f7efd51486Stephen Gallagherif ! copy_configuration ; then
45f75fc8e98092fa48faa3d180fd42f7efd51486Stephen Gallagher echo "Failed to write configuration file."
45f75fc8e98092fa48faa3d180fd42f7efd51486Stephen Gallagher exit 1
45f75fc8e98092fa48faa3d180fd42f7efd51486Stephen Gallagherfi
45f75fc8e98092fa48faa3d180fd42f7efd51486Stephen Gallagherpost_process
45f75fc8e98092fa48faa3d180fd42f7efd51486Stephen Gallagherif [ -n "$bindhome" ] ; then
45f75fc8e98092fa48faa3d180fd42f7efd51486Stephen Gallagher do_bindhome
45f75fc8e98092fa48faa3d180fd42f7efd51486Stephen Gallagherfi
45f75fc8e98092fa48faa3d180fd42f7efd51486Stephen Gallagherif [ $clean -eq 1 ] ; then
45f75fc8e98092fa48faa3d180fd42f7efd51486Stephen Gallagher cleanup || exit 1
45f75fc8e98092fa48faa3d180fd42f7efd51486Stephen Gallagher exit 0
45f75fc8e98092fa48faa3d180fd42f7efd51486Stephen Gallagherfi
45f75fc8e98092fa48faa3d180fd42f7efd51486Stephen Gallagher