3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini#!/bin/bash
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini#
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# lxc: linux Container library
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# Authors:
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# Daniel Lezcano <daniel.lezcano@free.fr>
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# Template for slackware by Matteo Bernardini <ponce@slackbuilds.org>
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# some parts are taken from the debian one (used as model)
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# This library is free software; you can redistribute it and/or
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# modify it under the terms of the GNU Lesser General Public
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# License as published by the Free Software Foundation; either
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# version 2.1 of the License, or (at your option) any later version.
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# This library is distributed in the hope that it will be useful,
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# but WITHOUT ANY WARRANTY; without even the implied warranty of
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# Lesser General Public License for more details.
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# You should have received a copy of the GNU Lesser General Public
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# License along with this library; if not, write to the Free Software
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# Detect use under userns (unsupported)
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinifor arg in "$@"; do
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini [ "$arg" = "--" ] && break
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini if [ "$arg" = "--mapped-uid" -o "$arg" = "--mapped-gid" ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini echo "This template can't be used for unprivileged containers." 1>&2
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini echo "You may want to try the \"download\" template instead." 1>&2
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini exit 1
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini fi
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinidone
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# Add some directories to PATH in case we create containers with sudo
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniexport PATH=/sbin:/usr/sbin:$PATH
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinicache=${cache:-/var/cache/lxc/slackware}
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# Use the primary Slackware site by default, but please consider changing
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# this to a closer mirror site.
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo BernardiniMIRROR=${MIRROR:-http://ftp.slackware.com/pub/slackware}
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniif [ -z "$arch" ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinicase "$( uname -m )" in
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini i?86) arch=i486 ;;
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini arm*) arch=arm ;;
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini *) arch=$( uname -m ) ;;
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniesac
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinifi
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo BernardiniLXC_TEMPLATE_CONFIG="@LXCTEMPLATECONFIG@"
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniconfigure_slackware()
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini{
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinirootfs=$1
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinihostname=$2
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniecho "Configuring..." ; echo
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# The next part contains excerpts taken from SeTconfig (written by
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# Patrick Volkerding) from the slackware setup disk.
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# But before pasting them just set a variable to use them as they are
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo BernardiniT_PX=$rootfs
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini( cd $T_PX ; chmod 755 ./ )
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini( cd $T_PX ; chmod 755 ./var )
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniif [ -d $T_PX/usr/src/linux ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini chmod 755 $T_PX/usr/src/linux
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinifi
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniif [ ! -d $T_PX/proc ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini mkdir $T_PX/proc
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini chown root.root $T_PX/proc
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinifi
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniif [ ! -d $T_PX/sys ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini mkdir $T_PX/sys
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini chown root.root $T_PX/sys
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinifi
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinichmod 1777 $T_PX/tmp
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniif [ ! -d $T_PX/var/spool/mail ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini mkdir -p $T_PX/var/spool/mail
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini chmod 755 $T_PX/var/spool
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini chown root.mail $T_PX/var/spool/mail
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini chmod 1777 $T_PX/var/spool/mail
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinifi
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniecho "#!/bin/sh" > $T_PX/etc/rc.d/rc.keymap
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniecho "# Load the keyboard map. More maps are in /usr/share/kbd/keymaps." \
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini >> $T_PX/etc/rc.d/rc.keymap
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniecho "if [ -x /usr/bin/loadkeys ]; then" >> $T_PX/etc/rc.d/rc.keymap
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniecho " /usr/bin/loadkeys us" >> $T_PX/etc/rc.d/rc.keymap
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniecho "fi" >> $T_PX/etc/rc.d/rc.keymap
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinichmod 755 $T_PX/etc/rc.d/rc.keymap
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# Network configuration is left to the user, that have to edit
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# /etc/rc.d/rc.inet1.conf and /etc/resolv.conf of the container
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# just set the hostname
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinicat <<EOF > $rootfs/etc/HOSTNAME
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini$hostname.example.net
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo BernardiniEOF
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinicp $rootfs/etc/HOSTNAME $rootfs/etc/hostname
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# make needed devices, from Chris Willing's MAKEDEV.sh
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# http://www.vislab.uq.edu.au/howto/lxc/MAKEDEV.sh
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo BernardiniDEV=$rootfs/dev
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinimkdir -p ${DEV}
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinimknod -m 666 ${DEV}/null c 1 3
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinimknod -m 666 ${DEV}/zero c 1 5
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinimknod -m 666 ${DEV}/random c 1 8
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinimknod -m 666 ${DEV}/urandom c 1 9
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinimkdir -m 755 ${DEV}/pts
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinimkdir -m 1777 ${DEV}/shm
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinimknod -m 666 ${DEV}/tty c 5 0
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinimknod -m 600 ${DEV}/console c 5 1
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinimknod -m 666 ${DEV}/tty0 c 4 0
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinimknod -m 666 ${DEV}/tty1 c 4 1
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinimknod -m 666 ${DEV}/tty2 c 4 2
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinimknod -m 666 ${DEV}/tty3 c 4 3
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinimknod -m 666 ${DEV}/tty4 c 4 4
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinimknod -m 666 ${DEV}/tty5 c 4 5
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinimknod -m 666 ${DEV}/full c 1 7
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinimknod -m 600 ${DEV}/initctl p
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinimknod -m 660 ${DEV}/loop0 b 7 0
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinimknod -m 660 ${DEV}/loop1 b 7 1
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniln -s pts/ptmx ${DEV}/ptmx
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniln -s /proc/self/fd ${DEV}/fd
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniecho "Adding an etc/fstab"
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinicat >$rootfs/etc/fstab <<EOF
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardininone /run tmpfs defaults,mode=0755 0 0
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo BernardiniEOF
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# simplify rc.6 and rc.S, http://www.vislab.uq.edu.au/howto/lxc/create_container.html
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# and some other small fixes for a clean boot
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinicat >$rootfs/tmp/rcs.patch <<'EOF'
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini--- ./etc/rc.orig/rc.6 2012-08-15 01:03:12.000000000 +0200
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+++ ./etc/rc.d/rc.6 2013-02-17 10:26:30.888839354 +0100
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini@@ -9,6 +9,12 @@
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # Author: Miquel van Smoorenburg <miquels@drinkel.nl.mugnet.org>
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # Modified by: Patrick J. Volkerding, <volkerdi@slackware.com>
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini #
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+# minor tweaks for an lxc container
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+# by Matteo Bernardini <ponce@slackbuilds.org>,
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+# based also on Chris Willing's modifications
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+# http://www.vislab.uq.edu.au/howto/lxc/rc.6
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+# a check for a container variable is made to jump sections
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+container="lxc"
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # Set the path.
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini PATH=/sbin:/etc:/bin:/usr/bin
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini@@ -37,6 +43,9 @@
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini ;;
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini esac
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+# lxc container check
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+if [ ! $container = "lxc" ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # Save the system time to the hardware clock using hwclock --systohc.
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini if [ -x /sbin/hwclock ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # Check for a broken motherboard RTC clock (where ioports for rtc are
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini@@ -53,6 +62,8 @@
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini fi
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini fi
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+fi # end container check
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # Run any local shutdown scripts:
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini if [ -x /etc/rc.d/rc.local_shutdown ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini /etc/rc.d/rc.local_shutdown stop
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini@@ -148,6 +159,9 @@
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini sleep 2
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini fi
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+# lxc container check
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+if [ ! $container = "lxc" ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # Shut down PCMCIA devices:
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini if [ -x /etc/rc.d/rc.pcmcia ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini . /etc/rc.d/rc.pcmcia stop
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini@@ -155,11 +169,16 @@
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini /bin/sleep 5
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini fi
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+fi # end container check
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # Turn off process accounting:
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini if [ -x /sbin/accton -a -r /var/log/pacct ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini /sbin/accton off
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini fi
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+# lxc container check
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+if [ ! $container = "lxc" ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # Terminate acpid before syslog:
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini if [ -x /etc/rc.d/rc.acpid -a -r /var/run/acpid.pid ]; then # quit
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini . /etc/rc.d/rc.acpid stop
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini@@ -170,6 +189,8 @@
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini sh /etc/rc.d/rc.udev force-stop
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini fi
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+fi # end container check
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # Kill all remaining processes.
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini if [ ! "$1" = "fast" ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini echo "Sending all processes the SIGTERM signal."
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini@@ -179,6 +200,9 @@
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini /sbin/killall5 -9
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini fi
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+# lxc container check
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+if [ ! $container = "lxc" ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # Try to turn off quota.
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini if /bin/grep -q quota /etc/fstab ; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini if [ -x /sbin/quotaoff ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini@@ -187,6 +211,8 @@
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini fi
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini fi
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+fi # end container check
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # Carry a random seed between reboots.
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini echo "Saving random seed from /dev/urandom in /etc/random-seed."
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # Use the pool size from /proc, or 512 bytes:
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini@@ -205,6 +231,9 @@
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini rm -f /var/lock/subsys/*
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini fi
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+# lxc container check
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+if [ ! $container = "lxc" ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # Turn off swap:
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini echo "Turning off swap."
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini /sbin/swapoff -a
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini@@ -216,6 +245,8 @@
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini echo "Remounting root filesystem read-only."
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini /bin/mount -v -n -o remount,ro /
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+fi # end container check
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # This never hurts:
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini /bin/sync
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini@@ -240,12 +271,17 @@
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini done
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini fi
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+# lxc container check
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+if [ ! $container = "lxc" ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # Deactivate LVM volume groups:
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini if [ -r /etc/lvmtab -o -d /etc/lvm/backup ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini echo "Deactivating LVM volume groups:"
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini /sbin/vgchange -an --ignorelockingfailure
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini fi
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+fi # end container check
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # This never hurts again (especially since root-on-LVM always fails
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # to deactivate the / logical volume... but at least it was
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # remounted as read-only first)
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini@@ -258,6 +294,9 @@
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # This is to ensure all processes have completed on SMP machines:
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini wait
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+# lxc container check
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+if [ ! $container = "lxc" ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini if [ -x /sbin/genpowerd ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # See if this is a powerfail situation:
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini if /bin/egrep -q "FAIL|SCRAM" /etc/upsstatus 2> /dev/null ; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini@@ -274,6 +313,13 @@
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini fi
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini fi
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+else
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+# confirm successful shutdown of the container
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+echo ; echo "* container stopped. *" ; echo
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+fi # end container check
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # Now halt (poweroff with APM or ACPI enabled kernels) or reboot.
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini if [ "$command" = "reboot" ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini echo "Rebooting."
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini--- ./etc/rc.orig/rc.S 2012-09-13 21:38:34.000000000 +0200
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+++ ./etc/rc.d/rc.S 2013-02-17 09:39:41.579799641 +0100
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini@@ -4,9 +4,18 @@
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini #
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # Mostly written by: Patrick J. Volkerding, <volkerdi@slackware.com>
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini #
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+# minor tweaks for an lxc container
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+# by Matteo Bernardini <ponce@slackbuilds.org>,
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+# based also on Chris Willing's modifications
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+# http://www.vislab.uq.edu.au/howto/lxc/rc.S
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+# a check for a container variable is made to jump sections
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+container="lxc"
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini PATH=/sbin:/usr/sbin:/bin:/usr/bin
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+# lxc container check
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+if [ ! $container = "lxc" ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # Try to mount /proc:
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini /sbin/mount -v proc /proc -n -t proc 2> /dev/null
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini@@ -254,10 +263,27 @@
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini read junk;
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini fi # Done checking root filesystem
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+else
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+ # We really don't want to start udev in the container
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+ if [ -f /etc/rc.d/rc.udev ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+ chmod -x /etc/rc.d/rc.udev
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+ fi
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+ # Alsa won't work
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+ if [ -f /etc/rc.d/rc.alsa ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+ chmod -x /etc/rc.d/rc.alsa
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+ fi
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+ # This too
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+ if [ -f /etc/rc.d/rc.loop ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+ chmod -x /etc/rc.d/rc.loop
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+ fi
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+fi # end container check
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # Any /etc/mtab that exists here is old, so we start with a new one:
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini /bin/rm -f /etc/mtab{,~,.tmp} && /bin/touch /etc/mtab
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+# lxc container check
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+if [ ! $container = "lxc" ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # Add entry for / to /etc/mtab:
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini /sbin/mount -f -w /
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini@@ -337,6 +363,8 @@
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # mounted read-write.
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini /sbin/swapon -a 2> /dev/null
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+fi # end container check
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # Clean up some temporary files:
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini rm -f /var/run/* /var/run/*/* /var/run/*/*/* /etc/nologin \
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini /etc/dhcpc/*.pid /etc/forcefsck /etc/fastboot \
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini@@ -364,7 +392,7 @@
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # if the first line of that file begins with the word 'Linux'.
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # You are free to modify the rest of the file as you see fit.
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini if [ -x /bin/sed ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini- /bin/sed -i "{1s/^Linux.*/$(/bin/uname -sr)\./}" /etc/motd
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+ /bin/sed -i "{1s/^Linux.*/$(/bin/uname -sr) lxc container\./}" /etc/motd
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini fi
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # If there are SystemV init scripts for this runlevel, run them.
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini@@ -372,6 +400,9 @@
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini . /etc/rc.d/rc.sysvinit
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini fi
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+# lxc container check
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+if [ ! $container = "lxc" ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # Run serial port setup script:
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # CAREFUL! This can make some systems hang if the rc.serial script isn't
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # set up correctly. If this happens, you may have to edit the file from a
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini@@ -380,6 +411,8 @@
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini sh /etc/rc.d/rc.serial start
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini fi
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+fi # end container check
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # Carry an entropy pool between reboots to improve randomness.
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini if [ -f /etc/random-seed ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini echo "Using /etc/random-seed to initialize /dev/urandom."
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini--- ./etc/rc.orig/rc.M 2012-09-25 19:47:07.000000000 +0200
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+++ ./etc/rc.d/rc.M 2013-02-17 09:39:41.579799641 +0100
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini@@ -10,6 +10,10 @@
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # Heavily modified by Patrick Volkerding <volkerdi@slackware.com>
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini #
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+# minor tweaks for an lxc container
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+# by Matteo Bernardini <ponce@slackbuilds.org>:
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+# a check for a container variable is made to jump sections
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+container="lxc"
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # Tell the viewers what's going to happen.
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini echo "Going multiuser..."
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini@@ -20,6 +24,9 @@
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini /sbin/ldconfig &
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini fi
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+# lxc container check
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+if [ ! $container = "lxc" ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # Screen blanks after 15 minutes idle time, and powers down in one hour
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # if the kernel supports APM or ACPI power management:
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini /bin/setterm -blank 15 -powersave powerdown -powerdown 60
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini@@ -33,6 +40,8 @@
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini /bin/hostname darkstar
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini fi
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+fi # end container check
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # Set the permissions on /var/log/dmesg according to whether the kernel
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # permits non-root users to access kernel dmesg information:
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini if [ -r /proc/sys/kernel/dmesg_restrict ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini@@ -135,6 +144,9 @@
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini chmod 755 / 2> /dev/null
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini chmod 1777 /tmp /var/tmp
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+# lxc container check
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+if [ ! $container = "lxc" ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # Start APM or ACPI daemon.
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # If APM is enabled in the kernel, start apmd:
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini if [ -e /proc/apm ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini@@ -146,6 +158,8 @@
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini . /etc/rc.d/rc.acpid start
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini fi
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+fi # end container check
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # Update any existing icon cache files:
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini if find /usr/share/icons 2> /dev/null | grep -q icon-theme.cache ; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini for theme_dir in /usr/share/icons/* ; do
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini--- ./etc/rc.orig/rc.inet1 2012-08-05 19:13:27.000000000 +0200
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+++ ./etc/rc.d/rc.inet1 2013-02-17 09:39:41.579799641 +0100
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini@@ -3,6 +3,11 @@
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # This script is used to bring up the various network interfaces.
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini #
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # @(#)/etc/rc.d/rc.inet1 10.2 Sun Jul 24 12:45:56 PDT 2005 (pjv)
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+#
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+# minor tweaks for an lxc container
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+# by Matteo Bernardini <ponce@slackbuilds.org>:
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+# a check for a container variable is made to jump sections
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+container="lxc"
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini ############################
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # READ NETWORK CONFIG FILE #
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini@@ -105,6 +110,10 @@
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini [ "${IFNAME[$i]}" = "${1}" ] && break
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini i=$(($i+1))
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini done
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+ # lxc container check
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+ if [ ! $container = "lxc" ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # If the interface is a bridge, then create it first:
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini [ -n "${BRNICS[$i]}" ] && br_open $i
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # If the interface isn't in the kernel yet (but there's an alias for it in
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini@@ -115,6 +124,9 @@
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini /sbin/modprobe ${1}
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini fi
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini fi
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+ fi # end container check
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini+
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini if grep `echo ${1}: | cut -f 1 -d :`: /proc/net/dev 1> /dev/null ; then # interface exists
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini if ! /sbin/ifconfig | grep -w "${1}" 1>/dev/null || \
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini ! /sbin/ifconfig ${1} | grep -w inet 1> /dev/null ; then # interface not up or not configured
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo BernardiniEOF
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini( cd $rootfs ; patch -p1 < tmp/rcs.patch ; rm tmp/rcs.patch )
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# restart rc.inet1 to have routing for the loop device
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniecho "/etc/rc.d/rc.inet1 restart" >> $rootfs/etc/rc.d/rc.local
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# reduce the number of local consoles: two should be enough
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinised -i '/^c3\|^c4\|^c5\|^c6/s/^/# /' $rootfs/etc/inittab
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# better not use this in a container
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinised -i 's/.*genpowerfail.*//' $rootfs/etc/inittab
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# add a message to rc.local that confirms successful container startup
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniecho "echo ; echo \"* container $name started. *\" ; echo" >> $rootfs/etc/rc.d/rc.local
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# borrow the time configuration from the local machine
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinicp -a /etc/localtime $rootfs/etc/localtime
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinireturn 0
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini}
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinicopy_slackware()
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini{
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinirootfs=$1
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# make a local copy of the installed filesystem
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniecho -n "Copying rootfs to $rootfs..."
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinimkdir -p $rootfs
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinicp -a $cache/rootfs-$release-$arch/* $rootfs/ || exit 1
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# fix fstab with the actual path
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinised -i "s|$cache/rootfs-$release-$arch|$rootfs|" $rootfs/etc/fstab
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinireturn 0
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini}
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniinstall_slackware()
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini{
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinirootfs=$1
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinimkdir -p /var/lock/subsys/
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini(
2c0f32e6432f24dcc698d8fe0bd84d83a3588bdcElan Ruusamäeflock -n -x 9
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniif [ $? -ne 0 ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini echo "Cache repository is busy."
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini return 1
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinifi
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniif [ "$arch" == "x86_64" ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini PKGMAIN=slackware64
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinielif [ "$arch" == "arm" ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini PKGMAIN=slackwarearm
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinielse
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini PKGMAIN=slackware
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinifi
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniexport CONF=$cache/slackpkg-conf
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniexport ROOT=$cache/rootfs-$release-$arch
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinimkdir -p $cache/cache-$release-$arch $cache/rootfs-$release-$arch \
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini $cache/slackpkg-$release-$arch $CONF/templates
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniecho "$MIRROR/$PKGMAIN-$release/" > $CONF/mirrors
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinitouch $CONF/blacklist
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinicat <<EOF > $CONF/slackpkg.conf
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# v2.8
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo BernardiniARCH=$arch
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo BernardiniTEMP=$cache/cache-$release-$arch
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo BernardiniWORKDIR=$cache/slackpkg-$release-$arch
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo BernardiniDELALL=off
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo BernardiniCHECKMD5=on
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo BernardiniCHECKGPG=on
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo BernardiniCHECKSIZE=off
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo BernardiniPRIORITY=( patches %PKGMAIN extra pasture testing )
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo BernardiniPOSTINST=on
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo BernardiniONLY_NEW_DOTNEW=off
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo BernardiniONOFF=on
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo BernardiniDOWNLOAD_ALL=on
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo BernardiniDIALOG=off
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo BernardiniBATCH=on
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo BernardiniDEFAULT_ANSWER=y
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo BernardiniUSE_INCLUDES=on
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo BernardiniSPINNING=off
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo BernardiniEOF
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# thanks to Vincent Batts for this list of packages
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# (that I modified a little :P)
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# http://connie.slackware.com/~vbatts/minimal/
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinicat <<EOF > $CONF/templates/minimal-lxc.template
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniaaa_base
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniaaa_elflibs
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniaaa_terminfo
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinibash
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinibin
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinibzip2
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinicoreutils
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinidhcpcd
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinidialog
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinidiffutils
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinie2fsprogs
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinielvis
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinietc
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinifindutils
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinigawk
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniglibc-solibs
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinignupg
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinigrep
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinigzip
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniiputils
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinilogrotate
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinimpfr
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardininet-tools
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardininetwork-scripts
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinincurses
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniopenssh
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniopenssl-solibs
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinipkgtools
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniprocps-ng
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinised
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinishadow
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinisharutils
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinislackpkg
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinisysklogd
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinisysvinit
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinisysvinit-functions
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinisysvinit-scripts
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinitar
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniudev
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniutil-linux
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniwget
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniwhich
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinixz
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo BernardiniEOF
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo BernardiniTEMPLATE=${TEMPLATE:-minimal-lxc}
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniif [ ! "$TEMPLATE" = "minimal-lxc" ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini if [ -f /etc/slackpkg/templates/$TEMPLATE.template ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini cat /etc/slackpkg/templates/$TEMPLATE.template \
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini > $CONF/templates/$TEMPLATE.template
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini else
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini TEMPLATE="minimal-lxc"
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini fi
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinifi
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# clean previous installs
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinirm -fR $ROOT/*
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinislackpkg -default_answer=n update
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinislackpkg install-template $TEMPLATE
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# add a slackpkg default mirror
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniecho "$MIRROR/$PKGMAIN-$release/" >> $ROOT/etc/slackpkg/mirrors
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# blacklist the devs package (we have to use our premade devices).
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# do the same with the kernel packages (we use the host's one),
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# but leave available headers and sources
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniecho "devs" >> $ROOT/etc/slackpkg/blacklist
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinised -i \
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini -e "s|^#kernel-|kernel-|" \
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini -e "s|^kernel-headers|#kernel-headers|" \
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini -e "s|^kernel-source|#kernel-source|" \
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini $ROOT/etc/slackpkg/blacklist
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# force klog to use the system call interface to the kernel message
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# buffers - needed for unprivileged containers
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinised -i 's|3\ \-x|3 -x -s|' $ROOT/etc/rc.d/rc.syslog || true
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinireturn 0
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
2c0f32e6432f24dcc698d8fe0bd84d83a3588bdcElan Ruusamäe) 9>/var/lock/subsys/lxc
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinireturn $?
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini}
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinicopy_configuration()
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini{
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinipath=$1
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinirootfs=$2
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardininame=$3
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinicat <<EOF >> $path/config
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinilxc.utsname = $name
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinilxc.arch = $arch
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinilxc.mount = $rootfs/etc/fstab
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinilxc.include = ${LXC_TEMPLATE_CONFIG}/slackware.common.conf
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo BernardiniEOF
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniif [ $? -ne 0 ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini echo "Failed to add configuration."
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini return 1
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinifi
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinireturn 0
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini}
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniclean()
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini{
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniif [ ! -e $cache ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini exit 0
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinifi
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# lock, so we won't purge while someone is creating a repository
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini(
2c0f32e6432f24dcc698d8fe0bd84d83a3588bdcElan Ruusamäeflock -n -x 9
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniif [ $? != 0 ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini echo "Cache repository is busy."
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini exit 1
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinifi
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniecho -n "Purging the download cache..."
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinirm --preserve-root --one-file-system -rf $cache && echo "Done." || exit 1
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniexit 0
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
2c0f32e6432f24dcc698d8fe0bd84d83a3588bdcElan Ruusamäe) 9>/var/lock/subsys/lxc
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini}
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniusage()
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini{
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinicat <<EOF
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini$1 -h|--help -p|--path=<path> --clean
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo BernardiniEOF
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinireturn 0
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini}
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinioptions=$(getopt -o hp:n:a:r:c -l help,rootfs:,path:,name:,arch:,release:,clean -- "$@")
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniif [ $? -ne 0 ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini usage $(basename $0)
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini exit 1
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinifi
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinieval set -- "$options"
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniwhile true
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinido
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinicase "$1" in
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini -h|--help) usage $0 && exit 0;;
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini -p|--path) path=$2; shift 2;;
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini --rootfs) rootfs=$2; shift 2;;
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini -a|--arch) arch=$2; shift 2;;
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini -r|--release) release=$2; shift 2;;
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini -n|--name) name=$2; shift 2;;
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini -c|--clean) clean=$2; shift 2;;
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini --) shift 1; break ;;
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini *) break ;;
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniesac
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinidone
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniif [ ! -z "$clean" -a -z "$path" ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini clean || exit 1
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini exit 0
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinifi
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinitype installpkg
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniif [ $? -ne 0 ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini echo "'installpkg' command is missing."
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini exit 1
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinifi
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinitype slackpkg
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniif [ $? -ne 0 ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini echo "'slackpkg' command is missing."
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini exit 1
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinifi
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniif [ -z "$path" ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini echo "'path' parameter is required."
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini exit 1
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinifi
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniif [ "$(id -u)" != "0" ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini echo "This script should be run as 'root'."
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini exit 1
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinifi
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# If no release version was specified, use current
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinirelease=${release:-current}
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniif [ -z "$name" ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini # no name given? set a default one
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini name=slackwarecontainer
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinifi
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini# detect rootfs
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniconfig="$path/config"
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniif [ -z "$rootfs" ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini if grep -q '^lxc.rootfs' $config 2>/dev/null ; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini rootfs=$(awk -F= '/^lxc.rootfs =/{ print $2 }' $config)
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini else
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini rootfs=$path/rootfs
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini fi
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinifi
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniecho
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniset -e
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniinstall_slackware $rootfs
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniif [ $? -ne 0 ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini echo "Failed to install slackware."
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini exit 1
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinifi
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniecho
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniconfigure_slackware $cache/rootfs-$release-$arch $name
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniif [ $? -ne 0 ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini echo "Failed to configure slackware for a container."
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini exit 1
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinifi
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniecho
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinirootfs=$path/rootfs
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinicopy_slackware $rootfs
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniif [ $? -ne 0 ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini echo "Failed to copy rootfs."
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini exit 1
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinifi
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniecho
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinicopy_configuration $path $rootfs $name
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniif [ $? -ne 0 ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini echo "Failed to write configuration file."
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini exit 1
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinifi
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardiniif [ ! -z $clean ]; then
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini clean || exit 1
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardini exit 0
3a05a669c1ad73fc57a5295d8aaae04b20e40c88Matteo Bernardinifi