Reformatting tabs and spaces in a coherent way

Signed-off-by: Tanya Degurechaff <34323200+TanyaEleventhGoddess@users.noreply.github.com>
This commit is contained in:
Tanya Degurechaff 2020-07-12 08:01:13 +02:00
parent 076cd7413d
commit 92d4e109f1
13 changed files with 347 additions and 347 deletions

View File

@ -196,8 +196,8 @@ download_altlinux()
# some scripts want to have /dev/null at least # some scripts want to have /dev/null at least
dev_path="$INSTALL_ROOT/dev" dev_path="$INSTALL_ROOT/dev"
if [ ! -c "${dev_path}/null" ]; then if [ ! -c "${dev_path}/null" ]; then
mkdir -p "${dev_path}" mkdir -p "${dev_path}"
mknod -m 666 "${dev_path}/null" c 1 3 mknod -m 666 "${dev_path}/null" c 1 3
fi fi
$APT_GET install $PKG_LIST $APT_GET install $PKG_LIST

View File

@ -389,8 +389,8 @@ configure_centos_init()
chroot ${rootfs_path} chkconfig network on chroot ${rootfs_path} chkconfig network on
if [ "$release" = "7" ]; then if [ "$release" = "7" ]; then
# don't wait for the timeout # don't wait for the timeout
chroot ${rootfs_path} chkconfig systemd-remount-fs off chroot ${rootfs_path} chkconfig systemd-remount-fs off
fi fi
if [ -d ${rootfs_path}/etc/init ] if [ -d ${rootfs_path}/etc/init ]
@ -435,13 +435,13 @@ download_centos()
REPO_FILE=$INSTALL_ROOT/etc/yum.repos.d/lxc-centos-temp.repo REPO_FILE=$INSTALL_ROOT/etc/yum.repos.d/lxc-centos-temp.repo
mkdir -p $(dirname $REPO_FILE) mkdir -p $(dirname $REPO_FILE)
if [ -n "$repo" ]; then if [ -n "$repo" ]; then
cat <<EOF > $REPO_FILE cat <<EOF > $REPO_FILE
[base] [base]
name=local repository name=local repository
baseurl="$repo" baseurl="$repo"
EOF EOF
elif [ ${basearch} = 'i386' ] || [ ${basearch} = 'x86_64' ]; then elif [ ${basearch} = 'i386' ] || [ ${basearch} = 'x86_64' ]; then
cat <<EOF > $REPO_FILE cat <<EOF > $REPO_FILE
[base] [base]
name=CentOS-$release - Base name=CentOS-$release - Base
mirrorlist=http://mirrorlist.centos.org/?release=$release&arch=$basearch&repo=os mirrorlist=http://mirrorlist.centos.org/?release=$release&arch=$basearch&repo=os
@ -451,7 +451,7 @@ name=CentOS-$release - Updates
mirrorlist=http://mirrorlist.centos.org/?release=$release&arch=$basearch&repo=updates mirrorlist=http://mirrorlist.centos.org/?release=$release&arch=$basearch&repo=updates
EOF EOF
else else
cat <<EOF > $REPO_FILE cat <<EOF > $REPO_FILE
[base] [base]
name=CentOS-$release - Base name=CentOS-$release - Base
baseurl=http://mirror.centos.org/altarch/7/os/$basearch/ baseurl=http://mirror.centos.org/altarch/7/os/$basearch/

View File

@ -797,14 +797,14 @@ fi
if [ -n "$authkey" ]; then if [ -n "$authkey" ]; then
if [ ! -f "$authkey" ]; then if [ ! -f "$authkey" ]; then
echo "SSH keyfile '$authkey' not found" echo "SSH keyfile '$authkey' not found"
exit 1 exit 1
fi fi
# This is mostly to prevent accidental uage of the private key instead # This is mostly to prevent accidental uage of the private key instead
# of the public key. # of the public key.
if [ "${authkey: -4}" != ".pub" ]; then if [ "${authkey: -4}" != ".pub" ]; then
echo "SSH keyfile '$authkey' does not end with '.pub'" echo "SSH keyfile '$authkey' does not end with '.pub'"
exit 1 exit 1
fi fi
fi fi
@ -812,8 +812,8 @@ release=${release:-stable}
permanent_releases=('stable' 'testing' 'sid' 'unstable') permanent_releases=('stable' 'testing' 'sid' 'unstable')
if [[ ! "${permanent_releases[*]}" =~ (^|[^[:alpha:]])$release([^[:alpha:]]|$) ]]; then if [[ ! "${permanent_releases[*]}" =~ (^|[^[:alpha:]])$release([^[:alpha:]]|$) ]]; then
if ! wget "${MIRROR}/dists/${release}/Release" -O /dev/null 2> /dev/null; then if ! wget "${MIRROR}/dists/${release}/Release" -O /dev/null 2> /dev/null; then
echo "Invalid release ${release} (not found in mirror)" echo "Invalid release ${release} (not found in mirror)"
exit 1 exit 1
fi fi
fi fi

View File

@ -743,14 +743,14 @@ fi
if [ -n "$authkey" ]; then if [ -n "$authkey" ]; then
if [ ! -f "$authkey" ]; then if [ ! -f "$authkey" ]; then
echo "SSH keyfile '$authkey' not found" echo "SSH keyfile '$authkey' not found"
exit 1 exit 1
fi fi
# This is mostly to prevent accidental uage of the private key instead # This is mostly to prevent accidental uage of the private key instead
# of the public key. # of the public key.
if [ "${authkey: -4}" != ".pub" ]; then if [ "${authkey: -4}" != ".pub" ]; then
echo "SSH keyfile '$authkey' does not end with '.pub'" echo "SSH keyfile '$authkey' does not end with '.pub'"
exit 1 exit 1
fi fi
fi fi
@ -758,8 +758,8 @@ release=${release:-stable}
permanent_releases=('stable' 'testing' 'ceres' 'unstable') permanent_releases=('stable' 'testing' 'ceres' 'unstable')
if [[ ! "${permanent_releases[*]}" =~ (^|[^[:alpha:]])$release([^[:alpha:]]|$) ]]; then if [[ ! "${permanent_releases[*]}" =~ (^|[^[:alpha:]])$release([^[:alpha:]]|$) ]]; then
if ! wget "${MIRROR}/dists/${release}/Release" -O /dev/null 2> /dev/null; then if ! wget "${MIRROR}/dists/${release}/Release" -O /dev/null 2> /dev/null; then
echo "Invalid release ${release} (not found in mirror)" echo "Invalid release ${release} (not found in mirror)"
exit 1 exit 1
fi fi
fi fi

View File

@ -455,7 +455,7 @@ container_portage()
printf "trying to guess portage distfiles dir from host ...\n" printf "trying to guess portage distfiles dir from host ...\n"
portage_distfiles_dir="$(portageq distdir 2>/dev/null)" portage_distfiles_dir="$(portageq distdir 2>/dev/null)"
if [ ! -d "${portage_distfiles_dir}" ]; then if [ ! -d "${portage_distfiles_dir}" ]; then
portage_distfiles_dir="${portage_dir}/distfiles" portage_distfiles_dir="${portage_dir}/distfiles"
fi fi
# if we are here, we have shared portage_dir # if we are here, we have shared portage_dir

View File

@ -746,14 +746,14 @@ fi
if [ -n "$authkey" ]; then if [ -n "$authkey" ]; then
if [ ! -f "$authkey" ]; then if [ ! -f "$authkey" ]; then
echo "SSH keyfile '$authkey' not found" echo "SSH keyfile '$authkey' not found"
exit 1 exit 1
fi fi
# This is mostly to prevent accidental uage of the private key instead # This is mostly to prevent accidental uage of the private key instead
# of the public key. # of the public key.
if [ "${authkey: -4}" != ".pub" ]; then if [ "${authkey: -4}" != ".pub" ]; then
echo "SSH keyfile '$authkey' does not end with '.pub'" echo "SSH keyfile '$authkey' does not end with '.pub'"
exit 1 exit 1
fi fi
fi fi

View File

@ -178,7 +178,7 @@ configure_openmandriva_systemd()
unlink ${rootfs_path}/etc/systemd/system/default.target unlink ${rootfs_path}/etc/systemd/system/default.target
chroot ${rootfs_path} ln -s /lib/systemd/system/multi-user.target /etc/systemd/system/default.target chroot ${rootfs_path} ln -s /lib/systemd/system/multi-user.target /etc/systemd/system/default.target
sed -i 's!ConditionPathExists=/dev/tty0!ConditionPathExists=|/dev/tty0\nConditionVirtualization=|lxc!' \ sed -i 's!ConditionPathExists=/dev/tty0!ConditionPathExists=|/dev/tty0\nConditionVirtualization=|lxc!' \
${rootfs_path}/lib/systemd/system/getty\@.service ${rootfs_path}/lib/systemd/system/getty\@.service
} }

View File

@ -453,8 +453,8 @@ fi
if grep -q Harlequin /etc/os-release || grep -q Tumbleweed /etc/os-release ; then if grep -q Harlequin /etc/os-release || grep -q Tumbleweed /etc/os-release ; then
BVER=`rpm -q --qf '%{version}\n' build` BVER=`rpm -q --qf '%{version}\n' build`
if [ $? -ne 0 -o "$BVER" -lt "20141120" ]; then if [ $? -ne 0 -o "$BVER" -lt "20141120" ]; then
echo "Building openSUSE containers with your version of the build package is broken. Please install the update to version 20141120 or newer." echo "Building openSUSE containers with your version of the build package is broken. Please install the update to version 20141120 or newer."
exit 1 exit 1
fi fi
fi fi
@ -465,43 +465,43 @@ if [ -z "$DISTRO" ]; then
else else
echo "" echo ""
case "$DISTRO" in case "$DISTRO" in
13.1) 13.1)
echo "Selected openSUSE 13.1" echo "Selected openSUSE 13.1"
;; ;;
13.2) 13.2)
echo "Selected openSUSE 13.2" echo "Selected openSUSE 13.2"
;; ;;
42.1|leap/42.1|421) 42.1|leap/42.1|421)
echo "Selected openSUSE Leap 42.1" echo "Selected openSUSE Leap 42.1"
DISTRO="leap/42.1" DISTRO="leap/42.1"
;; ;;
42.2|leap/42.2|422) 42.2|leap/42.2|422)
echo "Selected openSUSE Leap 42.2" echo "Selected openSUSE Leap 42.2"
DISTRO="leap/42.2" DISTRO="leap/42.2"
;; ;;
42.3|leap/42.3|423) 42.3|leap/42.3|423)
echo "Selected openSUSE Leap 42.3" echo "Selected openSUSE Leap 42.3"
DISTRO="leap/42.3" DISTRO="leap/42.3"
;; ;;
15.0|leap/15.0|150|leap) 15.0|leap/15.0|150|leap)
echo "Selected openSUSE Leap 15.0" echo "Selected openSUSE Leap 15.0"
DISTRO="leap/15.0" DISTRO="leap/15.0"
;; ;;
tumbleweed|factory) tumbleweed|factory)
echo "Selected openSUSE Leap Tumbleweed" echo "Selected openSUSE Leap Tumbleweed"
DISTRO="tumbleweed" DISTRO="tumbleweed"
;; ;;
*) *)
echo "You have chosen an invalid release, quitting..." echo "You have chosen an invalid release, quitting..."
exit 1 exit 1
;; ;;
esac esac
fi fi

View File

@ -148,21 +148,21 @@ EOF
# with newer systemd (OL7.2), getty service include container-getty.service # with newer systemd (OL7.2), getty service include container-getty.service
# let that be the one who manage the getty service instead # let that be the one who manage the getty service instead
if [ ! -f $container_rootfs/usr/lib/systemd/system/container-getty@.service ]; then if [ ! -f $container_rootfs/usr/lib/systemd/system/container-getty@.service ]; then
# from mhw in the fedora template: We do need to disable the # from mhw in the fedora template: We do need to disable the
# "ConditionalPathExists=/dev/tty0" line or no gettys are started on # "ConditionalPathExists=/dev/tty0" line or no gettys are started on
# the ttys in the container. Lets do it in an override copy of the # the ttys in the container. Lets do it in an override copy of the
# service so it can still pass rpm verifies and not be automatically # service so it can still pass rpm verifies and not be automatically
# updated by a new systemd version. # updated by a new systemd version.
sed -e 's/^ConditionPathExists=/#LXC ConditionPathExists=/' \ sed -e 's/^ConditionPathExists=/#LXC ConditionPathExists=/' \
< $container_rootfs/usr/lib/systemd/system/getty\@.service \ < $container_rootfs/usr/lib/systemd/system/getty\@.service \
> $container_rootfs/etc/systemd/system/getty\@.service > $container_rootfs/etc/systemd/system/getty\@.service
# Setup getty service on the 4 ttys we are going to allow in the # Setup getty service on the 4 ttys we are going to allow in the
# default config. Number should match lxc.tty # default config. Number should match lxc.tty
( cd $container_rootfs/etc/systemd/system/getty.target.wants ( cd $container_rootfs/etc/systemd/system/getty.target.wants
for i in 1 2 3 4 ; do ln -sf ../getty\@.service getty@tty${i}.service; done ) for i in 1 2 3 4 ; do ln -sf ../getty\@.service getty@tty${i}.service; done )
# We only want to spawn a getty on /dev/console in lxc, libvirt-lxc # We only want to spawn a getty on /dev/console in lxc, libvirt-lxc
# symlinks /dev/console to /dev/tty1 # symlinks /dev/console to /dev/tty1
sed -i '/Before=getty.target/a ConditionVirtualization=lxc' $container_rootfs/usr/lib/systemd/system/console-getty.service sed -i '/Before=getty.target/a ConditionVirtualization=lxc' $container_rootfs/usr/lib/systemd/system/console-getty.service
fi fi
# disable some systemd services, set default boot, sigpwr target # disable some systemd services, set default boot, sigpwr target
@ -307,9 +307,9 @@ EOF
# some of these might not exist in the image, so we silence chkconfig complaining # some of these might not exist in the image, so we silence chkconfig complaining
# about the service file not being found # about the service file not being found
for service in \ for service in \
acpid apmd auditd autofs cpuspeed dund gpm haldaemon hidd \ acpid apmd auditd autofs cpuspeed dund gpm haldaemon hidd \
ip6tables irqbalance iscsi iscsid isdn kdump kudzu \ ip6tables irqbalance iscsi iscsid isdn kdump kudzu \
lm_sensors lvm2-monitor mdmonitor microcode_ctl \ lm_sensors lvm2-monitor mdmonitor microcode_ctl \
ntpd pcmcia postfix sendmail udev-post xfs ; ntpd pcmcia postfix sendmail udev-post xfs ;
do do
chroot $container_rootfs chkconfig 2>/dev/null $service off chroot $container_rootfs chkconfig 2>/dev/null $service off
@ -363,13 +363,13 @@ EOF
# allow root login on console, tty[1-4], and pts/0 for libvirt # allow root login on console, tty[1-4], and pts/0 for libvirt
echo "# LXC (Linux Containers)" >>$container_rootfs/etc/securetty echo "# LXC (Linux Containers)" >>$container_rootfs/etc/securetty
echo "lxc/console" >>$container_rootfs/etc/securetty echo "lxc/console" >>$container_rootfs/etc/securetty
for i in 1 2 3 4; do for i in 1 2 3 4; do
echo "lxc/tty$i" >>$container_rootfs/etc/securetty echo "lxc/tty$i" >>$container_rootfs/etc/securetty
done done
echo "# For libvirt/Virtual Machine Monitor" >>$container_rootfs/etc/securetty echo "# For libvirt/Virtual Machine Monitor" >>$container_rootfs/etc/securetty
for i in 0 1 2 3 4; do for i in 0 1 2 3 4; do
echo "pts/$i" >>$container_rootfs/etc/securetty echo "pts/$i" >>$container_rootfs/etc/securetty
done done
# prevent mingetty from calling vhangup(2) since it fails with userns # prevent mingetty from calling vhangup(2) since it fails with userns
@ -511,7 +511,7 @@ EOF
lxc_network_hwaddr=`grep '^lxc.net.0.hwaddr' $cfg_dir/config | awk -F'[= \t]+' '{ print $2 }'` lxc_network_hwaddr=`grep '^lxc.net.0.hwaddr' $cfg_dir/config | awk -F'[= \t]+' '{ print $2 }'`
if [ -z "$lxc_network_hwaddr" ]; then if [ -z "$lxc_network_hwaddr" ]; then
# generate a hwaddr for the container # generate a hwaddr for the container
# see http://sourceforge.net/tracker/?func=detail&aid=3411497&group_id=163076&atid=826303 # see http://sourceforge.net/tracker/?func=detail&aid=3411497&group_id=163076&atid=826303
local hwaddr="00:16:3e:`dd if=/dev/urandom bs=8 count=1 2>/dev/null |od -t x8 | \ local hwaddr="00:16:3e:`dd if=/dev/urandom bs=8 count=1 2>/dev/null |od -t x8 | \
head -n1 | awk '{print $2}' | cut -c1-6 | \ head -n1 | awk '{print $2}' | cut -c1-6 | \
@ -850,19 +850,19 @@ eval set -- "$options"
while true while true
do do
case "$1" in case "$1" in
-h|--help) usage $0 && exit 0;; -h|--help) usage $0 && exit 0;;
-p|--path) cfg_dir=$2; shift 2;; -p|--path) cfg_dir=$2; shift 2;;
--rootfs) container_rootfs=$2; shift 2;; --rootfs) container_rootfs=$2; shift 2;;
-n|--name) name=$2; shift 2;; -n|--name) name=$2; shift 2;;
-a|--arch) arch=$2; shift 2;; -a|--arch) arch=$2; shift 2;;
-R|--release) container_release_version=$2; shift 2;; -R|--release) container_release_version=$2; shift 2;;
-r|--rpms) user_pkgs=$2; shift 2;; -r|--rpms) user_pkgs=$2; shift 2;;
-u|--url) repourl=$2; shift 2;; -u|--url) repourl=$2; shift 2;;
-t|--templatefs) template_rootfs=$2; shift 2;; -t|--templatefs) template_rootfs=$2; shift 2;;
--patch) patch_rootfs=$2; shift 2;; --patch) patch_rootfs=$2; shift 2;;
--baseurl) baseurl=$2; shift 2;; --baseurl) baseurl=$2; shift 2;;
--) shift 1; break ;; --) shift 1; break ;;
*) break ;; *) break ;;
esac esac
done done

View File

@ -40,21 +40,21 @@ cache_base=@LOCALSTATEDIR@/cache/lxc/pld/$arch
default_path=@LXCPATH@ default_path=@LXCPATH@
if [ -e /etc/os-release ]; then if [ -e /etc/os-release ]; then
# This is a shell friendly configuration file. We can just source it. # This is a shell friendly configuration file. We can just source it.
# What we're looking for in here is the ID, VERSION_ID and the CPE_NAME # What we're looking for in here is the ID, VERSION_ID and the CPE_NAME
. /etc/os-release . /etc/os-release
echo "Host CPE ID from /etc/os-release: ${CPE_NAME}" echo "Host CPE ID from /etc/os-release: ${CPE_NAME}"
fi fi
if [ "${CPE_NAME}" != "" -a "${ID}" = "pld" -a "${VERSION_ID}" != "" ]; then if [ "${CPE_NAME}" != "" -a "${ID}" = "pld" -a "${VERSION_ID}" != "" ]; then
pld_host_ver=${VERSION_ID} pld_host_ver=${VERSION_ID}
is_pld=true is_pld=true
elif [ -e /etc/pld-release ]; then elif [ -e /etc/pld-release ]; then
# Only if all other methods fail, try to parse the pld-release file. # Only if all other methods fail, try to parse the pld-release file.
pld_host_ver=$(sed -e '/PLD /!d' -e 's/^\([0-9.]*\)\sPLD.*/\1/' < /etc/pld-release) pld_host_ver=$(sed -e '/PLD /!d' -e 's/^\([0-9.]*\)\sPLD.*/\1/' < /etc/pld-release)
if [ "$pld_host_ver" != "" ]; then if [ "$pld_host_ver" != "" ]; then
is_pld=true is_pld=true
fi fi
fi fi
# Map a few architectures to their generic PLD Linux repository archs. # Map a few architectures to their generic PLD Linux repository archs.
@ -65,177 +65,177 @@ esac
configure_pld() configure_pld()
{ {
# disable selinux # disable selinux
mkdir -p $rootfs_path/selinux mkdir -p $rootfs_path/selinux
echo 0 > $rootfs_path/selinux/enforce echo 0 > $rootfs_path/selinux/enforce
# configure the network using the dhcp # configure the network using the dhcp
sed -i -e "s/^HOSTNAME=.*/HOSTNAME=${utsname}/" ${rootfs_path}/etc/sysconfig/network sed -i -e "s/^HOSTNAME=.*/HOSTNAME=${utsname}/" ${rootfs_path}/etc/sysconfig/network
# set hostname on systemd # set hostname on systemd
if [ $release = "3.0" ]; then if [ $release = "3.0" ]; then
echo "${utsname}" > ${rootfs_path}/etc/hostname echo "${utsname}" > ${rootfs_path}/etc/hostname
fi fi
# set minimal hosts # set minimal hosts
test -e $rootfs_path/etc/hosts || \ test -e $rootfs_path/etc/hosts || \
cat <<EOF > $rootfs_path/etc/hosts cat <<EOF > $rootfs_path/etc/hosts
127.0.0.1 localhost.localdomain localhost $utsname 127.0.0.1 localhost.localdomain localhost $utsname
::1 localhost6.localdomain6 localhost6 ::1 localhost6.localdomain6 localhost6
EOF EOF
dev_path="${rootfs_path}/dev" dev_path="${rootfs_path}/dev"
rm -rf $dev_path rm -rf $dev_path
mkdir -p $dev_path mkdir -p $dev_path
mknod -m 666 ${dev_path}/null c 1 3 mknod -m 666 ${dev_path}/null c 1 3
mknod -m 666 ${dev_path}/zero c 1 5 mknod -m 666 ${dev_path}/zero c 1 5
mknod -m 666 ${dev_path}/random c 1 8 mknod -m 666 ${dev_path}/random c 1 8
mknod -m 666 ${dev_path}/urandom c 1 9 mknod -m 666 ${dev_path}/urandom c 1 9
mkdir -m 755 ${dev_path}/pts mkdir -m 755 ${dev_path}/pts
mkdir -m 1777 ${dev_path}/shm mkdir -m 1777 ${dev_path}/shm
mknod -m 666 ${dev_path}/tty c 5 0 mknod -m 666 ${dev_path}/tty c 5 0
mknod -m 666 ${dev_path}/tty0 c 4 0 mknod -m 666 ${dev_path}/tty0 c 4 0
mknod -m 666 ${dev_path}/tty1 c 4 1 mknod -m 666 ${dev_path}/tty1 c 4 1
mknod -m 666 ${dev_path}/tty2 c 4 2 mknod -m 666 ${dev_path}/tty2 c 4 2
mknod -m 666 ${dev_path}/tty3 c 4 3 mknod -m 666 ${dev_path}/tty3 c 4 3
mknod -m 666 ${dev_path}/tty4 c 4 4 mknod -m 666 ${dev_path}/tty4 c 4 4
mknod -m 600 ${dev_path}/console c 5 1 mknod -m 600 ${dev_path}/console c 5 1
mknod -m 666 ${dev_path}/full c 1 7 mknod -m 666 ${dev_path}/full c 1 7
mknod -m 600 ${dev_path}/initctl p mknod -m 600 ${dev_path}/initctl p
mknod -m 666 ${dev_path}/ptmx c 5 2 mknod -m 666 ${dev_path}/ptmx c 5 2
if [ -n "${root_password}" ]; then if [ -n "${root_password}" ]; then
echo "setting root passwd to $root_password" echo "setting root passwd to $root_password"
echo "root:$root_password" | chroot $rootfs_path chpasswd echo "root:$root_password" | chroot $rootfs_path chpasswd
fi fi
return 0 return 0
} }
configure_pld_init() configure_pld_init()
{ {
# default powerfail action waits 2 minutes. for lxc we want it immediately # default powerfail action waits 2 minutes. for lxc we want it immediately
sed -i -e '/^pf::powerfail:/ s,/sbin/shutdown.*,/sbin/halt,' ${rootfs_path}/etc/inittab sed -i -e '/^pf::powerfail:/ s,/sbin/shutdown.*,/sbin/halt,' ${rootfs_path}/etc/inittab
} }
configure_pld_systemd() configure_pld_systemd()
{ {
unlink ${rootfs_path}/etc/systemd/system/default.target unlink ${rootfs_path}/etc/systemd/system/default.target
chroot ${rootfs_path} ln -s /dev/null /etc/systemd/system/udev.service chroot ${rootfs_path} ln -s /dev/null /etc/systemd/system/udev.service
chroot ${rootfs_path} ln -s /lib/systemd/system/multi-user.target /etc/systemd/system/default.target chroot ${rootfs_path} ln -s /lib/systemd/system/multi-user.target /etc/systemd/system/default.target
# Actually, the After=dev-%i.device line does not appear in the # Actually, the After=dev-%i.device line does not appear in the
# Fedora 17 or Fedora 18 systemd getty@.service file. It may be left # Fedora 17 or Fedora 18 systemd getty@.service file. It may be left
# over from an earlier version and it's not doing any harm. We do need # over from an earlier version and it's not doing any harm. We do need
# to disable the "ConditionalPathExists=/dev/tty0" line or no gettys are # to disable the "ConditionalPathExists=/dev/tty0" line or no gettys are
# started on the ttys in the container. Lets do it in an override copy of # started on the ttys in the container. Lets do it in an override copy of
# the service so it can still pass rpm verifies and not be automatically # the service so it can still pass rpm verifies and not be automatically
# updated by a new systemd version. -- mhw /\/\|=mhw=|\/\/ # updated by a new systemd version. -- mhw /\/\|=mhw=|\/\/
sed -e 's/^ConditionPathExists=/# ConditionPathExists=/' \ sed -e 's/^ConditionPathExists=/# ConditionPathExists=/' \
-e 's/After=dev-%i.device/After=/' \ -e 's/After=dev-%i.device/After=/' \
< ${rootfs_path}/lib/systemd/system/getty@.service \ < ${rootfs_path}/lib/systemd/system/getty@.service \
> ${rootfs_path}/etc/systemd/system/getty@.service > ${rootfs_path}/etc/systemd/system/getty@.service
# Setup getty service on the 4 ttys we are going to allow in the # Setup getty service on the 4 ttys we are going to allow in the
# default config. Number should match lxc.tty.max # default config. Number should match lxc.tty.max
for i in 1 2 3 4; do for i in 1 2 3 4; do
ln -sf ../getty@.service ${rootfs_path}/etc/systemd/system/getty.target.wants/getty@tty${i}.service ln -sf ../getty@.service ${rootfs_path}/etc/systemd/system/getty.target.wants/getty@tty${i}.service
done done
} }
download_pld() download_pld()
{ {
# check the mini pld was not already downloaded # check the mini pld was not already downloaded
INSTALL_ROOT=$cache/partial INSTALL_ROOT=$cache/partial
mkdir -p $INSTALL_ROOT mkdir -p $INSTALL_ROOT
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Failed to create '$INSTALL_ROOT' directory" echo "Failed to create '$INSTALL_ROOT' directory"
return 1 return 1
fi fi
# download a mini pld into a cache # download a mini pld into a cache
echo "Downloading PLD Linux minimal ..." echo "Downloading PLD Linux minimal ..."
POLDEK="poldek --root $INSTALL_ROOT --noask --nohold --noignore" POLDEK="poldek --root $INSTALL_ROOT --noask --nohold --noignore"
PKG_LIST="basesystem filesystem pld-release rpm poldek vserver-packages rc-scripts pwdutils mingetty" PKG_LIST="basesystem filesystem pld-release rpm poldek vserver-packages rc-scripts pwdutils mingetty"
mkdir -p $INSTALL_ROOT@LOCALSTATEDIR@/lib/rpm mkdir -p $INSTALL_ROOT@LOCALSTATEDIR@/lib/rpm
rpm --root $INSTALL_ROOT --initdb rpm --root $INSTALL_ROOT --initdb
$POLDEK -u $PKG_LIST $POLDEK -u $PKG_LIST
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Failed to download the rootfs, aborting." echo "Failed to download the rootfs, aborting."
return 1 return 1
fi fi
mv "$INSTALL_ROOT" "$cache/rootfs" mv "$INSTALL_ROOT" "$cache/rootfs"
echo "Download complete." echo "Download complete."
return 0 return 0
} }
copy_pld() copy_pld()
{ {
# make a local copy of the minipld # make a local copy of the minipld
echo -n "Copying rootfs to $rootfs_path ..." echo -n "Copying rootfs to $rootfs_path ..."
cp -a $cache/rootfs/* $rootfs_path || return 1 cp -a $cache/rootfs/* $rootfs_path || return 1
return 0 return 0
} }
update_pld() update_pld()
{ {
POLDEK="poldek --root $cache/rootfs --noask" POLDEK="poldek --root $cache/rootfs --noask"
$POLDEK --upgrade-dist $POLDEK --upgrade-dist
} }
install_pld() install_pld()
{ {
mkdir -p @LOCALSTATEDIR@/lock/subsys/ mkdir -p @LOCALSTATEDIR@/lock/subsys/
( (
flock -x 9 flock -x 9
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Cache repository is busy." echo "Cache repository is busy."
return 1 return 1
fi fi
echo "Checking cache download in $cache/rootfs ... " echo "Checking cache download in $cache/rootfs ... "
if [ ! -e "$cache/rootfs" ]; then if [ ! -e "$cache/rootfs" ]; then
download_pld download_pld
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Failed to download 'pld base'" echo "Failed to download 'pld base'"
return 1 return 1
fi fi
else else
echo "Cache found. Updating..." echo "Cache found. Updating..."
update_pld update_pld
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Failed to update 'pld base', continuing with last known good cache" echo "Failed to update 'pld base', continuing with last known good cache"
else else
echo "Update finished" echo "Update finished"
fi fi
fi fi
echo "Copy $cache/rootfs to $rootfs_path ... " echo "Copy $cache/rootfs to $rootfs_path ... "
copy_pld copy_pld
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Failed to copy rootfs" echo "Failed to copy rootfs"
return 1 return 1
fi fi
return 0 return 0
) 9>@LOCALSTATEDIR@/lock/subsys/lxc-pld ) 9>@LOCALSTATEDIR@/lock/subsys/lxc-pld
return $? return $?
} }
copy_configuration() copy_configuration()
{ {
mkdir -p $config_path mkdir -p $config_path
grep -q "^lxc.rootfs.path" $config_path/config 2>/dev/null || echo "lxc.rootfs.path = $rootfs_path" >> $config_path/config grep -q "^lxc.rootfs.path" $config_path/config 2>/dev/null || echo "lxc.rootfs.path = $rootfs_path" >> $config_path/config
cat <<EOF >> $config_path/config cat <<EOF >> $config_path/config
# Most of below settings should be taken as defaults from # Most of below settings should be taken as defaults from
# lxc.include = /usr/share/lxc/config/common.conf # lxc.include = /usr/share/lxc/config/common.conf
lxc.uts.name = $utsname lxc.uts.name = $utsname
@ -276,46 +276,46 @@ lxc.cgroup.devices.allow = c 5:2 rwm
lxc.cgroup.devices.allow = c 254:0 rm lxc.cgroup.devices.allow = c 254:0 rm
EOF EOF
cat <<EOF > $config_path/fstab cat <<EOF > $config_path/fstab
proc proc proc nodev,noexec,nosuid 0 0 proc proc proc nodev,noexec,nosuid 0 0
sysfs sys sysfs defaults 0 0 sysfs sys sysfs defaults 0 0
EOF EOF
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Failed to add configuration" echo "Failed to add configuration"
return 1 return 1
fi fi
return 0 return 0
} }
clean() clean()
{ {
if [ ! -e $cache ]; then if [ ! -e $cache ]; then
exit 0 exit 0
fi fi
# lock, so we won't purge while someone is creating a repository # lock, so we won't purge while someone is creating a repository
( (
flock -x 9 flock -x 9
if [ $? != 0 ]; then if [ $? != 0 ]; then
echo "Cache repository is busy." echo "Cache repository is busy."
exit 1 exit 1
fi fi
echo -n "Purging the download cache for PLD Linux $release..." echo -n "Purging the download cache for PLD Linux $release..."
rm --preserve-root --one-file-system -rf $cache && echo "Done." || exit 1 rm --preserve-root --one-file-system -rf $cache && echo "Done." || exit 1
exit 0 exit 0
) 9>@LOCALSTATEDIR@/lock/subsys/lxc-pld ) 9>@LOCALSTATEDIR@/lock/subsys/lxc-pld
} }
usage() usage()
{ {
cat <<EOF cat <<EOF
usage: usage:
$1 -n|--name=<container_name> $1 -n|--name=<container_name>
[-p|--path=<path>] [-c|--clean] [-R|--release=<PLD Release>] [--fqdn=<network name of container>] [-A|--arch=<arch of the container>] [-p|--path=<path>] [-c|--clean] [-R|--release=<PLD Release>] [--fqdn=<network name of container>] [-A|--arch=<arch of the container>]
[-h|--help] [-h|--help]
Mandatory args: Mandatory args:
-n,--name container name, used to as an identifier for that container from now on -n,--name container name, used to as an identifier for that container from now on
Optional args: Optional args:
@ -323,41 +323,41 @@ Optional args:
--rootfs path for actual rootfs. --rootfs path for actual rootfs.
-c,--clean clean the cache -c,--clean clean the cache
-R,--release PLD Linux release for the new container. if the host is PLD Linux, then it will default to the host's release. -R,--release PLD Linux release for the new container. if the host is PLD Linux, then it will default to the host's release.
--fqdn fully qualified domain name (FQDN) for DNS and system naming --fqdn fully qualified domain name (FQDN) for DNS and system naming
-A,--arch NOT USED YET. Define what arch the container will be [i686,x86_64] -A,--arch NOT USED YET. Define what arch the container will be [i686,x86_64]
-h,--help print this help -h,--help print this help
EOF EOF
return 0 return 0
} }
options=$(getopt -o hp:n:cR: -l help,path:,rootfs:,name:,clean,release:,fqdn: -- "$@") options=$(getopt -o hp:n:cR: -l help,path:,rootfs:,name:,clean,release:,fqdn: -- "$@")
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
usage $(basename $0) usage $(basename $0)
exit 1 exit 1
fi fi
eval set -- "$options" eval set -- "$options"
while :; do while :; do
case "$1" in case "$1" in
-h|--help) usage $0 && exit 0;; -h|--help) usage $0 && exit 0;;
-p|--path) path=$2; shift 2;; -p|--path) path=$2; shift 2;;
--rootfs) rootfs=$2; shift 2;; --rootfs) rootfs=$2; shift 2;;
-n|--name) name=$2; shift 2;; -n|--name) name=$2; shift 2;;
-c|--clean) clean=$2; shift 2;; -c|--clean) clean=$2; shift 2;;
-R|--release) release=$2; shift 2;; -R|--release) release=$2; shift 2;;
--fqdn) utsname=$2; shift 2;; --fqdn) utsname=$2; shift 2;;
--) shift 1; break ;; --) shift 1; break ;;
*) break ;; *) break ;;
esac esac
done done
if [ ! -z "$clean" -a -z "$path" ]; then if [ ! -z "$clean" -a -z "$path" ]; then
clean || exit 1 clean || exit 1
exit 0 exit 0
fi fi
if [ -z "${utsname}" ]; then if [ -z "${utsname}" ]; then
utsname=${name} utsname=${name}
fi fi
# This follows a standard "resolver" convention that an FQDN must have # This follows a standard "resolver" convention that an FQDN must have
@ -374,51 +374,51 @@ fi
# utsname and hostname = Container_Name.Domain_Name # utsname and hostname = Container_Name.Domain_Name
if [ $(expr "$utsname" : '.*\..*\.') = 0 ]; then if [ $(expr "$utsname" : '.*\..*\.') = 0 ]; then
if [ -n "$(dnsdomainname)" ]; then if [ -n "$(dnsdomainname)" ]; then
utsname=${utsname}.$(dnsdomainname) utsname=${utsname}.$(dnsdomainname)
fi fi
fi fi
needed_pkgs="" needed_pkgs=""
type poldek >/dev/null 2>&1 type poldek >/dev/null 2>&1
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
needed_pkgs="poldek $needed_pkgs" needed_pkgs="poldek $needed_pkgs"
fi fi
#type curl >/dev/null 2>&1 #type curl >/dev/null 2>&1
#if [ $? -ne 0 ]; then #if [ $? -ne 0 ]; then
# needed_pkgs="curl $needed_pkgs" # needed_pkgs="curl $needed_pkgs"
#fi #fi
if [ -n "$needed_pkgs" ]; then if [ -n "$needed_pkgs" ]; then
echo "Missing commands: $needed_pkgs" echo "Missing commands: $needed_pkgs"
echo "Please install these using \"sudo poldek -u $needed_pkgs\"" echo "Please install these using \"sudo poldek -u $needed_pkgs\""
exit 1 exit 1
fi fi
if [ -z "$path" ]; then if [ -z "$path" ]; then
path=$default_path/$name path=$default_path/$name
fi fi
if [ -z "$release" ]; then if [ -z "$release" ]; then
if [ "$is_pld" -a "$pld_host_ver" ]; then if [ "$is_pld" -a "$pld_host_ver" ]; then
release=$pld_host_ver release=$pld_host_ver
else else
echo "This is not a PLD Linux host and release missing, defaulting to 3.0. use -R|--release to specify release" echo "This is not a PLD Linux host and release missing, defaulting to 3.0. use -R|--release to specify release"
release=3.0 release=3.0
fi fi
fi fi
# pld th have systemd. We need autodev enabled to keep systemd from causing problems. # pld th have systemd. We need autodev enabled to keep systemd from causing problems.
if [ $release = 3.0 ]; then if [ $release = 3.0 ]; then
auto_dev="0" auto_dev="0"
else else
auto_dev="0" auto_dev="0"
fi fi
if [ "$(id -u)" != "0" ]; then if [ "$(id -u)" != "0" ]; then
echo "This script should be run as 'root'" echo "This script should be run as 'root'"
exit 1 exit 1
fi fi
if [ -z "$rootfs" ]; then if [ -z "$rootfs" ]; then
@ -436,49 +436,49 @@ cache=$cache_base/$release
revert() revert()
{ {
echo "Interrupted, so cleaning up" echo "Interrupted, so cleaning up"
lxc-destroy -n $name lxc-destroy -n $name
# maybe was interrupted before copy config # maybe was interrupted before copy config
rm -rf $path rm -rf $path
rm -rf $default_path/$name rm -rf $default_path/$name
echo "exiting..." echo "exiting..."
exit 1 exit 1
} }
trap revert SIGHUP SIGINT SIGTERM trap revert SIGHUP SIGINT SIGTERM
copy_configuration copy_configuration
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Failed write configuration file" echo "Failed write configuration file"
exit 1 exit 1
fi fi
install_pld install_pld
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Failed to install PLD Linux" echo "Failed to install PLD Linux"
exit 1 exit 1
fi fi
configure_pld configure_pld
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Failed to configure PLD Linux for a container" echo "Failed to configure PLD Linux for a container"
exit 1 exit 1
fi fi
# If the systemd configuration directory exists - set it up for what we need. # If the systemd configuration directory exists - set it up for what we need.
if [ -d ${rootfs_path}/etc/systemd/system ]; then if [ -d ${rootfs_path}/etc/systemd/system ]; then
configure_pld_systemd configure_pld_systemd
fi fi
# This configuration (rc.sysinit) is not inconsistent with the systemd stuff # This configuration (rc.sysinit) is not inconsistent with the systemd stuff
# above and may actually coexist on some upgraded systems. Let's just make # above and may actually coexist on some upgraded systems. Let's just make
# sure that, if it exists, we update this file, even if it's not used... # sure that, if it exists, we update this file, even if it's not used...
if [ -f ${rootfs_path}/etc/rc.sysinit ]; then if [ -f ${rootfs_path}/etc/rc.sysinit ]; then
configure_pld_init configure_pld_init
fi fi
if [ ! -z $clean ]; then if [ ! -z $clean ]; then
clean || exit 1 clean || exit 1
exit 0 exit 0
fi fi
echo "container rootfs and config created" echo "container rootfs and config created"

View File

@ -499,8 +499,8 @@ mkdir -p /var/lock/subsys/
( (
flock -n -x 9 flock -n -x 9
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Cache repository is busy." echo "Cache repository is busy."
return 1 return 1
fi fi
if [ "$arch" == "x86_64" ]; then if [ "$arch" == "x86_64" ]; then
@ -508,7 +508,7 @@ if [ "$arch" == "x86_64" ]; then
elif [ "$arch" == "arm" ]; then elif [ "$arch" == "arm" ]; then
PKGMAIN=slackwarearm PKGMAIN=slackwarearm
else else
PKGMAIN=slackware PKGMAIN=slackware
fi fi
export CONF=$cache/slackpkg-conf export CONF=$cache/slackpkg-conf
@ -651,8 +651,8 @@ lxc.include = ${LXC_TEMPLATE_CONFIG}/slackware.common.conf
EOF EOF
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Failed to add configuration." echo "Failed to add configuration."
return 1 return 1
fi fi
return 0 return 0
@ -661,15 +661,15 @@ return 0
clean() clean()
{ {
if [ ! -e $cache ]; then if [ ! -e $cache ]; then
exit 0 exit 0
fi fi
# lock, so we won't purge while someone is creating a repository # lock, so we won't purge while someone is creating a repository
( (
flock -n -x 9 flock -n -x 9
if [ $? != 0 ]; then if [ $? != 0 ]; then
echo "Cache repository is busy." echo "Cache repository is busy."
exit 1 exit 1
fi fi
echo -n "Purging the download cache..." echo -n "Purging the download cache..."
@ -689,8 +689,8 @@ return 0
options=$(getopt -o hp:n:a:r:c -l help,rootfs:,path:,name:,arch:,release:,clean -- "$@") options=$(getopt -o hp:n:a:r:c -l help,rootfs:,path:,name:,arch:,release:,clean -- "$@")
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
usage $(basename $0) usage $(basename $0)
exit 1 exit 1
fi fi
eval set -- "$options" eval set -- "$options"
@ -699,59 +699,59 @@ do
case "$1" in case "$1" in
-h|--help) usage $0 && exit 0;; -h|--help) usage $0 && exit 0;;
-p|--path) path=$2; shift 2;; -p|--path) path=$2; shift 2;;
--rootfs) rootfs=$2; shift 2;; --rootfs) rootfs=$2; shift 2;;
-a|--arch) arch=$2; shift 2;; -a|--arch) arch=$2; shift 2;;
-r|--release) release=$2; shift 2;; -r|--release) release=$2; shift 2;;
-n|--name) name=$2; shift 2;; -n|--name) name=$2; shift 2;;
-c|--clean) clean=$2; shift 2;; -c|--clean) clean=$2; shift 2;;
--) shift 1; break ;; --) shift 1; break ;;
*) break ;; *) break ;;
esac esac
done done
if [ ! -z "$clean" -a -z "$path" ]; then if [ ! -z "$clean" -a -z "$path" ]; then
clean || exit 1 clean || exit 1
exit 0 exit 0
fi fi
type installpkg type installpkg
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "'installpkg' command is missing." echo "'installpkg' command is missing."
exit 1 exit 1
fi fi
type slackpkg type slackpkg
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "'slackpkg' command is missing." echo "'slackpkg' command is missing."
exit 1 exit 1
fi fi
if [ -z "$path" ]; then if [ -z "$path" ]; then
echo "'path' parameter is required." echo "'path' parameter is required."
exit 1 exit 1
fi fi
if [ "$(id -u)" != "0" ]; then if [ "$(id -u)" != "0" ]; then
echo "This script should be run as 'root'." echo "This script should be run as 'root'."
exit 1 exit 1
fi fi
# If no release version was specified, use current # If no release version was specified, use current
release=${release:-current} release=${release:-current}
if [ -z "$name" ]; then if [ -z "$name" ]; then
# no name given? set a default one # no name given? set a default one
name=slackwarecontainer name=slackwarecontainer
fi fi
# detect rootfs # detect rootfs
config="$path/config" config="$path/config"
if [ -z "$rootfs" ]; then if [ -z "$rootfs" ]; then
if grep -q '^lxc.rootfs.path' $config 2>/dev/null ; then if grep -q '^lxc.rootfs.path' $config 2>/dev/null ; then
rootfs=$(awk -F= '/^lxc.rootfs.path =/{ print $2 }' $config) rootfs=$(awk -F= '/^lxc.rootfs.path =/{ print $2 }' $config)
else else
rootfs=$path/rootfs rootfs=$path/rootfs
fi fi
fi fi
echo echo
@ -760,16 +760,16 @@ set -e
install_slackware $rootfs install_slackware $rootfs
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Failed to install slackware." echo "Failed to install slackware."
exit 1 exit 1
fi fi
echo echo
configure_slackware $cache/rootfs-$release-$arch $name configure_slackware $cache/rootfs-$release-$arch $name
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Failed to configure slackware for a container." echo "Failed to configure slackware for a container."
exit 1 exit 1
fi fi
echo echo
@ -777,19 +777,19 @@ echo
rootfs=$path/rootfs rootfs=$path/rootfs
copy_slackware $rootfs copy_slackware $rootfs
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Failed to copy rootfs." echo "Failed to copy rootfs."
exit 1 exit 1
fi fi
echo echo
copy_configuration $path $rootfs $name copy_configuration $path $rootfs $name
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Failed to write configuration file." echo "Failed to write configuration file."
exit 1 exit 1
fi fi
if [ ! -z $clean ]; then if [ ! -z $clean ]; then
clean || exit 1 clean || exit 1
exit 0 exit 0
fi fi

View File

@ -233,9 +233,9 @@ EOF
# allow root login on console, tty[1-4], and pts/0 for libvirt # allow root login on console, tty[1-4], and pts/0 for libvirt
echo "# LXC (Linux Containers)" >>$container_rootfs/etc/securetty echo "# LXC (Linux Containers)" >>$container_rootfs/etc/securetty
echo "lxc/console" >>$container_rootfs/etc/securetty echo "lxc/console" >>$container_rootfs/etc/securetty
for i in 1 2 3 4; do for i in 1 2 3 4; do
echo "lxc/tty$i" >>$container_rootfs/etc/securetty echo "lxc/tty$i" >>$container_rootfs/etc/securetty
done done
echo "# For libvirt/Virtual Machine Monitor" >>$container_rootfs/etc/securetty echo "# For libvirt/Virtual Machine Monitor" >>$container_rootfs/etc/securetty
for i in 0 1 2 3 4; do for i in 0 1 2 3 4; do

View File

@ -32,9 +32,9 @@
# Check if array $2 contains item $1 # Check if array $2 contains item $1
containsElement() { containsElement() {
local e local e
for e in "${@:2}"; do [[ "$1" == "$e" ]] && return 0; done for e in "${@:2}"; do [[ "$1" == "$e" ]] && return 0; done
return 1 return 1
} }
# split comma-separated string into an array # split comma-separated string into an array