-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·120 lines (93 loc) · 2.91 KB
/
run.sh
File metadata and controls
executable file
·120 lines (93 loc) · 2.91 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/bin/bash
#Defaults
ROOTFS="rootfs"
# Check if whiptail is installed
if ! command -v whiptail &> /dev/null; then
echo "whiptail is not installed."
# Check if apt is available
if command -v apt &> /dev/null; then
echo "Attempting to install whiptail using apt..."
sudo apt update && sudo apt install -y whiptail
# Verify if whiptail installed successfully
if command -v whiptail &> /dev/null; then
echo "whiptail installed successfully."
else
echo "Failed to install whiptail."
exit 1
fi
else
echo "apt is not available on this system. Cannot install whiptail automatically."
exit 1
fi
fi
PBDEBUG=false
# Check if any arguments
for arg in "$@"; do
case "$arg" in
"bash") BASHARG="bash" ;;
"debug") PBDEBUG=true ;;
"arm64") ARCH="arm64" ;;
"riscv64") ARCH="riscv64" ;;
*)
if [ -d "$arg" ]; then
DISTRO_DIR="$arg"
fi
;;
esac
done
function start() {
set -e
docker build . -t distro-${ARCH} --network=host --no-cache --build-arg DISTRO_DIR=${DISTRO_DIR} --build-arg ROOTFS=${ROOTFS} --target distro-${ARCH}
mkdir -p $ROOTFS
docker run --rm -it --net=host --privileged \
-v ./rootfs:/rootfs \
-e DISTRO_HOSTNAME="${DISTRO_HOSTNAME}" -e ROOTPW="${ROOTPW}" \
-e ROOTFS="${ROOTFS}" \
-e PBDEBUG="${PBDEBUG}" \
distro-${ARCH} $BASHARG
}
function get_directory()
{
mapfile -t dirs < <(find . -maxdepth 2 -type f -name "ENV" -exec dirname {} \; | sort -u)
if [ ${#dirs[@]} -eq 0 ]; then
echo "No directories containing ENV file found."
exit 1
fi
menu_options=()
for i in "${!dirs[@]}"; do
dir_name=$(basename "${dirs[$i]}")
menu_options+=("$((i+1))" "$dir_name")
done
DISTRO_DIR=$(whiptail --title "Select Directory" \
--menu "Choose a directory containing ENV:" \
15 60 5 \
"${menu_options[@]}" \
3>&1 1>&2 2>&3)
if [ $? -ne 0 ] || [ -z "$DISTRO_DIR" ]; then
echo "No selection made. Exiting."
exit 0
fi
# Use the selected number to get the basename directly
DISTRO_DIR=$(basename "${dirs[$((DISTRO_DIR-1))]}")
}
function get_cpu()
{
CHOICE=$(whiptail --title "Architecture Selection" --menu "Choose an architecture:" 15 60 2 \
"1" "ARM64" \
"2" "RISC-V" 3>&1 1>&2 2>&3)
# Check the exit status of whiptail (0 means OK, 1 means Cancel)
if [ $? -eq 0 ]; then
# If-else block based on the user's selection
if [ "$CHOICE" = "1" ]; then
ARCH="arm64"
elif [ "$CHOICE" = "2" ]; then
ARCH="riscv64"
fi
fi
[ -z "$ARCH" ] && exit 0
}
[ -z "$DISTRO_DIR" ] && get_directory
source "$DISTRO_DIR/ENV"
[ -z "$ARCH" ] && get_cpu
start
source makeTar.sh