mirror of
https://github.com/m-housh/dotfiles.git
synced 2026-02-14 06:12:34 +00:00
82 lines
1.4 KiB
Bash
Executable File
82 lines
1.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
# Generates a new run file or webapp file.
|
|
|
|
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="$DEV_ENV/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="$DEV_ENV/env/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
|