shimboot/rootfs/opt/setup_rootfs.sh

105 lines
2.3 KiB
Bash
Raw Normal View History

2023-10-20 05:38:45 -05:00
#!/bin/bash
#setup the debian rootfs
#this is meant to be run within the chroot created by debootstrap
set -e
if [ "$DEBUG" ]; then
set -x
fi
DEBUG="$1"
release_name="$2"
packages="$3"
hostname="$4"
root_passwd="$5"
username="$6"
user_passwd="$7"
2024-05-03 06:59:07 -05:00
enable_root="$8"
disable_base_pkgs="$9"
2024-06-12 00:27:19 -05:00
arch="${10}"
2023-10-20 05:38:45 -05:00
custom_repo="https://shimboot.ading.dev/debian"
2023-10-20 07:04:19 -05:00
custom_repo_domain="shimboot.ading.dev"
2024-06-12 00:27:19 -05:00
sources_entry="deb [trusted=yes arch=$arch] ${custom_repo} ${release_name} main"
2023-10-20 05:38:45 -05:00
2024-05-03 06:59:07 -05:00
export DEBIAN_FRONTEND="noninteractive"
2023-10-20 05:38:45 -05:00
#add shimboot repos
echo -e "${sources_entry}\n$(cat /etc/apt/sources.list)" > /etc/apt/sources.list
tee -a /etc/apt/preferences << END
Package: *
2023-10-20 07:04:19 -05:00
Pin: origin ${custom_repo_domain}
2023-10-20 05:38:45 -05:00
Pin-Priority: 1001
END
#install the patched systemd
apt-get install -y ca-certificates
apt-get update
2023-12-22 00:51:47 -06:00
installed_systemd="$(dpkg-query -W -f='${binary:Package}\n' | grep "systemd")"
2024-06-12 00:27:19 -05:00
apt-get clean
apt-get install -y --reinstall --allow-downgrades $installed_systemd
2023-10-20 05:38:45 -05:00
2023-10-27 15:45:03 -05:00
#enable shimboot services
systemctl enable kill-frecon.service
2024-05-03 06:59:07 -05:00
#install base packages
if [ -z "$disable_base_pkgs" ]; then
apt-get install -y cloud-utils zram-tools sudo command-not-found bash-completion
2023-11-07 14:38:52 -06:00
2024-05-03 06:59:07 -05:00
#set up zram
echo "ALGO=lzo" >> /etc/default/zramswap
echo "PERCENT=50" >> /etc/default/zramswap
#update apt-file cache
apt-file update
fi
2023-10-20 07:39:43 -05:00
2023-10-20 21:30:02 -05:00
#set up hostname and username
if [ ! "$hostname" ]; then
read -p "Enter the hostname for the system: " hostname
fi
2023-10-20 21:30:02 -05:00
echo "${hostname}" > /etc/hostname
tee -a /etc/hosts << END
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
END
2024-05-03 06:59:07 -05:00
#install desktop and other custom packages
apt-get install -y $packages
2023-10-20 07:39:43 -05:00
if [ ! $username ]; then
read -p "Enter the username for the user account: " username
fi
2023-10-20 07:39:43 -05:00
useradd -m -s /bin/bash -G sudo $username
2024-05-03 06:59:07 -05:00
set_password() {
local user="$1"
local password="$2"
if [ ! "$password" ]; then
while ! passwd $user; do
echo "Failed to set password for $user, please try again."
done
else
yes "$password" | passwd $user
fi
}
if [ "$enable_root" ]; then
echo "Enter a root password:"
set_password root "$root_passwd"
else
2024-05-03 06:59:07 -05:00
usermod -a -G sudo $username
fi
2023-10-20 21:30:02 -05:00
2024-05-03 06:59:07 -05:00
echo "Enter a user password:"
set_password "$username" "$user_passwd"
2023-10-20 21:30:02 -05:00
#clean apt caches
apt-get clean