Skip to content

Commit

Permalink
Some chroot.sh changes
Browse files Browse the repository at this point in the history
  • Loading branch information
malwarepad committed Sep 30, 2024
1 parent 18423ee commit d5df90d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 30 deletions.
48 changes: 20 additions & 28 deletions tools/shared/chroot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,31 @@
# # anything
# EOT

SCRIPT=$(realpath "$0")
SCRIPTPATH=$(dirname "$SCRIPT")

TARGET_DIR="$SCRIPTPATH/../../target/"

chroot_drop() {
sudo umount -l "$TARGET_DIR/dev/shm" || true
sudo umount -l "$TARGET_DIR/run" || true
sudo umount -l "$TARGET_DIR/sys" || true
sudo umount -l "$TARGET_DIR/proc" || true
sudo umount -l "$TARGET_DIR/dev/pts" || true
sudo umount -l "$TARGET_DIR/dev" || true
sudo umount -l "$1/dev/shm" || true
sudo umount -l "$1/run" || true
sudo umount -l "$1/sys" || true
sudo umount -l "$1/proc" || true
sudo umount -l "$1/dev/pts" || true
sudo umount -l "$1/dev" || true
}

chroot_establish() {
chroot_drop

mkdir -p "$TARGET_DIR/"{dev,proc,sys,run,tmp}
sudo mount --bind /dev "$TARGET_DIR/dev"
sudo mount -t devpts devpts -o gid=5,mode=0620 "$TARGET_DIR/dev/pts"
sudo mount -t proc proc "$TARGET_DIR/proc"
sudo mount -t sysfs sysfs "$TARGET_DIR/sys"
sudo mount -t tmpfs tmpfs "$TARGET_DIR/run"
if [ -h "$TARGET_DIR/dev/shm" ]; then
sudo install -v -d -m 1777 "$TARGET_DIR/$(realpath /dev/shm)"
chroot_drop "$1"

mkdir -p "$1/"{dev,proc,sys,run,tmp}
sudo mount --bind /dev "$1/dev"
sudo mount -t devpts devpts -o gid=5,mode=0620 "$1/dev/pts"
sudo mount -t proc proc "$1/proc"
sudo mount -t sysfs sysfs "$1/sys"
sudo mount -t tmpfs tmpfs "$1/run"
if [ -h "$1/dev/shm" ]; then
sudo install -v -d -m 1777 "$1/$(realpath /dev/shm)"
else
sudo mount -t tmpfs -o nosuid,nodev tmpfs "$TARGET_DIR/dev/shm"
sudo mount -t tmpfs -o nosuid,nodev tmpfs "$1/dev/shm"
fi

# sudo chroot "$TARGET_DIR/" /usr/bin/bash -c "ls files
# cat files/ab.txt"
}

# chroot_establish
# sudo chroot "$TARGET_DIR/" /usr/bin/env -i HISTFILE=/dev/null /bin/bash
# chroot_drop
# chroot_establish "$1"
# sudo chroot "$1/" /usr/bin/env -i HISTFILE=/dev/null /bin/bash
# chroot_drop "$1"
4 changes: 2 additions & 2 deletions tools/userland/ports.sh
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ fi
# Hence, we can begin to use it for targetted compilations, instead of cross-compilations like so:

source "${SCRIPTPATH}/../shared/chroot.sh"
chroot_establish
chroot_establish "$USR_PATHNAME/../"
cd "$USR_PATHNAME/../"

# The netwide assembler (nasm)
Expand Down Expand Up @@ -194,4 +194,4 @@ if [ ! -f "$USR_PATHNAME/bin/vim" ]; then
sudo chroot "$TARGET_DIR/" /usr/bin/bash -c "cd /vim-9.1.0041 && ./configure --prefix=/usr --with-tlib=ncursesw && make -j$(nproc) && make install && cd / && rm -rf /vim-9.1.0041 /vim-9.1.0041.tar.gz"
fi

chroot_drop
chroot_drop "$USR_PATHNAME/../"

0 comments on commit d5df90d

Please sign in to comment.