-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_image.sh
More file actions
89 lines (80 loc) · 2.6 KB
/
build_image.sh
File metadata and controls
89 lines (80 loc) · 2.6 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
#!/usr/bin/env bash
set -o errexit -o pipefail -o noclobber -o nounset
PWD="$(pwd)"
PROJECT_DIR_NAME="PSX-Minecraft"
# Ensure we work from the project base dir to avoid
# weird mounting behaviour when running container
case "$(basename "$PWD")" in
"$PROJECT_DIR_NAME") ;;
*)
echo "[ERROR] This script must be run from the $PROJECT_DIR_NAME directory, not $PWD"
exit 1
;;
esac
# Ignore errexit with `&& true`
getopt --test > /dev/null && true
if [[ $? -ne 4 ]]; then
echo '[ERROR] getopt invocation failed.'
exit 1
fi
function printHelp() {
echo "Usage: ./build_image.sh [<options>]"
echo "Options:"
echo " -h | --help Print this help message"
echo " -c | --commit=<commit ish> SDK commit-ish to check out (default: multiple-allocators)"
echo " -r | --repo=<SDK repo> Namespaced SDK on GitHub (default: EngineersBox/PSn00bSDK)"
echo " -a | --allocator=<type> Allocator type to use if using the EngineersBox/PSn00bSDK repo with multiple-allocators (default: TLSF)"
echo " -i | --image=<image:tag> Specify which image to use when building (default: psxmc:latest)"
}
# Note that options with a ':' require an argument
LONGOPTS=help,commit:,repo:,allocator:,image:
OPTIONS=hc:r:a:i:
# 1. Temporarily store output to be able to check for errors
# 2. Activate quoting/enhanced mode (e.g. by writing out “--options”)
# 3. Pass arguments only via -- "$@" to separate them correctly
# 4. If getopt fails, it complains itself to stdout
PARSED=$(getopt --options=$OPTIONS --longoptions=$LONGOPTS --name "$0" -- "$@") || exit 2
# Read getopt’s output this way to handle the quoting right:
eval set -- "$PARSED"
commit="multiple-allocators"
repo="EngineersBox/PSn00bSDK"
allocator="TLSF"
image="psxmc:latest"
# Handle options in order and nicely split until we see --
while true; do
case "$1" in
-h|--help)
printHelp
exit 1
;;
-c|--commit)
commit="$2"
shift 2
;;
-r|--repo)
repo="$2"
shift 2
;;
-a|--allocator)
allocator="$2"
shift 2
;;
-i|--image)
image="$2"
shift 2
;;
--)
shift
break
;;
*)
echo "[ERROR] Unknown option encountered: $1"
exit 3
;;
esac
done
docker build "$image" \
--build-arg="REPO_TARGET=$repo" \
--build-arg="REPO_COMMIT_ISH=$commit" \
--build-arg="PSN00BSDK_LIBC_ALLOCATOR=$allocator" \
-f Dockerfile .