This repository was archived by the owner on Jul 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathaux.inc.sh
More file actions
55 lines (44 loc) · 1.28 KB
/
aux.inc.sh
File metadata and controls
55 lines (44 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash
#
# Auxiliar functions and rootchek.
#
# Author:
# Sergio Conde <skgsergio@gmail.com>
# https://github.com/skgsergio/rpi-buildenv
#
## Auxiliar functions
raise_error() {
echo -e "\n[!!!] $@" 1>&2
exit 1
}
print_msg() {
echo -e "\n[***] $@" 1>&2
}
run_chroot() {
$cmd_sudo mount -t proc proc $rootfs_dir/proc
$cmd_sudo mount -t sysfs sysfs $rootfs_dir/sys
$cmd_sudo mount -o bind /dev $rootfs_dir/dev
$cmd_sudo mount -o bind /dev/pts $rootfs_dir/dev/pts
LC_ALL=C $cmd_sudo chroot $rootfs_dir $@
sleep 5s
$cmd_sudo umount -Rf $rootfs_dir/dev/pts
$cmd_sudo umount -Rf $rootfs_dir/dev
$cmd_sudo umount -Rf $rootfs_dir/sys
$cmd_sudo umount -Rf $rootfs_dir/proc
}
## Check for root
if [[ $(whoami) == "root" ]]; then
export cmd_sudo=""
else
print_msg "This script needs to be run as root. It will automatically use 'sudo' so you will be asked for your password."
print_msg "If you prefer you can directly run this script as root."
echo
read -sn 1 -p "Press any key to continue or Ctrl-C to quit."
echo
export cmd_sudo=$(which sudo)
if [[ $? != 0 ]]; then
raise_error "You don't have sudo installed. Please install sudo or run this script as root."
fi
echo
fi
export rootfs_dir="rootfs"