first commit
This commit is contained in:
16
matter-chroot/README.md
Normal file
16
matter-chroot/README.md
Normal file
@ -0,0 +1,16 @@
|
||||
# matter-chroot
|
||||
This script is used for changing system root during installation
|
||||
and configuration.
|
||||
|
||||
### Usage
|
||||
To use the `matter-chroot` script, specify a target directory.
|
||||
In a normal installation, this directory would most likely
|
||||
be your mount directory:
|
||||
```bash
|
||||
matter-chroot /mnt
|
||||
```
|
||||
You can also specify a command, if no command is specified
|
||||
then script will run `/bin/bash --login`:
|
||||
```bash
|
||||
matter-chroot /mnt ls -la
|
||||
```
|
84
matter-chroot/main.sh
Normal file
84
matter-chroot/main.sh
Normal file
@ -0,0 +1,84 @@
|
||||
#!/bin/bash
|
||||
|
||||
# matter-chroot | Matterlinux Chroot Script
|
||||
# Copyright (C) 2023 Matterlinux
|
||||
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
|
||||
# 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"
|
||||
|
||||
error() {
|
||||
echo -e "$BOLD$RED>>>$RESET$BOLD $1$RESET"
|
||||
exit 1
|
||||
}
|
||||
|
||||
####################
|
||||
## util functions ##
|
||||
####################
|
||||
chrt() {
|
||||
mount --bind /dev $TARGET/dev
|
||||
mount --bind /dev/pts $TARGET/dev/pts
|
||||
mount -t proc proc $TARGET/proc
|
||||
mount -t sysfs sysfs $TARGET/sys
|
||||
mount -t tmpfs tmpfs $TARGET/run
|
||||
|
||||
if [ -h $TARGET/dev/shm ]; then
|
||||
mkdir -p $TARGET/$(readlink $TARGET/dev/shm)
|
||||
else
|
||||
mount -t tmpfs -o nosuid,nodev tmpfs $TARGET/dev/shm
|
||||
fi
|
||||
|
||||
local prompt='\e[1m\e[31m(chroot)\e[0m\e[1m \u@\h:\w#\e[0m '
|
||||
chroot $TARGET /usr/bin/env -i \
|
||||
HOME=/root \
|
||||
TERM="$TERM" \
|
||||
PS1="$prompt" \
|
||||
PATH=/usr/bin:/usr/sbin \
|
||||
$@
|
||||
|
||||
umount $TARGET/dev/pts
|
||||
mountpoint -q $TARGET/dev/shm && umount $TARGET/dev/shm
|
||||
umount $TARGET/dev
|
||||
umount $TARGET/run
|
||||
umount $TARGET/proc
|
||||
umount $TARGET/sys
|
||||
}
|
||||
|
||||
#################
|
||||
## main script ##
|
||||
#################
|
||||
if [ $# -eq 0 ]; then
|
||||
error "Please specify a directory"
|
||||
fi
|
||||
|
||||
TARGET=$(realpath $1)
|
||||
if [ -f $TARGET ]; then
|
||||
error "$TARGET is a file"
|
||||
fi
|
||||
|
||||
if [ ! -d $TARGET ]; then
|
||||
error "$TARGET does not exist"
|
||||
fi
|
||||
|
||||
if [ $# -gt 1 ]; then
|
||||
chrt ${@:2}
|
||||
exit 0
|
||||
fi
|
||||
|
||||
chrt bash --login
|
Reference in New Issue
Block a user