Skip to content

Instantly share code, notes, and snippets.

@tiagoapimenta
Created May 14, 2023 10:18
Show Gist options
  • Select an option

  • Save tiagoapimenta/a900dbc13a3c155e23fc48285b409cd3 to your computer and use it in GitHub Desktop.

Select an option

Save tiagoapimenta/a900dbc13a3c155e23fc48285b409cd3 to your computer and use it in GitHub Desktop.
Lightweight Ubuntu alternatives
#!/bin/sh
# wget -qO- ... | sudo sh -s
set -e
if [ "$(id -u)" != 0 ]; then
exec sudo -- "$0" "$@"
exit 1
fi
if [ ! -d /sys/firmware/efi/efivars ]; then
printf 'Deprecated support to Legacy BIOS.\n' >&2
exit 1
fi
device=$1
target=${2:-/target}
if [ -z "$device" ]; then
printf 'Device: '
read -r device < /dev/tty
fi
if [ "${device##*/}" = "$device" ]; then
device="/dev/$device"
fi
device="$(readlink -f "$device")"
if [ ! -b "$device" -o ! -d "/sys/block/${device##*/}" ]; then
printf 'Invalid device "%s".\n' "$device" >&2
exit 1
fi
if printf '%s' "$device" | egrep -q '[0-9]$'; then
devpart="${device}p"
else
devpart=$device
fi
if [ ! -d "$target" ]; then
mkdir -pv "$target"
fi
sfdisk -f "$device" <<\EOF
label: gpt
table-length: 4
first-lba: 3
3 102400 L
102403 - U
EOF
partprobe "$device"
mkfs.fat -F32 "${devpart}1"
mke2fs -T ext4 -i 65536 "${devpart}2"
mount -v -o noatime "${devpart}2" "$target"
rmdir -v "$target/lost+found"
install -v -o 0 -g 0 -m 755 -d "$target/boot"
install -v -o 0 -g 0 -m 700 -d "$target/boot/efi"
mount -v -o noatime,umask=0077 "${devpart}1" "$target/boot/efi"
if [ ! -x /usr/sbin/debootstrap ]; then
apt-get update
apt-get install -y debootstrap
fi
debootstrap \
--arch=amd64 \
--variant=minbase \
lunar \
"$target" \
http://archive.ubuntu.com/ubuntu/
find \
"$target/tmp" \
"$target/var/tmp" \
"$target/dev" \
"$target/run" \
-maxdepth 1 -mindepth 1 -exec rm -rvf {} +
for point in tmp var/tmp; do
mount -v -t tmpfs -o nodev,nosuid,noatime tmpfs "$target/$point"
done
mount -v -t tmpfs -o noexec,nosuid,mode=0755 tmpfs "$target/run"
for point in dev dev/pts; do
mount -v --bind --make-private "/$point" "$target/$point"
done
mount -v -t sysfs -o nosuid,nodev,noexec sys "$target/sys"
mount -v --bind --make-private "/sys/firmware/efi/efivars" "$target/sys/firmware/efi/efivars"
cp -vfaTL /etc/resolv.conf "$target/etc/resolv.conf"
mount -v -t proc -o nosuid,nodev,noexec none "$target/proc"
uuid_efi=$(blkid -s UUID -o value "${devpart}1")
uuid_root=$(blkid -s UUID -o value "${devpart}2")
install -o 0 -g 0 -m 644 /dev/stdin "$target/etc/fstab" <<EOF
UUID=$uuid_root / ext4 errors=remount-ro,noatime,discard,commit=600 0 1
UUID=$uuid_efi /boot/efi vfat noatime,umask=0077 0 1
EOF
install -o 0 -g 0 -m 644 /dev/stdin "$target/etc/hostname" <<\EOF
vm
EOF
install -o 0 -g 0 -m 644 /dev/stdin "$target/etc/apt/sources.list" <<\EOF
deb http://archive.ubuntu.com/ubuntu/ lunar main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ lunar-updates main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ lunar-backports main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu/ lunar-security main restricted universe multiverse
# deb http://archive.canonical.com/ubuntu/ lunar partner
EOF
install -o 0 -g 0 -m 644 /dev/stdin "$target/etc/apt/apt.conf.d/01-clean" <<\EOF
APT::Install-Recommends "0";
APT::Install-Suggests "0";
APT::Periodic::Enable "0";
Apt::AutoRemove::SuggestsImportant "false";
Unattended-Upgrade::Allowed-Origins:: "LP-PPA-mozillateam:${distro_codename}";
Acquire::GzipIndexes "true";
Acquire::CompressionTypes::Order:: "gz";
DPkg::Post-Invoke { "rm -f /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin || :"; };
APT::Update::Post-Invoke { "rm -f /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin || :"; };
Dir::Cache::pkgcache "";
Dir::Cache::srcpkgcache "";
EOF
install -o 0 -g 0 -m 644 /dev/stdin "$target/etc/apt/preferences.d/snapd" <<\EOF
Package: snapd
Pin: release *
Pin-Priority: -1
EOF
chroot "$target" dpkg --set-selections <<\EOF
snapd hold
EOF
install -o 0 -g 0 -m 644 /dev/stdin "$target/etc/apt/preferences.d/mozilla-firefox" <<\EOF
Package: *
Pin: release o=LP-PPA-mozillateam
Pin-Priority: 1001
EOF
install -o 0 -g 0 -m 644 /dev/stdin "$target/etc/default/locale" <<\EOF
LANG=en_GB.UTF-8
EOF
install -o 0 -g 0 -m 644 /dev/stdin "$target/etc/locale.gen" <<\EOF
en_GB.UTF-8 UTF-8
EOF
install -o 0 -g 0 -m 644 /dev/stdin "$target/etc/timezone" <<\EOF
Europe/Berlin
EOF
ln -vsf /usr/share/zoneinfo/Europe/Berlin "$target/etc/localtime"
# chroot "$target" dpkg-reconfigure tzdata
install -o 0 -g 0 -m 644 /dev/stdin "$target/etc/default/keyboard" <<\EOF
XKBMODEL="pc105"
XKBLAYOUT="de"
XKBVARIANT="deadtilde"
XKBOPTIONS=""
BACKSPACE="guess"
EOF
install -v -o 0 -g 0 -m 755 -d "$target/etc/kernel"
install -v -o 0 -g 0 -m 755 -d "$target/etc/kernel/postinst.d"
install -o 0 -g 0 -m 755 /dev/stdin "$target/etc/kernel/postinst.d/generate-uki" <<\CMDEOF
#!/bin/sh
set -e
kver=$1
tmp=
atexit() {
local ec=$?
if [ -n "$tmp" -a -e "$tmp" ]; then
rm -rf "$tmp"
tmp=
fi
exit $ec
}
trap atexit EXIT INT HUP TERM
tmp=$(mktemp -d)
mkdir -p "$tmp/b" "$tmp/s" "$tmp/.apt/cache" "$tmp/.apt/lists"
apt-get -o "Debug::NoLocking=yes" -o "Dir::Cache=$tmp/.apt/cache" -o "Dir::State::Lists=$tmp/.apt/lists" update
cd "$tmp/b"
apt-get -o "Debug::NoLocking=yes" -o "Dir::Cache=$tmp/.apt/cache" -o "Dir::State::Lists=$tmp/.apt/lists" download busybox-static
find "$tmp/b" -mindepth 1 -maxdepth 1 -type f -name '*.deb' -exec dpkg -x {} "$tmp/s" \;
if [ ! -x /usr/bin/x86_64-linux-gnu-objcopy -o ! -x /bin/cpio ]; then
mkdir "$tmp/d" "$tmp/o"
cd "$tmp/d"
apt-get -o "Debug::NoLocking=yes" -o "Dir::Cache=$tmp/.apt/cache" -o "Dir::State::Lists=$tmp/.apt/lists" download binutils-x86-64-linux-gnu libbinutils cpio
find "$tmp/d" -mindepth 1 -maxdepth 1 -type f -name '*.deb' -exec dpkg -x {} "$tmp/o" \;
export "LD_LIBRARY_PATH=$tmp/o/usr/lib/x86_64-linux-gnu"
export "PATH=$PATH:$tmp/o/usr/bin:$tmp/o/bin"
fi
cat > "$tmp/cmdline" <<EOF
root=PARTUUID=$(blkid -s PARTUUID -o value "$(findmnt -no SOURCE -T /)") ro quiet splash elevator=deadline raid=noautodetect
EOF
mkdir -p "$tmp/i/bin" "$tmp/i/lib/modules/$kver/kernel/drivers/ata"
cp -aT "$tmp/s/bin/busybox" "$tmp/i/bin/busybox"
ln -sfT busybox "$tmp/i/bin/sh"
for file in \
"kernel/drivers/ata/ahci.ko" \
"kernel/drivers/ata/libahci.ko"
do
cp -aT "/lib/modules/$kver/$file" "$tmp/i/lib/modules/$kver/$file"
done
/sbin/depmod -ab "$tmp/i" "$kver"
install -m 755 /dev/stdin "$tmp/i/init" <<\EOF
#!/bin/sh
modprobe ahci
mknod -m 660 /dev/root b 8 2
mkdir /new
/bin/busybox mount -t ext4 -o ro /dev/root /new
exec /bin/busybox switch_root /new /sbin/init
EOF
cd "$tmp/i"
find . | cpio -oH newc -R 0:0 | gzip -9 > "$tmp/initrd"
cd /tmp
if [ ! -d /boot/efi/EFI/boot ]; then
mkdir -p /boot/efi/EFI/boot
fi
x86_64-linux-gnu-objcopy \
--add-section .osrel=/etc/os-release \
--change-section-vma .osrel=0x20000 \
--add-section .cmdline="$tmp/cmdline" \
--change-section-vma .cmdline=0x30000 \
--add-section .splash=/dev/null \
--change-section-vma .splash=0x40000 \
--add-section .linux=/boot/vmlinuz \
--change-section-vma .linux=0x2000000 \
--add-section ".initrd=$tmp/initrd" \
--change-section-vma .initrd=0x3000000 \
/usr/lib/systemd/boot/efi/linuxx64.efi.stub \
/boot/efi/EFI/boot/bootx64.efi
CMDEOF
chroot "$target" apt-get update
DEBIAN_FRONTEND=noninteractive \
chroot "$target" apt-get --no-install-recommends --autoremove --purge -y dist-upgrade
DEBIAN_FRONTEND=noninteractive \
LANG=en_GB.UTF-8 chroot "$target" \
apt-get -y --no-install-recommends --autoremove --purge install \
systemd-boot-efi \
linux-generic-hwe-22.04 \
sudo \
kbd \
tzdata \
netplan.io \
connman \
wpasupplicant \
alsa-base \
pulseaudio \
bash-completion \
ca-certificates \
policykit-1-gnome \
xorg \
lightdm \
lightdm-gtk-greeter \
enlightenment \
terminology \
acpid \
dmz-cursor-theme \
librsvg2-common \
gtk2-engines-pixbuf \
xdg-user-dirs-gtk \
xdg-utils \
fonts-dejavu-core \
fonts-freefont-ttf \
fonts-liberation \
fonts-takao-mincho \
fonts-noto-color-emoji \
libavcodec-extra \
wbritish \
wamerican \
language-pack-gnome-en \
xserver-xorg-video-vesa \
software-properties-common \
gpg-agent
chroot "$target" add-apt-repository -ny ppa:mozillateam/ppa
chroot "$target" apt-get update
DEBIAN_FRONTEND=noninteractive \
chroot "$target" apt-get -y --no-install-recommends --autoremove --purge install \
firefox \
firefox-locale-en \
software-properties-common- \
gpg-agent-
chroot "$target" apt-get autoclean
# rm -rvf "$target/var/lib/apt/lists"
chroot "$target" systemctl disable systemd-timedated
install -o 0 -g 0 -m 644 /dev/stdin "$target/etc/netplan/01-connman.yaml" <<\EOF
network:
version: 2
renderer: connman
EOF
install -o 0 -g 0 -m 644 /dev/stdin "$target/etc/sudoers.d/nofqdn" <<\EOF
Defaults !fqdn
EOF
chroot "$target" useradd -m -U -G 'adm,cdrom,sudo,dip,plugdev' -p 'ZZvIHp4MBMwSE' -s '/bin/bash' -c 'Pepper,,,' pepper
install -o 0 -g 0 -m 644 /dev/stdin "$target/etc/lightdm/lightdm.conf.d/autologin.conf" <<\EOF
[Seat:*]
autologin-guest=false
autologin-user=pepper
autologin-user-timeout=0
EOF
umount -vR "$target"
# reboot
#!/bin/sh
# wget -qO- ... | sudo sh -s
set -e
if [ "$(id -u)" != 0 ]; then
exec sudo -- "$0" "$@"
exit 1
fi
if [ ! -d /sys/firmware/efi/efivars ]; then
printf 'Deprecated support to Legacy BIOS.\n' >&2
exit 1
fi
device=$1
target=${2:-/target}
if [ -z "$device" ]; then
printf 'Device: '
read -r device < /dev/tty
fi
if [ "${device##*/}" = "$device" ]; then
device="/dev/$device"
fi
device="$(readlink -f "$device")"
if [ ! -b "$device" -o ! -d "/sys/block/${device##*/}" ]; then
printf 'Invalid device "%s".\n' "$device" >&2
exit 1
fi
if printf '%s' "$device" | egrep -q '[0-9]$'; then
devpart="${device}p"
else
devpart=$device
fi
if [ ! -d "$target" ]; then
mkdir -pv "$target"
fi
sfdisk -f "$device" <<\EOF
label: gpt
table-length: 4
first-lba: 3
3 102400 L
102403 - U
EOF
partprobe "$device"
mkfs.fat -F32 "${devpart}1"
mke2fs -T ext4 -i 65536 "${devpart}2"
mount -v -o noatime "${devpart}2" "$target"
rmdir -v "$target/lost+found"
install -v -o 0 -g 0 -m 755 -d "$target/boot"
install -v -o 0 -g 0 -m 700 -d "$target/boot/efi"
mount -v -o noatime,umask=0077 "${devpart}1" "$target/boot/efi"
if [ ! -x /usr/sbin/debootstrap ]; then
apt-get update
apt-get install -y debootstrap
fi
debootstrap \
--arch=amd64 \
--variant=minbase \
lunar \
"$target" \
http://archive.ubuntu.com/ubuntu/
find \
"$target/tmp" \
"$target/var/tmp" \
"$target/dev" \
"$target/run" \
-maxdepth 1 -mindepth 1 -exec rm -rvf {} +
for point in tmp var/tmp; do
mount -v -t tmpfs -o nodev,nosuid,noatime tmpfs "$target/$point"
done
mount -v -t tmpfs -o noexec,nosuid,mode=0755 tmpfs "$target/run"
for point in dev dev/pts; do
mount -v --bind --make-private "/$point" "$target/$point"
done
mount -v -t sysfs -o nosuid,nodev,noexec sys "$target/sys"
mount -v --bind --make-private "/sys/firmware/efi/efivars" "$target/sys/firmware/efi/efivars"
cp -vfaTL /etc/resolv.conf "$target/etc/resolv.conf"
mount -v -t proc -o nosuid,nodev,noexec none "$target/proc"
uuid_efi=$(blkid -s UUID -o value "${devpart}1")
uuid_root=$(blkid -s UUID -o value "${devpart}2")
install -o 0 -g 0 -m 644 /dev/stdin "$target/etc/fstab" <<EOF
UUID=$uuid_root / ext4 errors=remount-ro,noatime,discard,commit=600 0 1
UUID=$uuid_efi /boot/efi vfat noatime,umask=0077 0 1
EOF
install -o 0 -g 0 -m 644 /dev/stdin "$target/etc/hostname" <<\EOF
vm
EOF
install -o 0 -g 0 -m 644 /dev/stdin "$target/etc/apt/sources.list" <<\EOF
deb http://archive.ubuntu.com/ubuntu/ lunar main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ lunar-updates main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ lunar-backports main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu/ lunar-security main restricted universe multiverse
# deb http://archive.canonical.com/ubuntu/ lunar partner
EOF
install -o 0 -g 0 -m 644 /dev/stdin "$target/etc/apt/apt.conf.d/01-clean" <<\EOF
APT::Install-Recommends "0";
APT::Install-Suggests "0";
APT::Periodic::Enable "0";
Apt::AutoRemove::SuggestsImportant "false";
Unattended-Upgrade::Allowed-Origins:: "LP-PPA-mozillateam:${distro_codename}";
Acquire::GzipIndexes "true";
Acquire::CompressionTypes::Order:: "gz";
DPkg::Post-Invoke { "rm -f /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin || :"; };
APT::Update::Post-Invoke { "rm -f /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin || :"; };
Dir::Cache::pkgcache "";
Dir::Cache::srcpkgcache "";
EOF
install -o 0 -g 0 -m 644 /dev/stdin "$target/etc/apt/preferences.d/snapd" <<\EOF
Package: snapd
Pin: release *
Pin-Priority: -1
EOF
chroot "$target" dpkg --set-selections <<\EOF
snapd hold
EOF
install -o 0 -g 0 -m 644 /dev/stdin "$target/etc/apt/preferences.d/mozilla-firefox" <<\EOF
Package: *
Pin: release o=LP-PPA-mozillateam
Pin-Priority: 1001
EOF
install -o 0 -g 0 -m 644 /dev/stdin "$target/etc/default/locale" <<\EOF
LANG=en_GB.UTF-8
EOF
install -o 0 -g 0 -m 644 /dev/stdin "$target/etc/locale.gen" <<\EOF
en_GB.UTF-8 UTF-8
EOF
install -o 0 -g 0 -m 644 /dev/stdin "$target/etc/timezone" <<\EOF
Europe/Berlin
EOF
ln -vsf /usr/share/zoneinfo/Europe/Berlin "$target/etc/localtime"
# chroot "$target" dpkg-reconfigure tzdata
install -o 0 -g 0 -m 644 /dev/stdin "$target/etc/default/keyboard" <<\EOF
XKBMODEL="pc105"
XKBLAYOUT="de"
XKBVARIANT="deadtilde"
XKBOPTIONS=""
BACKSPACE="guess"
EOF
install -v -o 0 -g 0 -m 755 -d "$target/etc/kernel"
install -v -o 0 -g 0 -m 755 -d "$target/etc/kernel/postinst.d"
install -o 0 -g 0 -m 755 /dev/stdin "$target/etc/kernel/postinst.d/generate-uki" <<\CMDEOF
#!/bin/sh
set -e
kver=$1
tmp=
atexit() {
local ec=$?
if [ -n "$tmp" -a -e "$tmp" ]; then
rm -rf "$tmp"
tmp=
fi
exit $ec
}
trap atexit EXIT INT HUP TERM
tmp=$(mktemp -d)
mkdir -p "$tmp/b" "$tmp/s" "$tmp/.apt/cache" "$tmp/.apt/lists"
apt-get -o "Debug::NoLocking=yes" -o "Dir::Cache=$tmp/.apt/cache" -o "Dir::State::Lists=$tmp/.apt/lists" update
cd "$tmp/b"
apt-get -o "Debug::NoLocking=yes" -o "Dir::Cache=$tmp/.apt/cache" -o "Dir::State::Lists=$tmp/.apt/lists" download busybox-static
find "$tmp/b" -mindepth 1 -maxdepth 1 -type f -name '*.deb' -exec dpkg -x {} "$tmp/s" \;
if [ ! -x /usr/bin/x86_64-linux-gnu-objcopy -o ! -x /bin/cpio ]; then
mkdir "$tmp/d" "$tmp/o"
cd "$tmp/d"
apt-get -o "Debug::NoLocking=yes" -o "Dir::Cache=$tmp/.apt/cache" -o "Dir::State::Lists=$tmp/.apt/lists" download binutils-x86-64-linux-gnu libbinutils cpio
find "$tmp/d" -mindepth 1 -maxdepth 1 -type f -name '*.deb' -exec dpkg -x {} "$tmp/o" \;
export "LD_LIBRARY_PATH=$tmp/o/usr/lib/x86_64-linux-gnu"
export "PATH=$PATH:$tmp/o/usr/bin:$tmp/o/bin"
fi
cat > "$tmp/cmdline" <<EOF
root=PARTUUID=$(blkid -s PARTUUID -o value "$(findmnt -no SOURCE -T /)") ro quiet splash elevator=deadline raid=noautodetect
EOF
mkdir -p "$tmp/i/bin" "$tmp/i/lib/modules/$kver/kernel/drivers/ata"
cp -aT "$tmp/s/bin/busybox" "$tmp/i/bin/busybox"
ln -sfT busybox "$tmp/i/bin/sh"
for file in \
"kernel/drivers/ata/ahci.ko" \
"kernel/drivers/ata/libahci.ko"
do
cp -aT "/lib/modules/$kver/$file" "$tmp/i/lib/modules/$kver/$file"
done
/sbin/depmod -ab "$tmp/i" "$kver"
install -m 755 /dev/stdin "$tmp/i/init" <<\EOF
#!/bin/sh
modprobe ahci
mknod -m 660 /dev/root b 8 2
mkdir /new
/bin/busybox mount -t ext4 -o ro /dev/root /new
exec /bin/busybox switch_root /new /sbin/init
EOF
cd "$tmp/i"
find . | cpio -oH newc -R 0:0 | gzip -9 > "$tmp/initrd"
cd /tmp
if [ ! -d /boot/efi/EFI/boot ]; then
mkdir -p /boot/efi/EFI/boot
fi
x86_64-linux-gnu-objcopy \
--add-section .osrel=/etc/os-release \
--change-section-vma .osrel=0x20000 \
--add-section .cmdline="$tmp/cmdline" \
--change-section-vma .cmdline=0x30000 \
--add-section .splash=/dev/null \
--change-section-vma .splash=0x40000 \
--add-section .linux=/boot/vmlinuz \
--change-section-vma .linux=0x2000000 \
--add-section ".initrd=$tmp/initrd" \
--change-section-vma .initrd=0x3000000 \
/usr/lib/systemd/boot/efi/linuxx64.efi.stub \
/boot/efi/EFI/boot/bootx64.efi
CMDEOF
chroot "$target" apt-get update
DEBIAN_FRONTEND=noninteractive \
chroot "$target" apt-get --no-install-recommends --autoremove --purge -y dist-upgrade
DEBIAN_FRONTEND=noninteractive \
LANG=en_GB.UTF-8 chroot "$target" \
apt-get -y --no-install-recommends --autoremove --purge install \
systemd-boot-efi \
linux-generic-hwe-22.04 \
sudo \
kbd \
tzdata \
netplan.io \
connman-gtk \
wpasupplicant \
alsa-base \
pulseaudio \
pavucontrol \
bash-completion \
ca-certificates \
policykit-1-gnome \
xorg \
lightdm \
lightdm-gtk-greeter \
lxde \
dmz-cursor-theme \
librsvg2-common \
gtk2-engines-pixbuf \
xdg-user-dirs-gtk \
xdg-utils \
fonts-dejavu-core \
fonts-freefont-ttf \
fonts-liberation \
fonts-takao-mincho \
fonts-noto-color-emoji \
libavcodec-extra \
wbritish \
wamerican \
language-pack-gnome-en \
xserver-xorg-video-vesa \
software-properties-common \
gpg-agent
chroot "$target" add-apt-repository -ny ppa:mozillateam/ppa
chroot "$target" apt-get update
DEBIAN_FRONTEND=noninteractive \
chroot "$target" apt-get -y --no-install-recommends --autoremove --purge install \
firefox \
firefox-locale-en \
software-properties-common- \
gpg-agent-
chroot "$target" apt-get autoclean
# rm -rvf "$target/var/lib/apt/lists"
chroot "$target" systemctl disable systemd-timedated
install -o 0 -g 0 -m 644 /dev/stdin "$target/etc/netplan/01-connman.yaml" <<\EOF
network:
version: 2
renderer: connman
EOF
install -o 0 -g 0 -m 644 /dev/stdin "$target/etc/sudoers.d/nofqdn" <<\EOF
Defaults !fqdn
EOF
#mkdir -pv "$target/etc/skel/.config/openbox"
#sed '/debian-menu\.xml/d' "$target/etc/xdg/openbox/rc.xml" > "$target/etc/skel/.config/openbox/rc.xml"
chroot "$target" useradd -m -U -G 'adm,cdrom,sudo,dip,plugdev' -p 'ZZvIHp4MBMwSE' -s '/bin/bash' -c 'Pepper,,,' pepper
install -o 0 -g 0 -m 644 /dev/stdin "$target/etc/lightdm/lightdm.conf.d/autologin.conf" <<\EOF
[Seat:*]
autologin-guest=false
autologin-user=pepper
autologin-user-timeout=0
EOF
umount -vR "$target"
# reboot
#!/bin/sh
set -e
if [ "$(id -u)" != 0 ]; then
exec sudo -- "$0" "$@"
exit 1
fi
install -o 0 -g 0 -m 644 /dev/stdin /etc/xdg/autostart/ui-test.desktop <<\EOF
[Desktop Entry]
Version=1.0
Name=UI-Test
Exec=/usr/local/bin/ui-test
Terminal=false
Type=Application
EOF
install -o 0 -g 0 -m 755 /dev/stdin /usr/local/bin/ui-test-terminal <<\EOF
#!/bin/sh
set -e
sleep 5
wid=$(xdotool getactivewindow)
if [ -e /usr/bin/gnome-shell ]; then
gnome-shell --version
elif [ -e /usr/bin/plasmashell ]; then
plasmashell --version
elif [ -e /usr/bin/lxqt-about ]; then
lxqt-about --version
elif [ -e /usr/bin/xfce4-panel ]; then
if [ -e /usr/bin/xfce4-about ]; then
xfce4-about --version
else
xfce4-panel --version
fi
if [ -e /usr/bin/openbox ]; then
openbox --version
fi
elif [ -e /usr/bin/mate-about ]; then
mate-about --version
elif [ -e /usr/bin/unity ]; then
unity --version
elif [ -e /usr/bin/cinnamon ]; then
cinnamon --version
elif [ -e /usr/bin/lxpanel ]; then
lxpanel --version
openbox --version
elif [ -e /usr/bin/enlightenment ]; then
enlightenment -version || :
else
printf 'Unknown desktop\n' >&2
fi
sleep 5
for y in $(seq 100 20 200); do
for x in $(seq 150 50 500) $(seq 450 -50 100); do
xdotool windowmove --sync -- "$wid" "$x" "$y"
sleep 0.05
done
done
sleep 5
EOF
install -o 0 -g 0 -m 755 /dev/stdin /usr/local/bin/ui-test <<\EOF
#!/bin/sh
set -e
sleep 10
x-terminal-emulator -e '/usr/local/bin/ui-test-terminal' || :
sleep 5
nohup setsid gtk3-widget-factory > /dev/null 2>&1 &
sleep 5
wid=$(xdotool search --onlyvisible --name gtk3-widget-factory)
xdotool windowfocus "$wid"
sleep 1
for y in $(seq 0 10 50); do
for x in $(seq -40 10 100) $(seq 90 -10 -50); do
timeout 0.05s xdotool windowmove --sync -- "$wid" "$x" "$y" || :
sleep 0.01
done
done
sleep 1
x=-10
y=-10
if [ -e /usr/bin/plasmashell ]; then
x=-100
y=-50
fi
xdotool windowfocus "$wid" windowmove --sync -- "$wid" "$x" "$y"
sleep 5
for i in 1 0.5; do
for s in $(seq 1 5); do
xdotool windowminimize --sync "$wid"
sleep "$i"
xdotool windowunmap --sync "$wid" windowmap --sync "$wid" windowactivate --sync "$wid"
sleep "$i"
xdotool search --onlyvisible --sync --name gtk3-widget-factory
done
done
sleep 1
xdotool windowactivate "$wid"
sleep 5
# TODO: maximize???
# sleep 5
geo=$(xdotool getwindowgeometry "$wid" | awk '$1 == "Geometry:" { print $2; exit }')
x=${geo%x*}
y=${geo#*x}
for s in $(seq 1 5); do
for n in $(seq 0 5 100) $(seq 100 -5 0); do
timeout 0.05s xdotool windowsize --sync -- "$wid" "$((x + n))" "$((y + n))" || :
sleep 0.01
done
done
sleep 5
xdotool windowkill "$wid"
sleep 5
systemctl poweroff
EOF
home=$(getent passwd "$SUDO_USER" | cut -d: -f6)
uid=$(id -u "$SUDO_USER")
gid=$(id -u "$SUDO_USER")
if [ -e /usr/bin/enlightenment ]; then
install -o "$uid" -g "$gid" -m 644 /dev/stdin "$home/.e/e/applications/startup/.order" <<\EOF
/etc/xdg/autostart/ui-test.desktop
EOF
elif [ -e /usr/bin/gnome-shell ]; then
# TODO: automate install https://github.com/ickyicky/window-calls
install -o 0 -g 0 -m 755 /dev/stdin /usr/local/bin/xdotool <<\EOF
#!/bin/sh
set -e
while [ $# -gt 0 ]; do
case "$1" in
getactivewindow)
gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell/Extensions/Windows --method org.gnome.Shell.Extensions.Windows.List | sed -r 's@^\(.(.*).,\)$@\1@' | jq -c '.[] | select (.focus == true) | .id'
;;
windowfocus|windowactivate)
while [ "$2" = --sync -o "$2" = -- ]; do
shift
done
gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell/Extensions/Windows --method org.gnome.Shell.Extensions.Windows.Activate "$2" > /dev/null
shift
;;
windowminimize|windowunmap)
while [ "$2" = --sync -o "$2" = -- ]; do
shift
done
gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell/Extensions/Windows --method org.gnome.Shell.Extensions.Windows.Minimize "$2" > /dev/null
shift
;;
windowmap)
while [ "$2" = --sync -o "$2" = -- ]; do
shift
done
gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell/Extensions/Windows --method org.gnome.Shell.Extensions.Windows.Unminimize "$2" > /dev/null
shift
;;
windowkill)
gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell/Extensions/Windows --method org.gnome.Shell.Extensions.Windows.Close "$2" > /dev/null
shift
;;
windowmove)
while [ "$2" = --sync -o "$2" = -- ]; do
shift
done
gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell/Extensions/Windows --method org.gnome.Shell.Extensions.Windows.Move -- "$2" "$3" "$4" > /dev/null
shift 3
;;
windowsize)
while [ "$2" = --sync -o "$2" = -- ]; do
shift
done
gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell/Extensions/Windows --method org.gnome.Shell.Extensions.Windows.MoveResize -- "$2" 0 0 "$3" "$4" > /dev/null
shift 3
;;
getwindowgeometry)
gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell/Extensions/Windows --method org.gnome.Shell.Extensions.Windows.List | sed -r 's@^\(.(.*).,\)$@\1@' | jq --arg id "$2" -rc '.[] | select (.id == ($id | tonumber)) | "Geometry: \(.width)x\(.height)"'
shift
;;
search)
while [ "$2" = --sync -o "$2" = --onlyvisible -o "$2" = --name -o "$2" = -- ]; do
shift
done
name=$2
shift
while :; do
out=$(gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell/Extensions/Windows --method org.gnome.Shell.Extensions.Windows.List | sed -r 's@^\(.(.*).,\)$@\1@' | jq --arg name "$name" -rc '.[] | select (.wm_class | contains($name)) | .id')
if [ -n "$out" ]; then
break
else
sleep 0.5
fi
done
printf '%s\n' "$out"
;;
esac
if ! shift; then
break
fi
done
EOF
fi
apt-get install -y gtk-3-examples xdotool
install -o 0 -g 0 -m 644 /dev/stdin /etc/sudoers.d/nopass <<EOF
$SUDO_USER ALL=(ALL:ALL) NOPASSWD: ALL
EOF
#!/bin/sh
# wget -qO- ... | sudo sh -s
set -e
if [ "$(id -u)" != 0 ]; then
exec sudo -- "$0" "$@"
exit 1
fi
if [ ! -d /sys/firmware/efi/efivars ]; then
printf 'Deprecated support to Legacy BIOS.\n' >&2
exit 1
fi
device=$1
target=${2:-/target}
if [ -z "$device" ]; then
printf 'Device: '
read -r device < /dev/tty
fi
if [ "${device##*/}" = "$device" ]; then
device="/dev/$device"
fi
device="$(readlink -f "$device")"
if [ ! -b "$device" -o ! -d "/sys/block/${device##*/}" ]; then
printf 'Invalid device "%s".\n' "$device" >&2
exit 1
fi
if printf '%s' "$device" | egrep -q '[0-9]$'; then
devpart="${device}p"
else
devpart=$device
fi
if [ ! -d "$target" ]; then
mkdir -pv "$target"
fi
sfdisk -f "$device" <<\EOF
label: gpt
table-length: 4
first-lba: 3
3 102400 L
102403 - U
EOF
partprobe "$device"
mkfs.fat -F32 "${devpart}1"
mke2fs -T ext4 -i 65536 "${devpart}2"
mount -v -o noatime "${devpart}2" "$target"
rmdir -v "$target/lost+found"
install -v -o 0 -g 0 -m 755 -d "$target/boot"
install -v -o 0 -g 0 -m 700 -d "$target/boot/efi"
mount -v -o noatime,umask=0077 "${devpart}1" "$target/boot/efi"
if [ ! -x /usr/sbin/debootstrap ]; then
apt-get update
apt-get install -y debootstrap
fi
debootstrap \
--arch=amd64 \
--variant=minbase \
lunar \
"$target" \
http://archive.ubuntu.com/ubuntu/
find \
"$target/tmp" \
"$target/var/tmp" \
"$target/dev" \
"$target/run" \
-maxdepth 1 -mindepth 1 -exec rm -rvf {} +
for point in tmp var/tmp; do
mount -v -t tmpfs -o nodev,nosuid,noatime tmpfs "$target/$point"
done
mount -v -t tmpfs -o noexec,nosuid,mode=0755 tmpfs "$target/run"
for point in dev dev/pts; do
mount -v --bind --make-private "/$point" "$target/$point"
done
mount -v -t sysfs -o nosuid,nodev,noexec sys "$target/sys"
mount -v --bind --make-private "/sys/firmware/efi/efivars" "$target/sys/firmware/efi/efivars"
cp -vfaTL /etc/resolv.conf "$target/etc/resolv.conf"
mount -v -t proc -o nosuid,nodev,noexec none "$target/proc"
uuid_efi=$(blkid -s UUID -o value "${devpart}1")
uuid_root=$(blkid -s UUID -o value "${devpart}2")
install -o 0 -g 0 -m 644 /dev/stdin "$target/etc/fstab" <<EOF
UUID=$uuid_root / ext4 errors=remount-ro,noatime,discard,commit=600 0 1
UUID=$uuid_efi /boot/efi vfat noatime,umask=0077 0 1
EOF
install -o 0 -g 0 -m 644 /dev/stdin "$target/etc/hostname" <<\EOF
vm
EOF
install -o 0 -g 0 -m 644 /dev/stdin "$target/etc/apt/sources.list" <<\EOF
deb http://archive.ubuntu.com/ubuntu/ lunar main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ lunar-updates main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu/ lunar-backports main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu/ lunar-security main restricted universe multiverse
# deb http://archive.canonical.com/ubuntu/ lunar partner
EOF
install -o 0 -g 0 -m 644 /dev/stdin "$target/etc/apt/apt.conf.d/01-clean" <<\EOF
APT::Install-Recommends "0";
APT::Install-Suggests "0";
APT::Periodic::Enable "0";
Apt::AutoRemove::SuggestsImportant "false";
Unattended-Upgrade::Allowed-Origins:: "LP-PPA-mozillateam:${distro_codename}";
Acquire::GzipIndexes "true";
Acquire::CompressionTypes::Order:: "gz";
DPkg::Post-Invoke { "rm -f /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin || :"; };
APT::Update::Post-Invoke { "rm -f /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin || :"; };
Dir::Cache::pkgcache "";
Dir::Cache::srcpkgcache "";
EOF
install -o 0 -g 0 -m 644 /dev/stdin "$target/etc/apt/preferences.d/snapd" <<\EOF
Package: snapd
Pin: release *
Pin-Priority: -1
EOF
chroot "$target" dpkg --set-selections <<\EOF
snapd hold
EOF
install -o 0 -g 0 -m 644 /dev/stdin "$target/etc/apt/preferences.d/mozilla-firefox" <<\EOF
Package: *
Pin: release o=LP-PPA-mozillateam
Pin-Priority: 1001
EOF
install -o 0 -g 0 -m 644 /dev/stdin "$target/etc/default/locale" <<\EOF
LANG=en_GB.UTF-8
EOF
install -o 0 -g 0 -m 644 /dev/stdin "$target/etc/locale.gen" <<\EOF
en_GB.UTF-8 UTF-8
EOF
install -o 0 -g 0 -m 644 /dev/stdin "$target/etc/timezone" <<\EOF
Europe/Berlin
EOF
ln -vsf /usr/share/zoneinfo/Europe/Berlin "$target/etc/localtime"
# chroot "$target" dpkg-reconfigure tzdata
install -o 0 -g 0 -m 644 /dev/stdin "$target/etc/default/keyboard" <<\EOF
XKBMODEL="pc105"
XKBLAYOUT="de"
XKBVARIANT="deadtilde"
XKBOPTIONS=""
BACKSPACE="guess"
EOF
install -v -o 0 -g 0 -m 755 -d "$target/etc/kernel"
install -v -o 0 -g 0 -m 755 -d "$target/etc/kernel/postinst.d"
install -o 0 -g 0 -m 755 /dev/stdin "$target/etc/kernel/postinst.d/generate-uki" <<\CMDEOF
#!/bin/sh
set -e
kver=$1
tmp=
atexit() {
local ec=$?
if [ -n "$tmp" -a -e "$tmp" ]; then
rm -rf "$tmp"
tmp=
fi
exit $ec
}
trap atexit EXIT INT HUP TERM
tmp=$(mktemp -d)
mkdir -p "$tmp/b" "$tmp/s" "$tmp/.apt/cache" "$tmp/.apt/lists"
apt-get -o "Debug::NoLocking=yes" -o "Dir::Cache=$tmp/.apt/cache" -o "Dir::State::Lists=$tmp/.apt/lists" update
cd "$tmp/b"
apt-get -o "Debug::NoLocking=yes" -o "Dir::Cache=$tmp/.apt/cache" -o "Dir::State::Lists=$tmp/.apt/lists" download busybox-static
find "$tmp/b" -mindepth 1 -maxdepth 1 -type f -name '*.deb' -exec dpkg -x {} "$tmp/s" \;
if [ ! -x /usr/bin/x86_64-linux-gnu-objcopy -o ! -x /bin/cpio ]; then
mkdir "$tmp/d" "$tmp/o"
cd "$tmp/d"
apt-get -o "Debug::NoLocking=yes" -o "Dir::Cache=$tmp/.apt/cache" -o "Dir::State::Lists=$tmp/.apt/lists" download binutils-x86-64-linux-gnu libbinutils cpio
find "$tmp/d" -mindepth 1 -maxdepth 1 -type f -name '*.deb' -exec dpkg -x {} "$tmp/o" \;
export "LD_LIBRARY_PATH=$tmp/o/usr/lib/x86_64-linux-gnu"
export "PATH=$PATH:$tmp/o/usr/bin:$tmp/o/bin"
fi
cat > "$tmp/cmdline" <<EOF
root=PARTUUID=$(blkid -s PARTUUID -o value "$(findmnt -no SOURCE -T /)") ro quiet splash elevator=deadline raid=noautodetect
EOF
mkdir -p "$tmp/i/bin" "$tmp/i/lib/modules/$kver/kernel/drivers/ata"
cp -aT "$tmp/s/bin/busybox" "$tmp/i/bin/busybox"
ln -sfT busybox "$tmp/i/bin/sh"
for file in \
"kernel/drivers/ata/ahci.ko" \
"kernel/drivers/ata/libahci.ko"
do
cp -aT "/lib/modules/$kver/$file" "$tmp/i/lib/modules/$kver/$file"
done
/sbin/depmod -ab "$tmp/i" "$kver"
install -m 755 /dev/stdin "$tmp/i/init" <<\EOF
#!/bin/sh
modprobe ahci
mknod -m 660 /dev/root b 8 2
mkdir /new
/bin/busybox mount -t ext4 -o ro /dev/root /new
exec /bin/busybox switch_root /new /sbin/init
EOF
cd "$tmp/i"
find . | cpio -oH newc -R 0:0 | gzip -9 > "$tmp/initrd"
cd /tmp
if [ ! -d /boot/efi/EFI/boot ]; then
mkdir -p /boot/efi/EFI/boot
fi
x86_64-linux-gnu-objcopy \
--add-section .osrel=/etc/os-release \
--change-section-vma .osrel=0x20000 \
--add-section .cmdline="$tmp/cmdline" \
--change-section-vma .cmdline=0x30000 \
--add-section .splash=/dev/null \
--change-section-vma .splash=0x40000 \
--add-section .linux=/boot/vmlinuz \
--change-section-vma .linux=0x2000000 \
--add-section ".initrd=$tmp/initrd" \
--change-section-vma .initrd=0x3000000 \
/usr/lib/systemd/boot/efi/linuxx64.efi.stub \
/boot/efi/EFI/boot/bootx64.efi
CMDEOF
chroot "$target" apt-get update
DEBIAN_FRONTEND=noninteractive \
chroot "$target" apt-get --no-install-recommends --autoremove --purge -y dist-upgrade
DEBIAN_FRONTEND=noninteractive \
LANG=en_GB.UTF-8 chroot "$target" \
apt-get -y --no-install-recommends --autoremove --purge install \
systemd-boot-efi \
linux-generic-hwe-22.04 \
sudo \
kbd \
tzdata \
netplan.io \
network-manager-gnome \
wpasupplicant \
alsa-base \
pulseaudio \
pavucontrol \
bash-completion \
ca-certificates \
policykit-1-gnome \
xorg \
lightdm \
xubuntu-default-settings \
openbox \
obconf \
dmz-cursor-theme \
librsvg2-common \
gtk2-engines-pixbuf \
xdg-user-dirs-gtk \
xdg-utils \
thunar \
xfce4-appfinder \
xfce4-notifyd \
xfce4-panel \
xfce4-whiskermenu-plugin \
xfce4-power-manager-plugins \
xfce4-pulseaudio-plugin \
xfce4-terminal \
suckless-tools \
fonts-dejavu-core \
fonts-freefont-ttf \
fonts-liberation \
fonts-takao-mincho \
fonts-noto-color-emoji \
libavcodec-extra \
wbritish \
wamerican \
language-pack-gnome-en \
xserver-xorg-video-vesa \
software-properties-common \
gpg-agent
chroot "$target" add-apt-repository -ny ppa:mozillateam/ppa
chroot "$target" apt-get update
DEBIAN_FRONTEND=noninteractive \
chroot "$target" apt-get -y --no-install-recommends --autoremove --purge install \
firefox \
firefox-locale-en \
software-properties-common- \
gpg-agent-
chroot "$target" apt-get autoclean
# rm -rvf "$target/var/lib/apt/lists"
chroot "$target" systemctl disable systemd-timedated
install -o 0 -g 0 -m 644 /dev/stdin "$target/etc/netplan/01-network-manager-all.yaml" <<\EOF
# Let NetworkManager manage all devices on this system
network:
version: 2
renderer: NetworkManager
EOF
install -o 0 -g 0 -m 644 /dev/stdin "$target/etc/sudoers.d/nofqdn" <<\EOF
Defaults !fqdn
EOF
mkdir -pv "$target/etc/skel/.config/openbox"
sed '/debian-menu\.xml/d' "$target/etc/xdg/openbox/rc.xml" > "$target/etc/skel/.config/openbox/rc.xml"
mkdir -pv "$target/etc/skel/.config/xfce4/xfconf/xfce-perchannel-xml"
sed 's@"xfwm4"@"openbox"@;/<property name="general"/a\ <property name="SaveOnExit" type="bool" value="false" />' "$target/etc/xdg/xfce4/xfconf/xfce-perchannel-xml/xfce4-session.xml" > "$target/etc/skel/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-session.xml"
chroot "$target" useradd -m -U -G 'adm,cdrom,sudo,dip,plugdev' -p 'ZZvIHp4MBMwSE' -s '/bin/bash' -c 'Pepper,,,' pepper
install -o 0 -g 0 -m 644 /dev/stdin "$target/etc/lightdm/lightdm.conf.d/autologin.conf" <<\EOF
[Seat:*]
autologin-guest=false
autologin-user=pepper
autologin-user-timeout=0
EOF
umount -vR "$target"
# reboot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment