feat: Adds gen script to generate new runs or webapps.

This commit is contained in:
2025-09-28 16:12:04 -04:00
parent 474746e296
commit d5ab230d3f
2 changed files with 91 additions and 23 deletions

83
gen Executable file
View File

@@ -0,0 +1,83 @@
#!/usr/bin/env bash
# Generates a new run file or webapp file.
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
if [ -z "$DEV_ENV" ]; then
echo "env var DEV_ENV needs to be present"
exit 1
fi
file=""
run="0"
webapp="0"
while [[ $# -gt 0 ]]; do
echo "Arg: \"$1\""
if [[ "$1" == "run" ]]; then
run="1"
elif [[ "$1" == "webapp" ]]; then
webapp="1"
else
file="$1"
fi
shift
done
log() { echo "$1"; }
generate-new-run() {
local dest="$script_dir/runs/$file"
if [ -f "$dest" ]; then
log "file exists: $dest"
exit 1
fi
log "Creating new run: $dest"
printf "#!/usr/bin/env bash\n\n" >$dest
printf "yay \${1:-\"-S --noconfirm\"} # packages\n" >>$dest
chmod +x $dest
}
generate-new-webapp() {
local dest="$script_dir/webapps/$file"
if [[ ! $dest =~ \.json$ ]]; then
dest="$dest.json"
fi
if [ -f "$dest" ]; then
log "dest exists: $dest"
exit 1
fi
log "Creating new webapp: $dest"
printf "{\n" >$dest
printf " \"name\": \"My App\",\n" >>$dest
printf " \"url\": \"https://example.com\",\n" >>$dest
printf " \"icon\": \"https://icon.com\"\n" >>$dest
printf "}" >>$dest
}
############################## MAIN ##############################
if [[ -z "$file" ]]; then
log "No file name supplied."
exit 1
fi
if [[ $run == "1" ]]; then
generate-new-run
elif [[ $webapp == "1" ]]; then
generate-new-webapp
else
log "Must supply either \"run\" or \"webapp\" option."
exit 1
fi