-
Notifications
You must be signed in to change notification settings - Fork 14
/
lsarch
executable file
·70 lines (60 loc) · 1.28 KB
/
lsarch
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env bash
# Written by Draco (tytydraco) @ GitHub
# Log in red and exit
err() {
echo -e " \e[91m*\e[39m $*"
exit 1
}
# Check for required dependencies
for dep in awk basename du id printf
do
! command -v "$dep" &> /dev/null && err "Unable to locate dependency $dep. Exiting."
done
# Check for root permissions
[[ "$(id -u)" -ne 0 ]] && err "No root permissions. Exiting."
# Path containing rootfs tarball and all rootfs instances
CHROOT_DIR="$HOME/charch"
usage() {
echo -n "Usage: $(basename "$0") [OPTIONS]
Options:
-d DIRECTORY Specify a chroot container directory (default: $CHROOT_DIR)
-s Simple output; only display the rootfs names
-h Show usage
"
}
while getopts ":d:sh" opt; do
case $opt in
d)
CHROOT_DIR="$OPTARG"
;;
s)
SIMPLE=1
;;
h)
usage
exit 0
;;
*)
usage
exit 1
;;
esac
done
shift $((OPTIND - 1))
# Check if chroot container exists
[[ ! -d "$CHROOT_DIR" ]] && err "No container at $CHROOT_DIR. Exiting."
# List just the directory names and exit
if [[ "$SIMPLE" -eq 1 ]]
then
for rootfs in "$CHROOT_DIR"/*
do
basename "$rootfs"
done
exit 0
fi
# List the directory names and full paths
printf "%-16s\t%-32s\n" "NAME" "PATH"
for rootfs in "$CHROOT_DIR"/*
do
printf "%-16s\t%-32s\n" "$(basename "$rootfs")" "$rootfs"
done