Created
April 27, 2025 06:46
-
-
Save yunfan/2c93881efe0cae5a5483eb0a75ed570b to your computer and use it in GitHub Desktop.
bootstrap an alpine on non-root user's home, and provide a script to use inside binary
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
CWD=$(dirname $(realpath $0)) | |
cd $CWD | |
TARGET_VER="3.21" | |
FULL_VER="${TARGET_VER}.3" | |
TARGET_DIR="${CWD}/sys" | |
TARGET_APK_REPO="mirrors.ustc.edu.cn" | |
TARGET_ARCH="x86_64" | |
BUILD_DIR="${CWD}/tmp" | |
REPO_BASE="https://${TARGET_APK_REPO}/alpine/v${TARGET_VER}" | |
ROOT_LINK="${REPO_BASE}/releases/${TARGET_ARCH}/alpine-minirootfs-${FULL_VER}-${TARGET_ARCH}.tar.gz" | |
init() { | |
mkdir -p ${TARGET_DIR} | |
mkdir -p ${BUILD_DIR} | |
cd ${BUILD_DIR} | |
repolistlink="${REPO_BASE}/main/${TARGET_ARCH}" | |
apkfile=$(wget ${repolistlink} -O- 2>/dev/null | grep 'apk-tools-static' | sed -n 's/^[^"]\+"\(.*\)".\+$/\1/p') | |
apklink="${repolistlink}/$apkfile" | |
echo "found apklink => ${apklink}" | |
wget ${apklink} -O apk.tar.gz | |
wget ${ROOT_LINK} -O root.tar.gz | |
# 下载完成 解压到目标目录 | |
cd ${TARGET_DIR} | |
tar -xvf ${BUILD_DIR}/apk.tar.gz | |
tar -xvf ${BUILD_DIR}/root.tar.gz | |
proot -R ${TARGET_DIR} -0 /sbin/apk.static \ | |
-X "${REPO_BASE}/main" \ | |
-U --allow-untrusted \ | |
--initdb \ | |
add alpine-base | |
rm -rf ${BUILD_DIR} | |
ln -s ${CWD}/with.alpine ~/.local/bin/ | |
} | |
init |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
CWD=$(dirname $(realpath $0)) | |
cd ${CWD} | |
SYS="${CWD}/sys" | |
realproot=$(which proot) | |
PATH="${SYS}/bin:${SYS}/sbin:${SYS}/usr/bin:${SYS}/usr/sbin:${SYS}/usr/local/bin" ${realproot} -R ${SYS} -0 $@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment