alpinelinux / alpine-chroot-install

Install Alpine Linux in chroot with a breeze. Build ARM on Travis CI or any other x86_64 CI.
MIT License
290 stars 59 forks source link

x86_64 is hardcoded, breaks aarch64 installs! #46

Open IngwiePhoenix opened 8 months ago

IngwiePhoenix commented 8 months ago

Hello!

I just come back from absolutely bricking my OS - OpenWrt on a FriendlyElec NanoPi R6s - and decided to have a "side system" for anything that I can not or do not want to containerize.

However, while installing, I was met with this:

https://github.com/alpinelinux/alpine-chroot-install/blob/master/alpine-chroot-install#L81-L82

I fixed it by just manually setting the values as environment variables - but I believe that this is actually not the intended way?

Thanks and kind regards, Ingwie

jirutka commented 8 months ago

I fixed it by just manually setting the values as environment variables - but I believe that this is actually not the intended way?

Well, the problem is that I originally wrote this script for one specific purpose – using Alpine Linux on Travis CI (and other x86_64-only CIs) – but people are now using it for many different purposes for which it was never intended. This is one of them. I guess I’ll have to completely rewrite the script to make it more suitable for the purposes people use it for today.

IngwiePhoenix commented 8 months ago

I guess so; I certainly facelifted the enter-script a lot...

Maybe this helps? I am using this in conjunction with a symlink to /usr/local/bin/alpine and as a procd service to call dinit as an "init system". Works quite well, even across reboots.

#!/bin/sh
set -e

try_to_mount() {
  local mto mfrom
  mfrom="$1"
  mto="/usb/alpine/$2"
  if [ -z "$2" ]; then
    mto="/usb/alpine/$1"
  fi

  # Exists?
  if [ ! -d "$mto" ]; then
    mkdir -p "$mto"
  fi

  # is not mounted?
  mountpoint -q "$mto" \
  || mount --bind "$mfrom" "$mto"
}

# Mounts
## Dirs
try_to_mount /proc
try_to_mount /sys
try_to_mount /dev
try_to_mount /root
## Drives
try_to_mount /usb
try_to_mount /sdcard
try_to_mount /mnt/diskstation/bunker
try_to_mount /mnt/diskstation/scratch
## Socks
try_to_mount /var/run/tailscale /run/tailscale

ENV_FILTER_REGEX='(TERM|ARCH|CI|QEMU_EMULATOR|TRAVIS_.*)'

user='root'
if [ $# -ge 2 ] && [ "$1" = '-u' ]; then
    user="$2"; shift 2
fi
oldpwd="$(pwd)"
[ "$(id -u)" -eq 0 ] || _sudo='sudo'

tmpfile="$(mktemp)"
chmod 644 "$tmpfile"
export | sed -En "s/^([^=]+ ${ENV_FILTER_REGEX}=)('.*'|\".*\")$/\1\3/p" > "$tmpfile" || true

cd "$(dirname "$0")"
$_sudo mv "$tmpfile" env.sh
$_sudo chroot . /usr/bin/env -i su -l "$user" \
    sh -c ". /etc/profile; . /env.sh; cd '$oldpwd' 2>/dev/null; \"\$@\"" \
    -- "${@:-fish}"

I added $TERM because fish would complain about it not being set. The rest is fine.