Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #### $ which chr
- #### /opt/scripts/chr
- #### $ cat /etc/sudoers.d/_opt_scripts_chr
- #### %sudo ALL=(ALL:ALL) NOPASSWD: /opt/scripts/chr
- test -z "$1" && exit 1
- # : ${CHR_ROOT:=$1}
- CHR_ROOT=$(readlink -e "$1")
- if test ! -d "${CHR_ROOT}"; then CHR_ROOT=$(readlink -e "/home/$1"); fi
- test ! -d "${CHR_ROOT}" && echo 'not found' && exit 1
- : ${CHR_WRAP:=$2}
- : ${CHR_HOME:=$3}
- : ${CHR_HOME:=${HOME}}
- : ${CHR_PIPE:=${CHR_HOME}/gentoo}
- test $(id -u) != 0 && exec sudo -n $0 "${CHR_ROOT}" "${CHR_WRAP}" "${CHR_HOME}"
- test $(id -u) != 0 && echo 'cant call myself with sudo' && exit 1
- MNT_LIST=''
- MNT_TMPFS='/tmp /var/cache/apt/archives /var/lib/apt/lists /run'
- MNT_BIND='/sys /proc /dev /dev/pts /dev/shm /proc/sys/fs/binfmt_misc'
- DIR_FIXUP='/run/lock /run/user'
- if test -d "${CHR_PIPE}"; then
- MNT_BIND=${MNT_BIND}" ${CHR_PIPE}:/gentoo"
- fi
- for i in ${MNT_TMPFS[@]}; do
- d=${CHR_ROOT}$i
- # test ! -d "$i" && continue
- mount -t tmpfs -o size=70% tmpfs "$d"
- MNT_LIST=$d' '${MNT_LIST}
- done
- for i in ${MNT_BIND[@]}; do
- s=$i
- d=${CHR_ROOT}$i
- # if echo "$i" | fgrep -qe ':'; then
- if [[ "$i" =~ ':' ]]; then
- # s=$(echo "$i" | cut -d':' -f1)
- s=${i%:*}
- # d=${CHR_ROOT}$(echo "$i" | cut -d':' -f2)
- d=${CHR_ROOT}${i#*:}
- fi
- # test ! -d "$d" && continue
- mount --bind "$s" "$d"
- MNT_LIST=$d' '${MNT_LIST}
- done
- for i in ${DIR_FIXUP[@]}; do
- mkdir -p "${CHR_ROOT}$i"
- done
- ionice -c 3 nice -n +40 ${CHR_WRAP} chroot "${CHR_ROOT}" login -f root
- for i in ${MNT_LIST[@]}; do
- # test ! -d "$i" && continue
- umount -f -l "$i"
- done
- if test -d "${CHR_PIPE}"; then
- ug=$(stat -c %U:%G "${CHR_PIPE}")
- # find "${CHR_PIPE}" \
- # \( -exec chown -c ${ug} {} + -exec chmod -c a+r,u+w,go-w {} + \) , \
- # \( -perm /0100 -exec chmod -c a+x {} + \)
- find "${CHR_PIPE}" \
- \( -exec chown -c ${ug} {} + \) , \
- \( -perm /0100 -exec chmod -c 755 {} + \) , \
- \( ! -perm /0100 -exec chmod -c 644 {} + \)
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement