summaryrefslogtreecommitdiffstats
path: root/bin/debian-chroot
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xbin/debian-chroot367
1 files changed, 367 insertions, 0 deletions
diff --git a/bin/debian-chroot b/bin/debian-chroot
new file mode 100755
index 0000000..9251244
--- /dev/null
+++ b/bin/debian-chroot
@@ -0,0 +1,367 @@
+#!/bin/sh
+
+set -e
+
+COMMAND="${1:-enter}"
+
+if [ -n "${2}" ]
+then
+ DISTRIBUTION="$(echo ${2} | awk -F- '{ print $1 }')"
+else
+ DISTRIBUTION="${2:-sid}"
+fi
+
+if [ -n "${3}" ]
+then
+ ARCHITECTURE="${3:-$(dpkg --print-architecture)}"
+else
+ ARCHITECTURE="$(echo ${2} | awk -F- '{ print $2 }')"
+ ARCHITECTURE="${ARCHITECTURE:-amd64}"
+fi
+
+case "${DISTRIBUTION}" in
+ buster*)
+ DERIVATIVE_DISTRIBUTION="engywuck"
+ ;;
+
+ bullseye*)
+ DERIVATIVE_DISTRIBUTION="fuchur"
+ ;;
+esac
+
+MIRROR="debian.ethz.ch"
+
+CHROOT="/srv/chroots/${DISTRIBUTION}-${ARCHITECTURE}"
+
+Chroot ()
+{
+ if [ "${ARCHITECTURE}" = "$(dpkg --print-architecture)" ]
+ then
+ chroot "${CHROOT}" /usr/bin/env -i HOME="/root" PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" TERM="${TERM}" ${@}
+ else
+ linux32 chroot "${CHROOT}" /usr/bin/env -i HOME="/root" PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" TERM="${TERM}" ${@}
+ fi
+}
+
+case "${COMMAND}" in
+ create)
+ if [ ! -d "${CHROOT}" ]
+ then
+ debootstrap --arch=${ARCHITECTURE} --include=progress-linux ${DISTRIBUTION} "${CHROOT}" http://${MIRROR}/debian
+ else
+ echo "${CHROOT}: file or directory already exists."
+ exit 1
+ fi
+
+ # Configure apt
+
+cat > "${CHROOT}/etc/apt/apt.conf.d/chroot.conf" << EOF
+Acquire::PDiffs "false";
+APT::Clean-Installed "true";
+APT::Install-Recommends "false";
+APT::Install-Suggests "false";
+EOF
+
+cat > "${CHROOT}/etc/apt/sources.list" << EOF
+deb http://${MIRROR}/debian ${DISTRIBUTION} main contrib non-free
+EOF
+
+ case "${DISTRIBUTION}" in
+ sid*)
+
+cat >> "${CHROOT}/etc/apt/sources.list" << EOF
+deb http://${MIRROR}/debian experimental main contrib non-free
+EOF
+
+ ;;
+
+ buster*)
+
+cat > "${CHROOT}/etc/apt/sources.list.d/progress-linux.sources" << EOF
+Types: deb
+URIs: https://deb.progress-linux.org/packages
+Suites: ${DERIVATIVE_DISTRIBUTION}-backports
+Components: main contrib non-free restricted
+PDiffs: no
+Signed-By: /usr/share/progress-linux/pgp-keys/apt.progress-linux.org.gpg
+EOF
+
+ ;;
+
+ bullseye*)
+
+cat > "${CHROOT}/etc/apt/sources.list.d/progress-linux.sources" << EOF
+Types: deb
+URIs: https://deb.progress-linux.org/packages
+Suites: ${DERIVATIVE_DISTRIBUTION}-backports
+Components: main contrib non-free restricted
+PDiffs: no
+Signed-By: /usr/share/progress-linux/pgp-keys/apt.progress-linux.org.gpg
+EOF
+
+ ;;
+ esac
+
+ # Configure bash
+
+cat > "${CHROOT}/etc/profile.d/chroot.sh" << EOF
+#!/bin/sh
+
+alias ls="ls --color=auto"
+
+export DEBEMAIL="maintainers@lists.progress-linux.org"
+export DEBFULLNAME="Progress Linux Maintainers"
+
+export LANG="en_US.UTF-8"
+export LANGUAGE="en_US:en"
+export LC_ALL="C.UTF-8"
+EOF
+
+ # Configure dpkg
+ if [ -e "${CHROOT}/etc/dpkg" ]
+ then
+
+cat > "${CHROOT}/etc/dpkg/dpkg.cfg.d/chroot" << EOF
+force-unsafe-io
+EOF
+
+ fi
+
+ if [ -e "${CHROOT}/sbin/start-stop-daemon" ]
+ then
+ mv "${CHROOT}/sbin/start-stop-daemon" "${CHROOT}/sbin/start-stop-daemon.orig"
+ fi
+
+cat > "${CHROOT}/sbin/start-stop-daemon" << EOF
+#!/bin/sh
+
+exit 0
+EOF
+
+ chmod 0755 "${CHROOT}/sbin/start-stop-daemon"
+
+ # Configure sysv-rc
+ if [ -e "${CHROOT}/usr/sbin/policy-rc.d" ]
+ then
+ mv "${CHROOT}/usr/sbin/policy-rc.d" "${CHROOT}/usr/sbin/policy-rc.d.orig"
+ fi
+
+cat > "${CHROOT}/usr/sbin/policy-rc.d" << EOF
+#!/bin/sh
+
+echo "All runlevel operations denied by policy" >&2
+
+exit 101
+EOF
+
+ chmod 0755 "${CHROOT}/usr/sbin/policy-rc.d"
+
+ # Configure debian
+ echo "${DISTRIBUTION}_${ARCHITECTURE}" > "${CHROOT}/etc/debian_chroot"
+
+ Chroot apt update
+ Chroot apt upgrade --yes
+ Chroot apt dist-upgrade --yes
+
+ Chroot apt install --yes \
+ build-essential debhelper fakeroot
+
+ Chroot apt install --yes \
+ gnupg sudo wget
+
+ Chroot apt install --yes \
+ git rsync ca-certificates wget
+
+ Chroot apt clean
+
+ echo "Root password"
+
+ Chroot "passwd"
+ Chroot "adduser --home /build --ingroup sudo build"
+
+ echo ". /etc/profile" >> "${CHROOT}/build/.bashrc"
+
+ case $(cat /etc/hostname) in
+ all*)
+ BASH_HISTORY="indep"
+ ;;
+
+ source*)
+ BASH_HISTORY="source"
+ ;;
+
+ *)
+ BASH_HISTORY="arch"
+ ;;
+ esac
+
+ case "${BASH_HISTORY}" in
+ arch)
+
+cat > "${CHROOT}/build/.bash_history" << EOF
+cd */ && sudo apt-get build-dep -y . && dpkg-buildpackage -B && cd .. && rm -rf */
+sudo apt-get install -y -t ${DERIVATIVE_DISTRIBUTION}-backports debhelper
+clear && pbuild.sh -b binary-arch -d ${DERIVATIVE_DISTRIBUTION}-backports -p
+rsync -aPv --progress --stats * apt.progress-linux.org::upload && rm -rf *
+EOF
+
+ ;;
+
+ indep)
+
+cat > "${CHROOT}/build/.bash_history" << EOF
+cd */ && sudo apt-get build-dep -y . && dpkg-buildpackage -A && cd .. && rm -rf */
+sudo apt-get install -y -t ${DERIVATIVE_DISTRIBUTION}-backports debhelper
+clear && pbuild.sh -b binary-indep -d ${DERIVATIVE_DISTRIBUTION}-backports -p
+rsync -aPv --progress --stats * apt.progress-linux.org::upload && rm -rf *
+EOF
+
+ ;;
+
+ source)
+
+cat > "${CHROOT}/build/.bash_history" << EOF
+cd */ && sudo apt-get build-dep -y . && dpkg-buildpackage -A && cd .. && rm -rf */
+sudo apt-get install -y -t ${DERIVATIVE_DISTRIBUTION}-backports debhelper
+clear && pbuild.sh -b source -d ${DERIVATIVE_DISTRIBUTION}-backports -p
+rsync -aPv --progress --stats * apt.progress-linux.org::upload && rm -rf *
+EOF
+
+ ;;
+ esac
+
+ case "${DISTRIBUTION}" in
+ sid)
+
+cat >> "${CHROOT}/build/.bash_history" << EOF
+dpkg-buildpackage --changes-option=-S
+EOF
+
+ ;;
+ esac
+
+ chown 1000:1000 "${CHROOT}/build/.bash_history"
+
+ echo "build ALL=NOPASSWD: ALL" >> "${CHROOT}/etc/sudoers"
+ ;;
+
+ chroot)
+ Chroot "su - build"
+ ;;
+
+ update)
+ Chroot chmod 777 /dev/ptmx
+ Chroot apt-get --force-yes --yes update
+ Chroot apt-get --force-yes --yes upgrade
+ Chroot apt-get --force-yes --yes dist-upgrade
+ Chroot apt-get --force-yes --yes clean
+ ;;
+
+ save)
+ killall -9 syslogd > /dev/null 2>&1 || true
+ killall -9 klogd > /dev/null 2>&1 || true
+
+ for FILESYSTEM in /sys /proc /lib/init/rw /dev/shm /dev/pts /dev
+ do
+ umount -f "${CHROOT}/${FILESYSTEM}" > /dev/null 2>&1 || true
+ done
+
+ rm -f "${CHROOT}/root/.bash_history"
+ rm -f "${CHROOT}/root/.viminfo"
+ rm -f "${CHROOT}/build/.viminfo"
+ rm -rf "${CHROOT}/var/tmp/vi.recover"
+ rm -f "${CHROOT}/etc/machine-id"
+
+ case $(cat /etc/hostname) in
+ all*)
+ BASH_HISTORY="indep"
+ ;;
+
+ source*)
+ BASH_HISTORY="source"
+ ;;
+
+ *)
+ BASH_HISTORY="arch"
+ ;;
+ esac
+
+ case "${BASH_HISTORY}" in
+ arch)
+
+cat > "${CHROOT}/build/.bash_history" << EOF
+cd */ && sudo apt-get build-dep -y . && dpkg-buildpackage -B && cd .. && rm -rf */
+sudo apt-get install -y -t ${DERIVATIVE_DISTRIBUTION}-backports debhelper
+clear && pbuild.sh -b binary-arch -d ${DERIVATIVE_DISTRIBUTION}-backports -p
+rsync -aPv --progress --stats * apt.progress-linux.org::upload && rm -rf *
+EOF
+
+ ;;
+
+ indep)
+
+cat > "${CHROOT}/build/.bash_history" << EOF
+cd */ && sudo apt-get build-dep -y . && dpkg-buildpackage -A && cd .. && rm -rf */
+sudo apt-get install -y -t ${DERIVATIVE_DISTRIBUTION}-backports debhelper
+clear && pbuild.sh -b binary-indep -d ${DERIVATIVE_DISTRIBUTION}-backports -p
+rsync -aPv --progress --stats * apt.progress-linux.org::upload && rm -rf *
+EOF
+
+ ;;
+
+ source)
+
+cat > "${CHROOT}/build/.bash_history" << EOF
+cd */ && sudo apt-get build-dep -y . && dpkg-buildpackage -A && cd .. && rm -rf */
+sudo apt-get install -y -t ${DERIVATIVE_DISTRIBUTION}-backports debhelper
+clear && pbuild.sh -b source -d ${DERIVATIVE_DISTRIBUTION}-backports -p
+rsync -aPv --progress --stats * apt.progress-linux.org::upload && rm -rf *
+EOF
+ ;;
+ esac
+
+ case "${DISTRIBUTION}" in
+ sid)
+
+cat >> "${CHROOT}/build/.bash_history" << EOF
+dpkg-buildpackage --changes-option=-S
+EOF
+
+ ;;
+ esac
+
+ rsync -av --delete "${CHROOT}"/ "${CHROOT}".orig
+
+ mount proc-$(basename ${CHROOT}) "${CHROOT}/proc" -t proc
+ mount devpts-$(basename ${CHROOT}) "${CHROOT}/dev/pts" -t devpts
+ mount sysfs-$(basename ${CHROOT}) "${CHROOT}/sys" -t sysfs
+ mount /dev/shm -o bind "${CHROOT}/dev/shm"
+ ;;
+
+ restore)
+ killall -9 syslogd > /dev/null 2>&1 || true
+ killall -9 klogd > /dev/null 2>&1 || true
+
+ for FILESYSTEM in /sys /proc /lib/init/rw /dev/shm /dev/pts /dev
+ do
+ umount -f "${CHROOT}/${FILESYSTEM}" > /dev/null 2>&1 || true
+ done
+
+ rsync -av --delete "${CHROOT}".orig/ "${CHROOT}"
+
+ mount proc-$(basename ${CHROOT}) "${CHROOT}/proc" -t proc
+ mount devpts-$(basename ${CHROOT}) "${CHROOT}/dev/pts" -t devpts
+ mount sysfs-$(basename ${CHROOT}) "${CHROOT}/sys" -t sysfs
+ mount /dev/shm -o bind "${CHROOT}/dev/shm"
+ ;;
+
+ reset)
+ "${0}" restore ${DISTRIBUTION} ${ARCHITECTURE}
+ "${0}" update ${DISTRIBUTION} ${ARCHITECTURE}
+ "${0}" save ${DISTRIBUTION} ${ARCHITECTURE}
+ ;;
+
+ *)
+ echo "Wrong option."
+ exit 1
+esac