Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/andreijiroh-dev/dotfiles-yadm. The YADM version of my dotfiles repo, minus nixos/home-manager speci
Something went wrong. Try again.
1.1 kB · 39 lines
at main
12345678910111213141516171819202122232425262728293031323334353637383940#!/usr/bin/bash# SPDX-License-Identifier: MPL-2.0# A mini scirpt to handle chrooting into different environments,# especially for Alpine Linux devenv on chroots instead of containers/VMs.
# Chroot command is optional and assume login binaryCHROOT_COMMAND=${2:-"/usr/bin/login"}TARGET_DIR=$1
if [[ $TARGET_DIR == "" ]]; then echo "Usage: $0 TARGET_DIR [CHROOT_COMMAND]" exit 1fi
if [ $EUID != "0" ]; then echo "error: Must be root to proceed!" exit 1fi
echo "===> Mounting required parts for chroot operation..."mount -o bind /dev "$TARGET_DIR/dev"mount -t proc none "$TARGET_DIR/proc"mount -o bind /sys "$TARGET_DIR/sys"echo " Kernel and device mount setup done!"sleep 3
if [[ -f "$TARGET_DIR/setup-chroot-env.sh" ]]; then echo "===> Preparing chroot environment..." if ! bash "$TARGET_DIR/setup-chroot-env.sh"; then echo "! Chroot env setup failed, please proceed at your own risk." else echo " Setup done!" fi sleep 3fi
echo "===> Teleporting to the chroot environment in 3 seconds..."sleep 3exec chroot "$TARGET_DIR" "${CHROOT_COMMAND}"