2018-09-24 22:47:35 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2024-08-24 10:49:50 +02:00
|
|
|
set -x
|
2018-09-24 22:47:35 +02:00
|
|
|
|
2024-08-24 10:49:50 +02:00
|
|
|
# WARNING: this codebase is now updated in the "alpine.mk" makefile.
|
|
|
|
# A makefile is a better option than a plain shell script, it enables
|
|
|
|
# an automatic selection of the action to perform (by just selecting
|
|
|
|
# the "rule" to make), without dedicated code.
|
2018-09-24 22:47:35 +02:00
|
|
|
|
2024-08-24 10:49:50 +02:00
|
|
|
#APKPKT=apk-tools-static-2.10.1-r0.apk
|
|
|
|
|
|
|
|
#mirror=http://uk.alpinelinux.org/alpine/
|
|
|
|
mirror=http://dl-cdn.alpinelinux.org/alpine
|
|
|
|
MAIN_DIR=/tmp/root
|
|
|
|
CHROOT=$MAIN_DIR/chroot
|
2018-09-24 22:47:35 +02:00
|
|
|
PACKAGES="vim zsh"
|
2024-08-24 10:49:50 +02:00
|
|
|
#POSTPACKAGES="alpine-sdk git openssh openssl openssl-dev crystal"
|
|
|
|
POSTPACKAGES=""
|
2018-09-24 22:47:35 +02:00
|
|
|
|
2024-08-24 10:49:50 +02:00
|
|
|
chroot_mkdir(){
|
|
|
|
mkdir -p $CHROOT || true
|
|
|
|
}
|
2018-09-24 22:47:35 +02:00
|
|
|
|
2024-08-24 10:49:50 +02:00
|
|
|
#chroot_apk_static(){
|
|
|
|
# cd ${MAIN_DIR}/
|
|
|
|
#
|
|
|
|
# if [ -f ${APKPKT} ]; then
|
|
|
|
# echo "apk already downloaded"
|
|
|
|
# else
|
|
|
|
# wget ${mirror}/latest-stable/main/`uname -p`/${APKPKT}
|
|
|
|
# tar -xzf ${APKPKT}
|
|
|
|
# fi
|
|
|
|
#}
|
|
|
|
|
|
|
|
chroot_install(){
|
|
|
|
cd ${MAIN_DIR}/
|
2018-09-24 22:47:35 +02:00
|
|
|
|
2024-08-24 10:49:50 +02:00
|
|
|
#${MAIN_DIR}/sbin/apk.static -X ${mirror}/latest-stable/main -U --allow-untrusted --root ${CHROOT} --initdb add alpine-base $PACKAGES
|
|
|
|
apk --arch $(arch) -X ${mirror}/latest-stable/main/ -U --allow-untrusted --root ${CHROOT} --initdb add alpine-base
|
2018-09-24 22:47:35 +02:00
|
|
|
cp /etc/resolv.conf $CHROOT/etc/
|
2024-08-24 10:49:50 +02:00
|
|
|
#cp -r ~/.zsh* ~/.vim* ${CHROOT}/root
|
|
|
|
#echo export PS1=\"\(chroot\) \$PS1\" >> ${CHROOT}/root/.zshrc
|
2018-09-24 22:47:35 +02:00
|
|
|
|
|
|
|
cat << END > $CHROOT/etc/apk/repositories
|
|
|
|
http://uk.alpinelinux.org/alpine/latest-stable/main
|
|
|
|
http://uk.alpinelinux.org/alpine/latest-stable/community
|
|
|
|
END
|
|
|
|
}
|
|
|
|
|
|
|
|
chroot_mount(){
|
2024-08-24 10:49:50 +02:00
|
|
|
for a in proc sys dev; do mount -o bind /$a ${CHROOT}/$a; done
|
2018-09-24 22:47:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
chroot_env(){
|
2024-08-24 10:49:50 +02:00
|
|
|
chroot ${CHROOT} /bin/sh
|
|
|
|
#chroot ${CHROOT} /bin/zsh -l
|
2018-09-24 22:47:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
chroot_post(){
|
2024-08-24 10:49:50 +02:00
|
|
|
#${MAIN_DIR}/sbin/apk.static --root ${CHROOT} add $POSTPACKAGES
|
2018-09-24 22:47:35 +02:00
|
|
|
# chroot ${CHROOT} /bin/zsh -l "apk update && apk upgrade && apk add $POSTPACKAGES"
|
|
|
|
}
|
|
|
|
|
|
|
|
ask(){
|
|
|
|
echo -en "$1? [YyNn] (n): "
|
|
|
|
read V ; echo $V | grep "[Yy]" >/dev/null
|
|
|
|
if [ $? -eq 0 ] ; then
|
|
|
|
echo -en "doing $1..." ; $1
|
|
|
|
else
|
|
|
|
echo "not doing $1"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2024-08-24 10:49:50 +02:00
|
|
|
chroot_mkdir
|
|
|
|
#ask chroot_apk_static
|
2018-09-24 22:47:35 +02:00
|
|
|
ask chroot_install
|
|
|
|
ask chroot_mount
|
|
|
|
ask chroot_post
|
|
|
|
ask chroot_env
|