Skip to content

Commit

Permalink
add experimental alpine linux support
Browse files Browse the repository at this point in the history
  • Loading branch information
ading2210 committed Jun 22, 2024
1 parent 91486b0 commit 752462d
Show file tree
Hide file tree
Showing 5 changed files with 170 additions and 18 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ Debian Sid (the rolling release version of Debian) is also supported if you just
sudo ./build_complete.sh dedede release=unstable
```

There is also experimental support for Alpine Linux. Pass the `distro=alpine` to use it:
```bash
sudo ./build_complete.sh dedede distro=alpine
```

#### How can I install a desktop environment other than XFCE?
You can pass the `desktop` argument to the `build_complete.sh` script, like this:
```bash
Expand Down
20 changes: 16 additions & 4 deletions build_complete.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ print_help() {
echo " data_dir - The working directory for the scripts. This defaults to ./data"
echo " arch - The CPU architecture to build the shimboot image for. Set this to 'arm64' if you have an ARM Chromebook."
echo " release - Set this to either 'bookworm' or 'unstable' to build for Debian stable/unstable."
echo " distro - The Linux distro to use. This should be either 'debian' or 'alpine'."
}

assert_root
Expand All @@ -29,7 +30,8 @@ quiet="${args['quiet']}"
desktop="${args['desktop']-'xfce'}"
data_dir="${args['data_dir']}"
arch="${args['arch']-amd64}"
release="${args['release']-bookworm}"
release="${args['release']}"
distro="${args['distro']-debian}"

arm_boards="
corsola hana jacuzzi kukui strongbad nyan-big kevin bob
Expand Down Expand Up @@ -134,22 +136,32 @@ download_and_unzip $reco_url $reco_zip $reco_bin
print_title "downloading shim image"
download_and_unzip $shim_url $shim_zip $shim_bin

print_title "building $distro rootfs"
if [ ! "$rootfs_dir" ]; then
rootfs_dir="$(realpath -m data/rootfs_$board)"
desktop_package="task-$desktop-desktop"
rootfs_dir="$(realpath -m data/rootfs_$board)"
if [ "$(findmnt -T "$rootfs_dir/dev")" ]; then
sudo umount -l $rootfs_dir/* 2>/dev/null || true
fi
rm -rf $rootfs_dir
mkdir -p $rootfs_dir

print_title "building debian rootfs"
if [ "$distro" = "debian" ]; then
release="${release:-bookworm}"
elif [ "$distro" = "alpine" ]; then
release="${release:-latest-stable}"
else
print_error "invalid distro selection"
exit 1
fi

./build_rootfs.sh $rootfs_dir $release \
custom_packages=$desktop_package \
hostname=shimboot-$board \
username=user \
user_passwd=user \
arch=$arch
arch=$arch \
distro=$distro
fi

print_title "patching debian rootfs"
Expand Down
61 changes: 48 additions & 13 deletions build_rootfs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@

#build the debian rootfs

set -e
if [ "$DEBUG" ]; then
set -x
fi

. ./common.sh

print_help() {
Expand All @@ -20,18 +15,20 @@ print_help() {
echo " user_passwd - The password for the unprivileged user."
echo " disable_base - Disable the base packages such as zram, cloud-utils, and command-not-found."
echo " arch - The CPU architecture to build the rootfs for."
echo " distro - The Linux distro to use. This should be either 'debian' or 'alpine'."
echo "If you do not specify the hostname and credentials, you will be prompted for them later."
}

assert_root
assert_deps "realpath debootstrap findmnt"
assert_deps "realpath debootstrap findmnt wget pcregrep tar"
assert_args "$2"
parse_args "$@"

rootfs_dir=$(realpath -m "${1}")
release_name="${2}"
packages="${args['custom_packages']-'task-xfce-desktop'}"
packages="${args['custom_packages']-task-xfce-desktop}"
arch="${args['arch']-amd64}"
distro="${args['distro']-debian}"
chroot_mounts="proc sys dev run"

mkdir -p $rootfs_dir
Expand All @@ -58,10 +55,48 @@ if [ "$(need_remount "$rootfs_dir")" ]; then
do_remount "$rootfs_dir"
fi

debootstrap --arch $arch $release_name $rootfs_dir http://deb.debian.org/debian/
cp -ar rootfs/* $rootfs_dir
cp /etc/resolv.conf $rootfs_dir/etc/resolv.conf
if [ "$distro" = "debian" ]; then
print_info "bootstraping debian chroot"
debootstrap --arch $arch $release_name $rootfs_dir http://deb.debian.org/debian/
chroot_script="/opt/setup_rootfs.sh"

elif [ "$distro" = "alpine" ]; then
print_info "downloading alpine package list"
pkg_list_url="https://dl-cdn.alpinelinux.org/alpine/latest-stable/main/x86_64/"
pkg_data="$(wget -qO- --show-progress $pkg_list_url | grep "apk-tools-static")"
pkg_url="$pkg_list_url$(echo "$pkg_data" | pcregrep -o1 '"(.+?.apk)"')"

print_info "downloading and extracting apk-tools-static"
pkg_extract_dir="/tmp/apk-tools-static"
pkg_dl_path="$pkg_extract_dir/pkg.apk"
apk_static="$pkg_extract_dir/sbin/apk.static"
mkdir -p "$pkg_extract_dir"
wget -q --show-progress "$pkg_url" -O "$pkg_dl_path"
tar --warning=no-unknown-keyword -xzf "$pkg_dl_path" -C "$pkg_extract_dir"

print_info "bootstraping alpine chroot"
real_arch="x86_64"
if [ "$arch" = "arm64" ]; then
real_arch="aarch64"
fi
$apk_static \
--arch $real_arch \
-X http://dl-cdn.alpinelinux.org/alpine/$release_name/main/ \
-U --allow-untrusted \
--root "$rootfs_dir" \
--initdb add alpine-base
chroot_script="/opt/setup_rootfs_alpine.sh"

else
print_error "'$distro' is an invalid distro choice."
exit 1
fi

print_info "copying rootfs setup scripts"
cp -ar rootfs/* "$rootfs_dir"
cp /etc/resolv.conf "$rootfs_dir/etc/resolv.conf"

print_info "creating bind mounts for chroot"
trap unmount_all EXIT
for mountpoint in $chroot_mounts; do
mount --make-rslave --rbind "/${mountpoint}" "${rootfs_dir}/$mountpoint"
Expand All @@ -74,15 +109,15 @@ username="${args['username']}"
user_passwd="${args['user_passwd']}"
disable_base="${args['disable_base']}"

chroot_command="/opt/setup_rootfs.sh \
chroot_command="$chroot_script \
'$DEBUG' '$release_name' '$packages' \
'$hostname' '$root_passwd' '$username' \
'$user_passwd' '$enable_root' '$disable_base' \
'$arch'"

LC_ALL=C chroot $rootfs_dir /bin/bash -c "${chroot_command}"
LC_ALL=C chroot $rootfs_dir /bin/sh -c "${chroot_command}"

trap - EXIT
unmount_all

echo "rootfs has been created"
print_info "rootfs has been created"
3 changes: 2 additions & 1 deletion rootfs/opt/setup_rootfs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
#setup the debian rootfs
#this is meant to be run within the chroot created by debootstrap


DEBUG="$1"
set -e
if [ "$DEBUG" ]; then
set -x
fi

DEBUG="$1"
release_name="$2"
packages="$3"

Expand Down
99 changes: 99 additions & 0 deletions rootfs/opt/setup_rootfs_alpine.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#!/bin/sh

#setup the alpine linux rootfs
#this is meant to be run within the chroot created by build_rootfs.sh

DEBUG="$1"
set -e
if [ "$DEBUG" ]; then
set -x
fi

release_name="$2"
packages="$3"
hostname="$4"
root_passwd="$5"
username="$6"
user_passwd="$7"
enable_root="$8"
disable_base_pkgs="$9"
arch="${10}"

#set hostname and apk repos
setup-hostname "$hostname"
setup-apkrepos \
"http://dl-cdn.alpinelinux.org/alpine/$release_name/main/" \
"http://dl-cdn.alpinelinux.org/alpine/$release_name/community/"

#enable services on startup
rc-update add acpid default
rc-update add bootmisc boot
rc-update add crond default
rc-update add devfs sysinit
rc-update add sysfs sysinit
rc-update add dmesg sysinit
rc-update add hostname boot
rc-update add hwclock boot
rc-update add hwdrivers sysinit
rc-update add killprocs shutdown
rc-update add mdev sysinit
rc-update add modules boot
rc-update add mount-ro shutdown
rc-update add networking boot
rc-update add savecache shutdown
rc-update add seedrng boot
rc-update add swap boot
rc-update add syslog boot

#add service to kill frecon
echo "#!/sbin/openrc-run
command="/usr/bin/pkill frecon-lite"
" > /etc/init.d/kill-frecon
chmod +x /etc/init.d/kill-frecon
rc-update add kill-frecon boot

#setup the desktop
if echo "$packages" | grep "task-" >/dev/null; then
desktop="$(echo $packages | cut -d'-' -f2)"
setup-desktop $desktop

else
apk add $packages
fi

#install base packages
if [ -z "$disable_base_pkgs" ]; then
apk add elogind polkit-elogind udisks2 polkit-elogind sudo zram-init networkmanager networkmanager-tui networkmanager-wifi wpa_supplicant adw-gtk3
rc-update add networkmanager default
rc-update add wpa_supplicant default
rc-update add zram-init default
fi

if [ ! $username ]; then
read -p "Enter the username for the user account: " username
fi
useradd -m $username
adduser $username plugdev

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
usermod -a -G wheel $username
fi

echo "Enter a user password:"
set_password "$username" "$user_passwd"

0 comments on commit 752462d

Please sign in to comment.