-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake_release_input_dir.sh
More file actions
executable file
·106 lines (82 loc) · 2.84 KB
/
make_release_input_dir.sh
File metadata and controls
executable file
·106 lines (82 loc) · 2.84 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
#!/usr/bin/env bash
# A simple script that takes a firmware version as input and generates a new directory with the
# KeyOS firmware components inside it.
#
# These components and their locations inside the `keyos` repository are:
#
# - app.bin | target/armv7a-unknown-xous-elf/release/images/app.bin
# - apps/ | target/armv7a-unknown-xous-elf/release/apps/
#
# Requires the `keyos` repository to run. Path to it can be passed as an optional last argument
# to this script.
set -e
# Print an error message in bold red.
# Usage: error "Your error message"
error() {
echo -e "\033[1;31mERROR\033[0m $1"
}
# Print a warning message in bold yellow.
# Usage: warn "Your warning message"
warn() {
echo -e "\033[1;33mWARN\033[0m $1"
}
# Print an info message in bold green.
# Usage: info "Your info message"
info() {
echo -e "\033[1;32mINFO\033[0m $1"
}
if [ ! -d .git ] || [ ! -f .git/config ] || ! grep -q "Foundation-Devices/KeyOS-Releases" .git/config; then
error "please run the script from the root of the 'KeyOS-Releases' repository"
exit 1
fi
if [ "$#" -ne 1 ] && [ "$#" -ne 2 ]; then
error "invalid number of arguments
Usage: make_release_input_dir.sh <firmware_version> [<path_to_keyos_repo>]"
exit 1
fi
# Also the output directory.
FIRMWARE_VERSION=$1
KEYOS_DIR=${2:-../keyos}
START_DIR=$(pwd)
if [ -d "$FIRMWARE_VERSION" ]; then
warn "Directory '$FIRMWARE_VERSION' already exists. Would you like to overwrite its contents? (y/n)"
read -r response
if [[ "$response" == "y" ]]; then
rm -rf "$FIRMWARE_VERSION"
else
info "Exiting without making any changes."
exit 0
fi
fi
info "checking 'keyos' directory"
if [ ! -d "$KEYOS_DIR" ]; then
error "keyos project not found at '$(realpath -m -q "$KEYOS_DIR")'. \
Please clone it from https://github.com/Foundation-Devices/keyos"
exit 1
fi
cd "$KEYOS_DIR"
info "checking 'keyos' git status"
if [ ! -d .git ]; then
error "keyos directory at '$(pwd)' is not a git repository"
exit 1
fi
if [ -n "$(git status --porcelain)" ]; then
error "keyos repository at '$(pwd)' has uncommitted changes. Please commit or stash them before running this script."
exit 1
fi
KEYOS_COMMIT=$(git rev-parse HEAD)
info "generating firmware components in 'keyos'"
cargo xtask build --dont-sign --reproducible
cd "$START_DIR"
info "preparing release input directory"
mkdir "$FIRMWARE_VERSION"
COMMITS_FILE="$START_DIR/keyos-commits.txt"
if [ -f "$COMMITS_FILE" ]; then
tmp_file="${COMMITS_FILE}.tmp"
grep -v -F "$FIRMWARE_VERSION " "$COMMITS_FILE" > "$tmp_file" || true
mv "$tmp_file" "$COMMITS_FILE"
fi
echo "$FIRMWARE_VERSION $KEYOS_COMMIT" >> "$COMMITS_FILE"
cp "$KEYOS_DIR/target/armv7a-unknown-xous-elf/release/images/app.bin" "$FIRMWARE_VERSION"
cp -r "$KEYOS_DIR/target/armv7a-unknown-xous-elf/release/apps/" "$FIRMWARE_VERSION"
info "done"