-
Notifications
You must be signed in to change notification settings - Fork 8
/
ubuntu-touch-pdk
executable file
·197 lines (174 loc) · 4.42 KB
/
ubuntu-touch-pdk
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#!/usr/bin/env bash
set -e
TMPDIR=""
trap ctrl_c INT
function ctrl_c {
printf "\n\nCTRL-C received\n"
for JOB in $(jobs -p); do
kill -9 "$JOB"
done
exit 1
}
if [ "$(uname -m)" == "aarch64" ] || [ "$(uname -p)" == "arm64" ] || [ "$(uname -m)" == "arm64" ]; then
HOST_ARCH="arm64"
else
HOST_ARCH="amd64"
fi
SCRIPTPATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
PULL_IMG=no
SETUP=no
CLEARCACHE=no
LIST=no
RUN=no
PRINT_VERSION=no
NAME=default
ARCH="$HOST_ARCH"
RELEASE=focal
function printHelp {
printf "usage: %s <options> <command> [<command> ..]\n\n" "$0"
printf "Options:\n"
printf "\t-a=|--arch=: Architecture override (optional, defaults to '%s')\n" "$HOST_ARCH"
printf "\t Possible values: arm64, amd64\n"
printf "\t-r=|--release=: Ubuntu Touch release override (optional, defaults to 'focal')\n"
printf "\t Possible values: noble, focal\n"
printf "\t-n=|--name=: Name of the image (optional, defaults to 'default')\n\n"
printf "Commands:\n"
printf "\tsetup: Host OS preparations (recommended for first-time use)\n"
printf "\tclear: Clean up all images\n"
printf "\tpull: Download pre-generated image\n"
printf "\trun: Run desired image\n"
printf "\tlist: Show list of cached images\n"
}
# Argument parsing
while [[ $# -gt 0 ]]; do
arg="$1"
case $arg in
pull)
PULL_IMG=yes
shift
;;
setup)
SETUP=yes
shift
;;
clear)
CLEARCACHE=yes
shift
;;
easy)
SETUP=yes
PULL_IMG=yes
shift
;;
list)
LIST=yes
shift
;;
run)
RUN=yes
shift
;;
-v|--version)
PRINT_VERSION=yes
shift
;;
"-n="*|"--name="*)
NAME="${arg#*=}"
shift
;;
"-a="*|"--arch="*)
ARCH="${arg#*=}"
shift
;;
"-r="*|"--release="*)
RELEASE="${arg#*=}"
shift
;;
-h|--help)
printHelp
exit 0
;;
*)
printHelp
exit 1
;;
esac
done
# Read common script variables
source "$SCRIPTPATH/scripts/vars.sh"
initCommonVars
mkdir -p "$CONFIG_ROOT"
# Source the config if available
if [ -f "$CONFIG_ROOT/config.sh" ]; then
# shellcheck source=/dev/null
source "$CONFIG_ROOT/config.sh"
IMG_CACHE="$DATA_ROOT/pdk-image-cache"
fi
if [ "$PRINT_VERSION" == "yes" ]; then
printf "%s (%s)" "$VERSION" "$CODENAME"
exit 0
fi
function printSeparator {
printf "#####################################\n"
}
printSeparator
printf "Ubuntu Touch Platform Development Kit\n"
printSeparator
printf "\nExecuting tasks:\n"
printf "\tSetup? %s\n" "$SETUP"
printf "\tClear cache? %s\n" "$CLEARCACHE"
printf "\tList? %s\n" "$LIST"
printf "\tPull image? %s\n" "$PULL_IMG"
printf "\tRun an image? %s\n\n" "$RUN"
source "$SCRIPTPATH/scripts/caches.sh"
source "$SCRIPTPATH/scripts/setup.sh"
source "$SCRIPTPATH/scripts/images.sh"
source "$SCRIPTPATH/scripts/mounts.sh"
initImageVars
initSettingsVars
if [ -z "$IMG_NAME" ]; then
printf "Invalid release '%s' specified.\n" "$RELEASE"
printHelp
exit 1
fi
if [ -z "$DATA_ROOT" ] || [ "$SETUP" == "yes" ]; then
# Warn when something's not right
if [ -z "$DATA_ROOT" ]; then
printf "WARNING: You haven't set up your environment yet. Continuing with setup...\n"
fi
setup
generateSettingsImage
copySettingsIntoImage
fi
# List available images
if [ "$LIST" == "yes" ]; then
listImages
fi
# Clear the cache
if [ "$CLEARCACHE" == "yes" ]; then
clearCaches
fi
# Decide on pulling or creating an image
if [ "$PULL_IMG" == "yes" ]; then
pullLatestImage
fi
# Aaand run it!
if [ "$RUN" == "yes" ]; then
printf "\nName of the environment: %s\n\n" "$NAME"
if [ ! -d "$IMG_CACHE/$NAME" ]; then
printf "Cache directory for image '%s' doesn't exist.\n" "$NAME"
printf "Consider pulling or creating an image yourself.\n"
exit 1
fi
if [ ! -f "$IMG_CACHE/$NAME/hdd.raw" ]; then
printf "Hard disk for image '%s' doesn't exist." "$NAME"
printf "Consider pulling or creating an image yourself."
exit 1
fi
startVirtiofsd
runImage
fi
for JOB in $(jobs -p); do
kill -9 "$JOB"
done
exit 0