-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserve.sh
executable file
·126 lines (96 loc) · 3.2 KB
/
serve.sh
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
#!/bin/bash
#
# epaper-idf
#
# Copyright (c) 2021 Jeremy Carter <jeremy@jeremycarter.ca>
#
# This code is released under the license terms contained in the
# file named LICENSE, which is found in the top-level folder in
# this project. You must agree to follow those license terms,
# otherwise you aren't allowed to copy, distribute, or use any
# part of this project in any way.
epaper_idf_serve_set_version() {
VER_FILE=${VER_FILE:-"version.txt"}
VER_MIC_FILE=${VER_MIC_FILE:-"version-micro.txt"}
new_args=($(printf "$1\n" | sed -E 's/v//g' | sed -E 's/\./ /g'))
set -- ${new_args[@]}
if [ $# -ge 1 ]; then
export EPAPER_IDF_VERSION_MAJOR=$1
fi
export EPAPER_IDF_VERSION_MAJOR=${EPAPER_IDF_VERSION_MAJOR:-0}
if [ $# -ge 2 ]; then
export EPAPER_IDF_VERSION_MINOR=$2
fi
export EPAPER_IDF_VERSION_MINOR=${EPAPER_IDF_VERSION_MINOR:-1}
if [ $# -ge 3 ]; then
export EPAPER_IDF_VERSION_MICRO=$3
fi
if [ ! -f "$VER_MIC_FILE" ]; then
export EPAPER_IDF_VERSION_MICRO=${EPAPER_IDF_VERSION_MICRO:-0}
else
EPAPER_IDF_VERSION_MICRO_LAST=$(cat "$VER_MIC_FILE" | sed 's/[\s\n]//g')
export EPAPER_IDF_VERSION_MICRO=${EPAPER_IDF_VERSION_MICRO:-$(( EPAPER_IDF_VERSION_MICRO_LAST + 1 ))}
fi
printf '%s' "$EPAPER_IDF_VERSION_MICRO" | tee "$VER_MIC_FILE" >/dev/null
set -- ${1:-$EPAPER_IDF_VERSION_MAJOR} ${2:-$EPAPER_IDF_VERSION_MINOR} ${3:-$EPAPER_IDF_VERSION_MICRO}
while [ $# -ge 1 ]; do
if [ $# -le 1 ]; then
mic=${1:-$EPAPER_IDF_VERSION_MICRO}
shift
elif [ $# -le 2 ]; then
min=${1:-$EPAPER_IDF_VERSION_MINOR}
shift
elif [ $# -le 3 ]; then
maj=${1:-$EPAPER_IDF_VERSION_MAJOR}
shift
fi
done
export EPAPER_IDF_VERSION=${EPAPER_IDF_VERSION:-"v${maj}.${min}.${mic}"}
printf '%s' "$EPAPER_IDF_VERSION" | tee "$VER_FILE" >/dev/null
}
epaper_idf_serve() {
HOST=${2:-"esprog"}
PORT=${3:-"8089"}
CERT_DIR=${CERT_DIR:-"build/"}
if [ -z ${IDF_PYTHON_ENV_PATH+x} ]; then
echo ""
echo "note: ESP-IDF has not been sourced yet. To speed things up, you can source it first by running the following command:"
echo ""
echo ". idf.env"
echo ""
echo "note: Sourcing ESP-IDF for you now..."
echo ""
. idf.env
fi
# Build latest version of config site:
cd components/epaper-idf-component
./build-web.sh
cd ../..
# Copy sites for GitHub:
rm -rf docs/
cp -r public/ docs/
cd components/epaper-idf-component
rm -rf docs/
cp -r public/ docs/
cd ../..
epaper_idf_serve_set_version $@
echo "Building EpaperIDF firmware version: ${EPAPER_IDF_VERSION}"
go_back() {
cd "$pwd"
}
pwd="$PWD"
cp ca_cert.pem ca_key.pem dhparam.pem "$CERT_DIR"
idf.py build
build_res=$?
if [ $build_res -ne 0 ]; then
return $build_res
fi
cd "$CERT_DIR"
ln -sf "$(basename "$pwd").bin" "firmware.bin"
trap 'go_back' INT
echo
echo "Serving OTA EpaperIDF firmware version: ${EPAPER_IDF_VERSION}"
echo "The device will request firmware from: https://${HOST}:${PORT}/firmware.bin"
openssl s_server -cert ca_cert.pem -key ca_key.pem -dhparam dhparam.pem -accept ${PORT} -WWW
}
epaper_idf_serve $@