Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save JonTheNiceGuy/c00dca0a164d7e4d937679fe78b4efc4 to your computer and use it in GitHub Desktop.

Select an option

Save JonTheNiceGuy/c00dca0a164d7e4d937679fe78b4efc4 to your computer and use it in GitHub Desktop.

deploy.sh for tildagon

This script is to help deploy micropython scripts to tildagon devices. It creates the directory structure for installing your app, and copies the files in. It resets the device before and after to make sure the OS is ready to receive and then is ready for you to activate your script.

Initially based on the advice on the tildagon documentation for running apps this script was enhanced by an LLM to make adjustments like;

  1. Making sure the metadata.json matches the path to your script
  2. Making subdirectories, not just copying files
  3. Ensuring directories do not exist before trying to make them
  4. Checking available space after the deploy script is completed.

Released under the Unlicense due to the presence of LLM created code.

#!/bin/bash
# To invoke, ./deploy.sh badge-app-path local/path/to/source
safe_mkdir() {
local dir="$1"
local parent
parent=$(dirname "$dir")
local base
base=$(basename "$dir")
if ! mpremote fs ls "$parent" 2>/dev/null | grep -q " $base/"; then
mpremote fs mkdir "$dir"
fi
}
src="${2%/}"
mpremote reset
sleep 10
safe_mkdir apps
safe_mkdir "apps/$1"
while IFS= read -r file; do
rel="${file#$src/}"
dir=$(dirname "$rel")
if [ "$dir" != "." ]; then
safe_mkdir "apps/$1/$dir"
fi
if [ "$rel" = "metadata.json" ]; then
tmp=$(mktemp --suffix=.json)
sed "s|\"path\":.*|\"path\": \"apps.$1.app\"|" "$file" > "$tmp"
mpremote fs cp "$tmp" ":/apps/$1/metadata.json"
rm "$tmp"
else
mpremote fs cp "$file" ":/apps/$1/$rel"
fi
done < <(find "$src" -type f -not -path '*/.git/*' -not -path '*/.claude/*')
mpremote exec "import os; s = os.statvfs('/'); print(str(s[0]*s[3]) + ' bytes free')"
mpremote reset
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <https://unlicense.org/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment