forked from ubports/ubports-pdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathubuntu-touch-pdk
executable file
·178 lines (155 loc) · 3.51 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
#!/bin/bash
set -e
TMPDIR=""
trap ctrl_c INT
function ctrl_c {
echo "CTRL-C received"
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"
function printHelp {
echo "usage: $0 <options> <command> [<command> ..]"
echo ""
echo "Options:"
printf "\t-a=|--arch=: Architecture override (optional, defaults to '$HOST_ARCH')\n"
printf "\t Possible values: arm64, amd64\n"
printf "\t-n=|--name=: Name of the image (optional, defaults to 'default')\n"
echo ""
echo "Commands:"
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
;;
clean)
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
;;
-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
source "$CONFIG_ROOT/config.sh"
IMG_CACHE="$DATA_ROOT/pdk-image-cache"
fi
if [ "$PRINT_VERSION" == "yes" ]; then
echo "$VERSION ($CODENAME)"
exit 0
fi
function printSeparator {
echo "#####################################"
}
printSeparator
echo "Ubuntu Touch Platform Development Kit"
printSeparator
echo ""
echo "Executing tasks:"
printf "\tSetup? $SETUP\n"
printf "\tClear cache? $CLEARCACHE\n"
printf "\tList? $LIST\n"
printf "\tPull image? $PULL_IMG\n"
printf "\tRun an image? $RUN\n"
source $SCRIPTPATH/scripts/caches.sh
source $SCRIPTPATH/scripts/setup.sh
source $SCRIPTPATH/scripts/images.sh
source $SCRIPTPATH/scripts/mounts.sh
initImageVars
initSettingsVars
echo ""
# Warn when something's not right
if [ "$DATA_ROOT" == "" ] || [ "$SETUP" == "yes" ]; then
echo "WARNING: You haven't set up your environment yet. Continuing with setup..."
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
echo ""
echo "Name of the environment: $NAME"
echo ""
startVirtiofsd
runImage
fi
for JOB in `jobs -p`; do
kill -9 $JOB
done
exit 0