dumbserve/scripts/publish.sh

107 lines
2.4 KiB
Bash
Raw Normal View History

2022-08-14 15:22:11 +05:30
#!/bin/bash
# Copyright (C) 2022 Aravinth Manivannan <realaravinth@batsense.net>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# publish.sh: grab bin from docker container, pack, sign and upload
# $2: binary version
# $3: Docker img tag
# $4: dumbserve username
# $5: dumbserve password
2022-08-14 15:22:11 +05:30
set -xEeuo pipefail
2022-08-14 17:38:12 +05:30
DUMBSERVE_USERNAME=$4
DUMBSERVE_PASSWORD=$5
DUMBSERVE_HOST="https://$DUMBSERVE_USERNAME:$DUMBSERVE_PASSWORD@dl.batsense.net"
2022-08-14 15:22:11 +05:30
NAME=dumbserve
KEY=7981CA5AE57350D9F9BF5F6456CB9AF170E4A02F
2022-08-14 15:22:11 +05:30
TMP_DIR=$(mktemp -d)
FILENAME="$NAME-$2-linux-amd64"
TARBALL=$TMP_DIR/$FILENAME.tar.gz
TARGET_DIR="$TMP_DIR/$FILENAME/"
mkdir -p $TARGET_DIR
2022-08-14 15:22:11 +05:30
DOCKER_IMG="realaravinth/$NAME:$3"
get_bin(){
echo "[*] Grabbing binary"
container_id=$(docker create $DOCKER_IMG)
docker cp $container_id:/usr/local/bin/$NAME $TARGET_DIR/
docker rm -v $container_id
}
copy() {
echo "[*] Copying dist assets"
cp README.md $TARGET_DIR
cp LICENSE.md $TARGET_DIR
# cp CHANGELOG.md $TARGET_DIR
# cp docker-compose.yml $TARGET_DIR
2022-08-14 15:22:11 +05:30
# mkdir $TARGET_DIR/docs
# cp docs/DEPLOYMENT.md $TARGET_DIR/docs
# cp docs/CONFIGURATION.md $TARGET_DIR/docs
2022-08-14 15:22:11 +05:30
get_bin
}
pack() {
echo "[*] Creating dist tarball"
tar -cvzf $TARBALL $TARGET_DIR
}
checksum() {
echo "[*] Generating dist tarball checksum"
sha256sum $TARBALL > $TARBALL.sha256
}
sign() {
echo "[*] Signing dist tarball checksum"
gpg --local-user $KEY --output $TARBALL.asc --sign --detach --armor $TARBALL
2022-08-14 15:22:11 +05:30
}
delete_dir() {
2022-08-14 17:38:12 +05:30
curl --location --request DELETE "$DUMBSERVE_HOST/api/v1/files/delete" \
2022-08-14 15:22:11 +05:30
--header 'Content-Type: application/json' \
--data-raw "{
\"path\": \"$1\"
}"
}
upload_dist() {
delete_dir $1
for file in $TARBALL $TARBALL.asc $TARBALL.sha256
do
curl -v \
-F upload=@$file \
2022-08-14 17:38:12 +05:30
"$DUMBSERVE_HOST/api/v1/files/upload?path=$1/"
2022-08-14 15:22:11 +05:30
done
}
publish() {
copy
pack
checksum
sign
upload_dist $2
2022-08-14 15:22:11 +05:30
}
$1 $@