2018-04-30 18:57:01 +02:00
|
|
|
#!/bin/bash
|
|
|
|
#remaster lib
|
2018-05-07 02:56:46 +02:00
|
|
|
[ -d "<LIBDIR>" ] || { echo "LIBDIR not exist"; exit 1; }
|
2018-04-30 18:57:01 +02:00
|
|
|
|
|
|
|
#chroot_sh [chroot_dir] [command]
|
|
|
|
function chroot_sh() {
|
|
|
|
#check chroot dir
|
|
|
|
chroot_dir="$1"
|
|
|
|
[ -d "$chroot_dir" ] || {
|
|
|
|
echo "### ERROR ### chroot_sh: chroot directory not exist!"
|
|
|
|
return 12
|
|
|
|
}
|
|
|
|
|
|
|
|
command="$2"
|
|
|
|
|
|
|
|
[ -f "$chroot_dir/tmp/env.sh" ] || {
|
|
|
|
#if not exist create environment skript
|
|
|
|
cat "$chroot_dir/etc/environment" | grep -v "#" | grep "=" > "$chroot_dir/tmp/env"
|
|
|
|
while read line; do echo export $line; done < "$chroot_dir/tmp/env" > "$chroot_dir/tmp/env.sh"
|
|
|
|
chmod +x "$chroot_dir/tmp/env.sh" && rm "$chroot_dir/tmp/env"
|
|
|
|
}
|
|
|
|
|
|
|
|
chroot "$chroot_dir" /bin/bash --login -c ". /tmp/env.sh; $command"
|
|
|
|
}
|
2018-05-10 17:13:19 +02:00
|
|
|
|
2018-05-11 00:04:02 +02:00
|
|
|
#this func is standalone executable
|
2018-05-10 17:13:19 +02:00
|
|
|
[ -n "$1" ] && {
|
2018-05-11 00:04:02 +02:00
|
|
|
chroot_sh $@
|
2018-05-10 17:13:19 +02:00
|
|
|
}
|