Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speedup and fix umount #33

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 30 additions & 31 deletions alpine-chroot-install
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ gen_destroy_script() {
[ "$(id -u)" -eq 0 ] || _sudo='sudo'

# Unmounts all filesystem under the specified directory tree.
cat /proc/mounts | cut -d' ' -f2 | grep "^$SCRIPT_DIR" | sort -r | while read path; do
cat /proc/mounts | cut -d' ' -f2 | grep "^$SCRIPT_DIR." | sort -r | while read path; do
echo "Unmounting $path" >&2
$_sudo umount -fn "$path" || exit 1
done
Expand Down Expand Up @@ -291,10 +291,6 @@ if [ "$(id -u)" -ne 0 ]; then
die 'This script must be run as root!'
fi

mkdir -p "$CHROOT_DIR"
cd "$CHROOT_DIR"


# Install QEMU user mode emulation if needed (works only on Debian and derivates)

QEMU_EMULATOR=''
Expand All @@ -316,37 +312,37 @@ if [ -n "$ARCH" ] && [ $(normalize_arch $ARCH) != $(normalize_arch $(uname -m))
cp -v "$QEMU_EMULATOR" usr/bin/
fi


einfo 'Downloading static apk-tools'

download_file "$APK_TOOLS_URI" "$APK_TOOLS_SHA256" "$TEMP_DIR"
tar -C "$TEMP_DIR" -xzf "$TEMP_DIR/${APK_TOOLS_URI##*/}"
mv "$TEMP_DIR"/apk-tools-*/apk "$TEMP_DIR"/


einfo "Installing Alpine Linux $ALPINE_BRANCH ($ARCH) into chroot"

mkdir -p "$CHROOT_DIR"/etc/apk
cd "$CHROOT_DIR"
cp /etc/resolv.conf etc/resolv.conf

printf '%s\n' \
"$ALPINE_MIRROR/$ALPINE_BRANCH/main" \
"$ALPINE_MIRROR/$ALPINE_BRANCH/community" \
$EXTRA_REPOS \
> etc/apk/repositories
# Initial one-time setup
if [ ! -e 'sbin/apk' ]; then
einfo 'Downloading static apk-tools'

dump_alpine_keys etc/apk/keys/
download_file "$APK_TOOLS_URI" "$APK_TOOLS_SHA256" "$TEMP_DIR"
tar -C "$TEMP_DIR" -xzf "$TEMP_DIR/${APK_TOOLS_URI##*/}"
mv "$TEMP_DIR"/apk-tools-*/apk "$TEMP_DIR"/

cp /etc/resolv.conf etc/resolv.conf
einfo "Installing Alpine Linux $ALPINE_BRANCH ($ARCH) into chroot"

"$TEMP_DIR"/apk \
--root . --update-cache --initdb --no-progress \
${ARCH:+--arch $ARCH} \
add alpine-base
printf '%s\n' \
"$ALPINE_MIRROR/$ALPINE_BRANCH/main" \
"$ALPINE_MIRROR/$ALPINE_BRANCH/community" \
$EXTRA_REPOS \
> etc/apk/repositories

gen_chroot_script > enter-chroot
gen_destroy_script > destroy
chmod +x enter-chroot destroy
dump_alpine_keys etc/apk/keys/

"$TEMP_DIR"/apk \
--root . --update-cache --initdb --no-progress \
${ARCH:+--arch $ARCH} \
add alpine-base

gen_chroot_script > enter-chroot
gen_destroy_script > destroy
chmod +x enter-chroot destroy
fi


einfo 'Binding filesystems into chroot'
Expand Down Expand Up @@ -375,8 +371,11 @@ einfo 'Setting up Alpine'

./enter-chroot <<-EOF
set -e
apk update
apk add $ALPINE_PACKAGES

if [ "$ALPINE_PACKAGES" != ' ' ]; then
apk update
apk add $ALPINE_PACKAGES
fi

if [ -d /etc/sudoers.d ] && [ ! -e /etc/sudoers.d/wheel ]; then
echo '%wheel ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/wheel
Expand Down