new: mtsc-common, mp-build and mp-pool
This commit is contained in:
9
matter-chroot/Makefile
Normal file
9
matter-chroot/Makefile
Normal file
@ -0,0 +1,9 @@
|
||||
PREFIX = /usr
|
||||
|
||||
install:
|
||||
install -m755 "main.sh" $(DESTDIR)/$(PREFIX)/bin/matter-chroot
|
||||
|
||||
uninstall:
|
||||
rm $(DESTDIR)/$(PREFIX)/lib/matter-chroot
|
||||
|
||||
.PHONY: install uninstall
|
91
matter-chroot/main.sh
Normal file → Executable file
91
matter-chroot/main.sh
Normal file → Executable file
@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
|
||||
# matter-chroot | Matterlinux Chroot Script
|
||||
# matter-chroot | MatterLinux chroot script
|
||||
# MatterLinux 2023-2024 (https://matterlinux.xyz)
|
||||
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
@ -16,67 +16,71 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
############################
|
||||
## logging functions/vars ##
|
||||
############################
|
||||
RED="\e[31m"
|
||||
BOLD="\e[1m"
|
||||
RESET="\e[0m"
|
||||
#############################
|
||||
## import common functions ##
|
||||
#############################
|
||||
location="$(dirname "${0}")"
|
||||
location="$(realpath "${location}")"
|
||||
commonsh="$(echo "${location}" | sed 's/\/bin/\/lib/g')/mtsc-common.sh"
|
||||
|
||||
error() {
|
||||
echo -e "$BOLD$RED>>>$RESET$BOLD $1$RESET"
|
||||
source "${commonsh}"
|
||||
|
||||
if [ "${?}" != "0" ]; then
|
||||
echo "Failed to import mtsc-common"
|
||||
exit 1
|
||||
}
|
||||
fi
|
||||
|
||||
####################
|
||||
## util functions ##
|
||||
####################
|
||||
linkresolv(){
|
||||
if [ ! -f "$TARGET/etc/resolv.conf" ]; then
|
||||
ln -sf /run/systemd/resolve/resolv.conf "$TARGET/etc/resolv.conf"
|
||||
if [ ! -f "${target}/etc/resolv.conf" ]; then
|
||||
ln -sf /run/systemd/resolve/resolv.conf "${target}/etc/resolv.conf"
|
||||
fi
|
||||
}
|
||||
|
||||
chrt() {
|
||||
mount -t proc proc "$TARGET/proc"
|
||||
mount -t sysfs sysfs "$TARGET/sys"
|
||||
if [[ -d "$TARGET/sys/firmware/efi/efivars" ]]; then
|
||||
mount -t efivarfs efivarfs "$TARGET/sys/firmware/efi/efivars"
|
||||
mount -t proc proc "${target}/proc"
|
||||
mount -t sysfs sysfs "${target}/sys"
|
||||
if [[ -d "${target}/sys/firmware/efi/efivars" ]]; then
|
||||
mount -t efivarfs efivarfs "${target}/sys/firmware/efi/efivars"
|
||||
fi
|
||||
|
||||
mount -o bind /dev "$TARGET/dev"
|
||||
mount -t devpts none "$TARGET/dev/pts"
|
||||
mount --bind /run "$TARGET/run"
|
||||
mount -o bind /dev "${target}/dev"
|
||||
mount -t devpts none "${target}/dev/pts"
|
||||
mount --bind /run "${target}/run"
|
||||
linkresolv
|
||||
|
||||
if [ -h $TARGET/dev/shm ]; then
|
||||
mkdir -p $TARGET/$(readlink $TARGET/dev/shm)
|
||||
if [ -h "${target}/dev/shm" ]; then
|
||||
mkdir -p "${target}/$(readlink "${target}/dev/shm")"
|
||||
else
|
||||
mount -t tmpfs -o nosuid,nodev tmpfs "$TARGET/dev/shm"
|
||||
mount -t tmpfs -o nosuid,nodev tmpfs "${target}/dev/shm"
|
||||
fi
|
||||
|
||||
|
||||
local prompt='\['$BOLD'\['$RED'(chroot)\['$RESET'\['$BOLD' \u@\h:\w#\['$RESET' '
|
||||
chroot "$TARGET" /usr/bin/env -i \
|
||||
HOME=/root \
|
||||
TERM="$TERM" \
|
||||
PS1="$prompt" \
|
||||
PATH=/usr/bin:/usr/sbin \
|
||||
chroot "${target}" /usr/bin/env -i \
|
||||
HOME=/root \
|
||||
TERM="${TERM}" \
|
||||
PS1="${prompt}" \
|
||||
PATH=/usr/bin:/usr/sbin \
|
||||
"$@"
|
||||
RET_CODE=$?
|
||||
local ret_code=$?
|
||||
|
||||
# kill procs that may prevent umount
|
||||
killall -9 dirmngr 2> /dev/null
|
||||
killall -9 gpg-agent 2> /dev/null
|
||||
|
||||
umount "$TARGET/proc"
|
||||
mountpoint -q "$TARGET/sys/firmware/efi/efivars" && umount "$TARGET/sys/firmware/efi/efivars"
|
||||
umount "$TARGET/sys"
|
||||
umount "${target}/proc"
|
||||
mountpoint -q "${target}/sys/firmware/efi/efivars" && umount "${target}/sys/firmware/efi/efivars"
|
||||
umount "${target}/sys"
|
||||
|
||||
umount "$TARGET/dev/pts"
|
||||
mountpoint -q "$TARGET/dev/shm" && umount "$TARGET/dev/shm"
|
||||
umount "$TARGET/dev"
|
||||
umount "$TARGET/run"
|
||||
umount "${target}/dev/pts"
|
||||
mountpoint -q "${target}/dev/shm" && umount "${target}/dev/shm"
|
||||
umount "${target}/dev"
|
||||
umount "${target}/run"
|
||||
|
||||
return $ret_code
|
||||
}
|
||||
|
||||
#################
|
||||
@ -84,24 +88,29 @@ chrt() {
|
||||
#################
|
||||
if [ "$EUID" -ne 0 ]; then
|
||||
error "Cannot chroot without root"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ $# -eq 0 ]; then
|
||||
error "Please specify a directory"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
TARGET=$(realpath $1)
|
||||
if [ -f $TARGET ]; then
|
||||
error "$TARGET is a file"
|
||||
target="$(realpath "${1}")"
|
||||
|
||||
if [ -f "${target}" ]; then
|
||||
error "${target} is a file"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -d $TARGET ]; then
|
||||
error "$TARGET does not exist"
|
||||
if [ ! -d "${target}" ]; then
|
||||
error "${target} does not exist"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ $# -gt 1 ]; then
|
||||
chrt ${@:2}
|
||||
exit $RET_CODE
|
||||
exit $?
|
||||
fi
|
||||
|
||||
chrt bash --noprofile --login
|
||||
|
Reference in New Issue
Block a user