mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-26 18:31:52 +00:00
* continuous deployment * fix * escape braces in format string * Update upload-ota.sh * curl fail on http error
48 lines
1.4 KiB
Bash
48 lines
1.4 KiB
Bash
#!/bin/bash
|
|
|
|
declare -A params
|
|
while IFS='=' read -r -d '&' key value && [[ -n "$key" ]]; do
|
|
params["$key"]=$value
|
|
done <<<"${QUERY_STRING}&"
|
|
|
|
index_key="${params['key']}"
|
|
if [ -z "$index_key" ] || [ "$index_key" != "$(cat /var/www/index_key.txt)" ]; then
|
|
echo "HTTP/1.1 401 UNAUTHORIZED"
|
|
echo "Content-Type: text/html"
|
|
echo
|
|
echo "UNAUTHORIZED"
|
|
exit
|
|
fi
|
|
|
|
git_hash="${params['gitHash']}"
|
|
version="${params['version']}"
|
|
platform="${params['platform']}"
|
|
shasum="${params['shasum']}"
|
|
if [ -z "$git_hash" ] || [ -z "$version" ] || [ -z "$platform" ] || [ -z "$shasum" ]; then
|
|
echo "HTTP/1.1 400 BAD REQUEST"
|
|
echo "Content-Type: text/html"
|
|
echo
|
|
echo "BAD REQUEST: missing param"
|
|
exit
|
|
fi
|
|
|
|
tmp_file=$(mktemp /var/tmp/tmp.XXXXXXXXXX.squashfs)
|
|
cat > $tmp_file
|
|
|
|
if ! sha256sum $tmp_file | grep "$shasum"; then
|
|
rm $tmp_file
|
|
echo "HTTP/1.1 400 BAD REQUEST"
|
|
echo "Content-Type: text/html"
|
|
echo
|
|
echo "BAD REQUEST: shasum mismatch"
|
|
fi
|
|
|
|
mkdir -p /var/www/resources/eos/${version}/${git_hash}
|
|
mv $tmp_file /var/www/resources/eos/${version}/${git_hash}/startos-${version}-${git_hash}_${platform}.squashfs
|
|
rm /var/www/resources/eos/${version}/eos.${platform}.squashfs
|
|
ln -rs /var/www/resources/eos/${version}/${git_hash}/startos-${version}-${git_hash}_${platform}.squashfs /var/www/resources/eos/${version}/eos.${platform}.squashfs
|
|
|
|
echo "HTTP/1.1 200 OK"
|
|
echo "Content-Type: text/html"
|
|
echo
|
|
echo "OK: Upload successful" |