Skip to content

Instantly share code, notes, and snippets.

@ariary
Last active July 12, 2022 14:25
Show Gist options
  • Save ariary/2db681e3c4ae94901476dffe870119dc to your computer and use it in GitHub Desktop.
Save ariary/2db681e3c4ae94901476dffe870119dc to your computer and use it in GitHub Desktop.
Deploy binary to a worlwide reachable HTTP endpoint using surge (binary raw + binary embed in HTML)
#!/bin/bash
export ROSE='\033[1;35m'
export NC='\033[0m'
if [ $# -lt 1 ];then
echo "Usage: ./surge-binary-deployment.sh [BINARY_FILE]"
else
BINARY_PATH=$1
BINARY_FILENAME=$(echo $BINARY_PATH | rev | cut -d'/' -f 1 | rev)
SUFFIX=$RANDOM
BINARY_CPY=cpy_$BINARY_FILENAME
cp $BINARY_PATH $BINARY_CPY
## EmbedInHTML
git clone https://github.com/Arno0x/EmbedInHTML.git > /dev/null 2>&1
#EmbedInHTML limitation force creation and copy
cp -r EmbedInHTML/templates .
mkdir output
python2 EmbedInHTML/embedInHTML.py -k mysecretkey -f $BINARY_PATH -o $BINARY_FILENAME.html -m octet-stream
rm -rf EmbedInHTML
mv output/$BINARY_FILENAME.html .
rm -rf output
rm -rf templates
## Surge
touch .surgeignore
echo "*" > .surgeignore
echo "!*$BINARY_FILENAME*" >> .surgeignore
surge --domain $BINARY_FILENAME$SUFFIX.surge.sh .
echo
echo -e "${ROSE}$BINARY_FILENAME raw:${NC} https://$BINARY_FILENAME$SUFFIX.surge.sh/$BINARY_CPY"
echo -e "${ROSE}$BINARY_FILENAME in HTML (browser):${NC} https://$BINARY_FILENAME$SUFFIX.surge.sh/$BINARY_FILENAME.html"
echo
while true; do
read -p "Do you to teardown surge deployment? " yn
case $yn in
[Yy]* ) break;;
[Nn]* ) exit;;
* ) echo "Please answer yes or no.";;
esac
done
surge teardown $BINARY_FILENAME$SUFFIX.surge.sh
rm .surgeignore $BINARY_FILENAME.html $BINARY_CPY
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment