Personal dotfiles for Linux, mostly for Nixpkgs/NixOS-based and Termux setups. Mirrored using GitLab's push mirroring feature. gitlab.com/andreijiroh-dev/dotfiles
linux dotfiles
at pre-nixpkgs/main 39 lines 1.1 kB view raw
1#!/usr/bin/bash 2# SPDX-License-Identifier: MPL-2.0 3# A mini scirpt to handle chrooting into different environments, 4# especially for Alpine Linux devenv on chroots instead of containers/VMs. 5 6# Chroot command is optional and assume login binary 7CHROOT_COMMAND=${2:-"/usr/bin/login"} 8TARGET_DIR=$1 9 10if [[ $TARGET_DIR == "" ]]; then 11 echo "Usage: $0 TARGET_DIR [CHROOT_COMMAND]" 12 exit 1 13fi 14 15if [ $EUID != "0" ]; then 16 echo "error: Must be root to proceed!" 17 exit 1 18fi 19 20echo "===> Mounting required parts for chroot operation..." 21mount -o bind /dev "$TARGET_DIR/dev" 22mount -t proc none "$TARGET_DIR/proc" 23mount -o bind /sys "$TARGET_DIR/sys" 24echo " Kernel and device mount setup done!" 25sleep 3 26 27if [[ -f "$TARGET_DIR/setup-chroot-env.sh" ]]; then 28 echo "===> Preparing chroot environment..." 29 if ! bash "$TARGET_DIR/setup-chroot-env.sh"; then 30 echo "! Chroot env setup failed, please proceed at your own risk." 31 else 32 echo " Setup done!" 33 fi 34 sleep 3 35fi 36 37echo "===> Teleporting to the chroot environment in 3 seconds..." 38sleep 3 39exec chroot "$TARGET_DIR" "${CHROOT_COMMAND}"