Improved Devuan template

Signed-off-by: Tanya Degurechaff <34323200+TanyaEleventhGoddess@users.noreply.github.com>
This commit is contained in:
Tanya Degurechaff 2020-07-06 11:47:22 +02:00
parent d43cb69eec
commit 05a7be54fb

View File

@ -5,6 +5,8 @@
# Authors:
# Daniel Lezcano <daniel.lezcano@free.fr>
# Greg Olsen <gregolsen@computer.org>
# Tanya <tanyadegurechaff@waifu.club>
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
@ -40,6 +42,7 @@ LOCALSTATEDIR="@LOCALSTATEDIR@"
LXC_TEMPLATE_CONFIG="@LXCTEMPLATECONFIG@"
# Allows the lxc-cache directory to be set by environment variable
LXC_CACHE_PATH=${LXC_CACHE_PATH:-"$LOCALSTATEDIR/cache/lxc"}
[ -z "$DOWNLOAD_KEYRING" ] && DOWNLOAD_KEYRING=1
find_interpreter()
{
@ -105,6 +108,9 @@ EOF
mkdir -p "$rootfs/selinux"
echo 0 > "$rootfs/selinux/enforce"
# remove links protection settings
rm -f "$rootfs/etc/sysctl.d/protect-links.conf"
# configure the network using the dhcp
cat <<EOF > $rootfs/etc/network/interfaces
auto lo
@ -117,6 +123,17 @@ EOF
# set the hostname
cat <<EOF > $rootfs/etc/hostname
$hostname
EOF
# set minimal hosts
cat <<EOF > $rootfs/etc/hosts
127.0.0.1 localhost
127.0.1.1 $hostname
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
EOF
# reconfigure some services
@ -129,7 +146,8 @@ EOF
chroot "$rootfs" locale-gen en_US.UTF-8 UTF-8
chroot "$rootfs" update-locale LANG=en_US.UTF-8
else
encoding=$(echo "$LANG" | cut -d. -f2)
encoding=$(locale charmap)
[ -z "${encoding}" ] && encoding="UTF-8"
chroot "$rootfs" sed -e "s/^# \(${LANG} ${encoding}\)/\1/" \
-i /etc/locale.gen 2> /dev/null
cat >> "$rootfs/etc/locale.gen" << EOF
@ -172,10 +190,12 @@ EOF
# set initial timezone as on host
if [ -f /etc/timezone ]; then
cat /etc/timezone > "$rootfs/etc/timezone"
rm -f "$rootfs/etc/localtime"
chroot "$rootfs" dpkg-reconfigure -f noninteractive tzdata
elif [ -f /etc/sysconfig/clock ]; then
. /etc/sysconfig/clock
echo "$ZONE" > "$rootfs/etc/timezone"
rm -f "$rootfs/etc/localtime"
chroot "$rootfs" dpkg-reconfigure -f noninteractive tzdata
else
echo "Timezone in container is not configured. Adjust it manually."
@ -210,12 +230,12 @@ write_sourceslist()
fi
cat >> "${rootfs}/etc/apt/sources.list" << EOF
${prefix} $MIRROR ${release} main${non_main}
${prefix} $MIRROR ${release} main${non_main}
EOF
if [ "$release" != "unstable" -a "$release" != "sid" ]; then
if [ "$release" != "unstable" -a "$release" != "ceres" ]; then
cat >> "${rootfs}/etc/apt/sources.list" << EOF
${prefix} $SECURITY_MIRROR ${release}/updates main${non_main}
${prefix} $SECURITY_MIRROR ${release}-updates main${non_main}
EOF
fi
}
@ -274,25 +294,15 @@ cleanup()
download_devuan()
{
case "$release" in
wheezy)
init=sysvinit
iproute=iproute
;;
*)
init=init
iproute=iproute2
;;
esac
packages=\
$init,\
init,\
ifupdown,\
locales,\
dialog,\
isc-dhcp-client,\
netbase,\
net-tools,\
$iproute,\
iproute2,\
openssh-server
cache=$1
@ -306,20 +316,26 @@ openssh-server
# Create the cache
mkdir -p "$cache"
# If debian-archive-keyring isn't installed, fetch GPG keys directly
releasekeyring=/usr/share/keyrings/debian-archive-keyring.gpg
if [ ! -f $releasekeyring ]; then
releasekeyring="$cache/archive-key.gpg"
case $release in
"wheezy")
gpgkeyname="archive-key-7.0"
;;
*)
gpgkeyname="archive-key-8"
;;
esac
wget https://ftp-master.debian.org/keys/${gpgkeyname}.asc -O - --quiet \
| gpg --import --no-default-keyring --keyring="${releasekeyring}"
# If devuan-archive-keyring isn't installed, fetch GPG keys directly
releasekeyring=/usr/share/keyrings/devuan-archive-keyring.gpg
lreleasekeyring=/etc/apt/trusted.gpg.d/devuan-archive-keyring.gpg
if [ -f "$releasekeyring" ]; then
apt_gpg_opt="--keyring=${releasekeyring}"
elif [ -f "$lreleasekeyring" ]; then
apt_gpg_opt="--keyring=${lreleasekeyring}"
elif [ "$DOWNLOAD_KEYRING" = 1 ]; then
[ ! -d "/etc/apt/trusted.gpg.d" ] && lreleasekeyring="$cache/archive-key.gpg"
if [[ "$(id -u)" == "0" ]]; then
wget https://git.devuan.org/devuan/devuan-keyring/raw/branch/master/keyrings/devuan-archive-keyring.gpg -O - --quiet \
| gpg --import --no-default-keyring --keyring="${lreleasekeyring}"
apt_gpg_opt="--keyring=${lreleasekeyring}"
else
echo "Must be root (sudo) to save $lreleasekeyring"
fi
fi
if [ -z "$apt_gpg_opt" ]; then
echo "WARNING: No GPG check"
apt_gpg_opt='--no-check-gpg'
fi
# check the mini devuan was not already downloaded
try_mksubvolume "$cache/partial-$release-$arch"
@ -332,7 +348,7 @@ openssh-server
echo "Downloading devuan minimal ..."
if [ "$interpreter" = "" ] ; then
debootstrap --verbose --variant=minbase --arch="$arch" \
--include=$packages --keyring="${releasekeyring}" \
--include=$packages "${apt_gpg_opt}" \
"$release" "$cache/partial-$release-$arch" "$MIRROR"
if [ $? -ne 0 ]; then
echo "Failed to download the rootfs, aborting."
@ -340,7 +356,7 @@ openssh-server
fi
else
debootstrap --foreign --verbose --variant=minbase --arch="$arch" \
--include=$packages --keyring="${releasekeyring}" \
--include=$packages "${apt_gpg_opt}" \
"$release" "$cache/partial-$release-$arch" "$MIRROR"
if [ $? -ne 0 ]; then
echo "Failed to download the rootfs, aborting."
@ -525,6 +541,11 @@ EOF
# Re-enable service startup
rm "${rootfs}/usr/sbin/policy-rc.d"
# Fix by Greg Olsen, avoid warning 'stdin not a tty' in some cases
if [[ -f "${rootfs}/root/.profile" ]]; then
sed -i -e 's/^mesg n/test -t 0 \&\& mesg n/g' ${rootfs}/root/.profile
fi
# end
}
@ -593,6 +614,8 @@ Environment variables:
Defaults to '$MIRROR'
SECURITY_MIRROR The Devuan package security mirror to use. See also the --security-mirror switch above.
Defaults to '$SECURITY_MIRROR'
DOWNLOAD_KEYRING Sets whether to download keyring when missing or ignore keyring checks
Defaults to 1
EOF
return 0
@ -732,7 +755,7 @@ if [ -n "$authkey" ]; then
fi
release=${release:-stable}
permanent_releases=('stable' 'testing' 'sid' 'unstable')
permanent_releases=('stable' 'testing' 'ceres' 'unstable')
if [[ ! "${permanent_releases[*]}" =~ (^|[^[:alpha:]])$release([^[:alpha:]]|$) ]]; then
if ! wget "${MIRROR}/dists/${release}/Release" -O /dev/null 2> /dev/null; then
echo "Invalid release ${release} (not found in mirror)"