1
0
mirror of https://codeberg.org/kiss-community/kiss synced 2024-12-24 08:00:05 -07:00
kiss/contrib/kiss-chroot
Dylan Araps fdf2775640
kiss: Integrate with user scripts.
kiss' help output will now include all executables found in $PATH
which begin with kiss-*. A comment string is optionally usable via
setting the second line of the script to a string.

Example:

...

This also means that 'kiss <script name>' is also possible now.
If I have a script in my $PATH called kiss-depends, I can now use
it via kiss with 'kiss depends'.
2020-04-18 11:39:37 +03:00

59 lines
1.4 KiB
Bash
Executable File

#!/bin/sh -e
# Enter a kiss chroot.
log() {
printf '\033[32m->\033[m %s.\n' "$*"
}
die() {
log "$*" >&2
exit 1
}
clean() {
log Unmounting /dev, /proc and /sys from chroot; {
umount "$1/dev" ||:
umount "$1/proc" ||:
umount "$1/sys" ||:
}
log Cleaning leftover host files; {
rm -f "$1/root/.ash_history"
rm -f "$1/etc/resolv.conf"
}
}
main() {
[ -z "$1" ] && die Need a path to the chroot
[ -d "$1" ] || die Given path does not exist
[ "$(id -u)" = 0 ] || die Script needs to be run as root
trap 'clean "$1"' EXIT INT
log Mounting /dev, /proc and /sys from host; {
mountpoint -q "$1/dev" || mount -o bind /dev "$1/dev"
mountpoint -q "$1/proc" || mount -t proc proc "$1/proc"
mountpoint -q "$1/sys" || mount -t sysfs sys "$1/sys"
}
log Copying /etc/resolv.conf from host; {
cp -f /etc/resolv.conf "$1/etc"
}
log Entering chroot; {
chroot "$1" /usr/bin/env -i \
HOME=/root \
TERM="$TERM" \
SHELL=/bin/sh \
USER=root \
KISS_ASROOT=1 \
CFLAGS="${2:--march=x86-64 -mtune=generic -pipe -Os}" \
CXXFLAGS="${2:--march=x86-64 -mtune=generic -pipe -Os}" \
MAKEFLAGS="-j$(nproc 2>/dev/null || echo 1)" \
/bin/sh -l
}
}
main "$@"