alpine.mk

master
Karchnu 2024-08-24 10:49:50 +02:00
parent 17d8545e0a
commit ee0d4cc27a
2 changed files with 68 additions and 25 deletions

View File

@ -1,51 +1,63 @@
#!/bin/bash #!/bin/bash
# TODO: good codebase, need parameters and make a more generic tool set -x
APKPKT=apk-tools-static-2.10.1-r0.apk # 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.
mirror=http://uk.alpinelinux.org/alpine/ #APKPKT=apk-tools-static-2.10.1-r0.apk
MAINREP=/media/fast/al
CHROOT=$MAINREP/chroot #mirror=http://uk.alpinelinux.org/alpine/
mirror=http://dl-cdn.alpinelinux.org/alpine
MAIN_DIR=/tmp/root
CHROOT=$MAIN_DIR/chroot
PACKAGES="vim zsh" PACKAGES="vim zsh"
POSTPACKAGES="alpine-sdk git openssh openssl openssl-dev crystal" #POSTPACKAGES="alpine-sdk git openssh openssl openssl-dev crystal"
POSTPACKAGES=""
chroot_mkdir(){
mkdir -p $CHROOT || true
}
#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(){ chroot_install(){
mkdir -p $CHROOT cd ${MAIN_DIR}/
cd ${MAINREP}/
if [ -f ${APKPKT} ]; then #${MAIN_DIR}/sbin/apk.static -X ${mirror}/latest-stable/main -U --allow-untrusted --root ${CHROOT} --initdb add alpine-base $PACKAGES
echo "apk already downloaded" apk --arch $(arch) -X ${mirror}/latest-stable/main/ -U --allow-untrusted --root ${CHROOT} --initdb add alpine-base
else
wget ${mirror}/latest-stable/main/`uname -p`/${APKPKT}
tar -xzf ${APKPKT}
fi
${MAINREP}/sbin/apk.static -X ${mirror}/latest-stable/main -U --allow-untrusted --root ${CHROOT} --initdb add alpine-base $PACKAGES
cp /etc/resolv.conf $CHROOT/etc/ cp /etc/resolv.conf $CHROOT/etc/
cp -r ~/.zsh* ~/.vim* ${CHROOT}/root #cp -r ~/.zsh* ~/.vim* ${CHROOT}/root
echo export PS1=\"\(chroot\) \$PS1\" >> ${CHROOT}/root/.zshrc #echo export PS1=\"\(chroot\) \$PS1\" >> ${CHROOT}/root/.zshrc
cat << END > $CHROOT/etc/apk/repositories cat << END > $CHROOT/etc/apk/repositories
http://uk.alpinelinux.org/alpine/latest-stable/main http://uk.alpinelinux.org/alpine/latest-stable/main
http://uk.alpinelinux.org/alpine/latest-stable/community http://uk.alpinelinux.org/alpine/latest-stable/community
http://uk.alpinelinux.org/alpine/edge/main
http://uk.alpinelinux.org/alpine/edge/community
END END
} }
chroot_mount(){ chroot_mount(){
mount -t proc /proc ${CHROOT}/proc/ for a in proc sys dev; do mount -o bind /$a ${CHROOT}/$a; done
mount -o bind /sys ${CHROOT}/sys/
mount -o bind /dev ${CHROOT}/dev/
} }
chroot_env(){ chroot_env(){
chroot ${CHROOT} /bin/zsh -l chroot ${CHROOT} /bin/sh
#chroot ${CHROOT} /bin/zsh -l
} }
chroot_post(){ chroot_post(){
${MAINREP}/sbin/apk.static --root ${CHROOT} add $POSTPACKAGES #${MAIN_DIR}/sbin/apk.static --root ${CHROOT} add $POSTPACKAGES
# chroot ${CHROOT} /bin/zsh -l "apk update && apk upgrade && apk add $POSTPACKAGES" # chroot ${CHROOT} /bin/zsh -l "apk update && apk upgrade && apk add $POSTPACKAGES"
} }
@ -59,6 +71,8 @@ ask(){
fi fi
} }
chroot_mkdir
#ask chroot_apk_static
ask chroot_install ask chroot_install
ask chroot_mount ask chroot_mount
ask chroot_post ask chroot_post

29
mk/alpine.mk Normal file
View File

@ -0,0 +1,29 @@
CHROOT ?= /tmp/root
ARCH ?= x86_64
VERSION ?= v3.20
MIRROR ?= http://uk.alpinelinux.org/alpine/
URL_REPOS ?= $(MIRROR)$(VERSION)
enter-chroot:
chroot $(CHROOT) /bin/sh
install-chroot:
@echo "creating a new alpine $(VERSION) chroot"
mkdir -p $(CHROOT)
apk --arch $(ARCH) -X $(URL_REPOS)/main/ -U --allow-untrusted --root $(CHROOT) --initdb add alpine-base
cp /etc/resolv.conf $(CHROOT)/etc/
echo "$(URL_REPOS)/main" > $(CHROOT)/etc/apk/repositories
echo "$(URL_REPOS)/community" >> $(CHROOT)/etc/apk/repositories
mount-chroot:
for a in proc sys dev; do mount -o bind /$$a $(CHROOT)/$$a; done
umount-chroot:
-umount $(CHROOT)/proc
-umount $(CHROOT)/sys
-umount $(CHROOT)/dev
delete-chroot: umount-chroot
rm -r $(CHROOT)
new-chroot: install-chroot mount-chroot enter-chroot