User setup and erlang installation

A bit fiddly, but this lets us run a realistic erlang install script
from userspace, and then re-enter userspace later without wiping the
installation.
This commit is contained in:
Jarvis Carroll
2025-05-23 21:21:16 +10:00
parent 4f6ee7cc88
commit 28de550295
7 changed files with 204 additions and 13 deletions
+10 -12
View File
@@ -17,14 +17,6 @@ else
./get_debootstrap --arch i386 sid "$FRESH" http://deb.debian.org/debian/
fi
cleanup_mount() {
if mountpoint "$1" > /dev/null
then
echo "Unmounting $1"
umount "$1"
fi
}
if test -e "$ROOT"
then
echo "Existing installation found at $ROOT, removing."
@@ -35,8 +27,14 @@ echo "Copying $FRESH to $ROOT."
cp -r "$FRESH" "$ROOT"
echo "Initializing $ROOT."
mkdir -p "$ROOT/proc"
mount proc $ROOT/proc -t proc
mkdir -p "$ROOT/sys"
mount sysfs $ROOT/sys -t sysfs
./mountpoints
# Don't bother creating a new tmpfs. We don't want to leak files in, and we
# don't want to waste more RAM on a second tmpfs. The whole thing is
# temporary, after all.
chmod 1777 "$ROOT/tmp"
cp -r install_scripts "$ROOT/root"
chroot "$ROOT" /root/install_scripts/user_setup "$@"
+3 -1
View File
@@ -18,8 +18,10 @@ cleanup_mount() {
if test -e "$ROOT"
then
cleanup_mount "$ROOT/proc"
cleanup_mount "$ROOT/dev/pts"
cleanup_mount "$ROOT/dev"
cleanup_mount "$ROOT/sys"
cleanup_mount "$ROOT/proc"
echo "Removing $ROOT"
rm -r "$ROOT"
else
Vendored Executable
+20
View File
@@ -0,0 +1,20 @@
#!/bin/sh
if test `id -u` -ne 0
then
echo "$0 must be run as root."
return
fi
ROOT=test_environment
if test -e "$ROOT"
then
echo "Using existing environment in $ROOT."
else
./create_environment
fi
./mountpoints
chroot "$ROOT" sudo -iu user "$@"
+3
View File
@@ -0,0 +1,3 @@
#!/bin/sh
sudo apt install erlang-base
wget -q https://zxq9.com/projects/zomp/get_zx && bash get_zx
+25
View File
@@ -0,0 +1,25 @@
#!/bin/bash
# Noninteractive, so that other scripts can install things with apt.
export DEBIAN_FRONTEND=noninteractive
# Overwrite locale setting specified before the chroot
export LANG=C
export LC_ALL=C
# Install sudo, since most user-facing scripts will use sudo
apt install sudo
# Add a passwordless sudoer
useradd -m -s /bin/bash -G sudo user
passwd -d user
echo "user ALL=(ALL) NOPASSWD:ALL" > "/etc/sudoers.d/user"
chmod 0440 "/etc/sudoers.d/user"
# Copy the install scripts into their home directory
cp -r ~/install_scripts /home/user
chown -R user:user /home/user/install_scripts
# su to this new user... Or sudo -iu, since we want to pass in arguments too.
cd /home/user
sudo -iu user "$@"
Vendored Executable
+25
View File
@@ -0,0 +1,25 @@
#!/bin/sh
if test `id -u` -ne 0
then
echo "$0 must be run as root."
return
fi
ROOT=test_environment
check_mount() {
if mountpoint "$ROOT$1" > /dev/null
then
echo "$ROOT$1 already mounted."
else
mkdir -p "$ROOT$1"
mount -o bind "$1" "$ROOT$1"
fi
}
check_mount /proc
check_mount /sys
check_mount /dev
check_mount /dev/pts