diff --git a/env/.local/scripts/install-webapp b/env/.local/scripts/install-webapp index bc88a6e..a67bedb 100755 --- a/env/.local/scripts/install-webapp +++ b/env/.local/scripts/install-webapp @@ -8,7 +8,7 @@ Generates a '.desktop' file for a web application, so that it can act as a stand alone application and launched from an application launcher. -USAGE: install-webapp [-n ] [-u ] [-i ] [-e ] [-m ] [-h] [args...] +USAGE: install-webapp [-n ] [-u ] [-i ] [-e ] [-m ] [-f ] [-h] [args...] OPTIONS: -n | --name: The name of the application. @@ -16,6 +16,7 @@ OPTIONS: -i | --icon: The icon for the application. -e | --exec: Custom execution command (optional). -m | --mime-types: MIME-types for the application (optional). + -f | --file: Install from a spec in a json file. -h | --help: Show usage information. EXAMPLES: @@ -32,6 +33,10 @@ Calling the app with named arguments: --url "https://awesome.com" \\ --icon "https://awesome.com/assets/icon.png" +Using a json file as input: + + $ install-webapp --file myapp.json + It is also possible to use only positional arguments with out their key. They can be passed in the order as they're listed. @@ -47,6 +52,16 @@ can either be the full path to the file or a file name of an icon located in '~/ Interactive sessions do not give the option to use a custom execution command or supply the MIME types, which are less frequently used options. +If using a json spec file, all keys are the same as their option name, except for mime-types use 'mime_types' as the +key in the json object. Although the 'exec' and 'mime_types' are not required in the spec file. An common json spec +file example would look like: + +{ + "name": "My Awesome App", + "url": "https://awesome.com", + "icon: "https://awesome.com/assets/icon.png" +} + EOF } @@ -56,6 +71,7 @@ declare -a icon_ref declare -a custom_exec # Optional custom exec command declare -a mime_types # Optional mime types declare -a help_flag +declare -a file_mode declare INTERACTIVE_MODE=false zparseopts -D -F -K -- \ @@ -64,6 +80,7 @@ zparseopts -D -F -K -- \ {i,-icon}:=icon_ref \ {e,-exec}:=custom_exec \ {m,-mime-types}:=mime_types \ + {f,-file}:=file_mode \ {h,-help}=help_flag [ ${#help_flag[@]} -gt 0 ] && usage && exit 0 @@ -75,6 +92,16 @@ zparseopts -D -F -K -- \ [ -n "$4" ] && custom_exec+=("$4") [ -n "$5" ] && mime_types+=("$5") +# If passed in a json spec file. +if [[ -n "$file_mode" ]]; then + file=$(cat ${file_mode[-1]}) + app_name+=$(echo $file | jq -r '.name') + app_url+=$(echo $file | jq -r '.url') + icon_ref+=$(echo $file | jq -r '.icon') + custom_exec+=$(echo $file | jq -r '.exec') + mime_types+=$(echo $file | jq -r '.mime_types') +fi + # Check if proper arguments were passed in. Start interactive mode if not. if [[ -z "$app_name[-1]" || -z "$app_url[-1]" || -z "$icon_ref[-1]" ]]; then echo -e "\e[32mLet's create a new web app you can start with the app launcher.\n\e[0m" @@ -87,7 +114,9 @@ else fi # Ensure valid execution -if [[ -z "$app_name[-1]" || -z "$app_url[-1]" || -z "$icon_ref[-1]" ]]; then +if [[ -z "$app_name[-1]" || "$app_name[-1]" == "null" || + -z "$app_url[-1]" || "$app_url[-1]" == "null" || + -z "$icon_ref[-1]" || "$icon_ref[-1]" == "null" ]]; then echo "You must set app name, app URL, and icon URL!" exit 1 fi diff --git a/env/.local/scripts/uninstall-webapp b/env/.local/scripts/uninstall-webapp index 90a31de..fc9d582 100755 --- a/env/.local/scripts/uninstall-webapp +++ b/env/.local/scripts/uninstall-webapp @@ -3,7 +3,18 @@ # Uninstall's a web app, including it's icon. app_dir="$HOME/.local/share/applications" -file="$1" +spec="" +file="" + +while [[ $# -gt 0 ]]; do + if [[ $1 =~ "-f" ]] || [[ $1 =~ "--file" ]]; then + shift + file=$(jq -r '.name' $1) + else + file=$1 + fi + shift +done if [[ -z "$file" ]]; then echo -e "Must supplye a web app name to uninstall.\n\n" diff --git a/webapp b/webapp index 690fa32..3080c50 100755 --- a/webapp +++ b/webapp @@ -46,7 +46,7 @@ log() { } install() { - local file=$(cat $1) + local file=$1 local script="${script_dir}/env/.local/scripts/install-webapp" if [[ ! -x $script ]]; then @@ -65,17 +65,11 @@ install() { log "Installing webapp from spec: $1" if [[ $dry_run == "0" ]]; then - $script \ - --name $(echo $file | jq -r '.name') \ - --url $(echo $file | jq -r '.url') \ - --icon $(echo $file | jq -r '.icon') \ - --exec $(echo $file | jq -r '.exec') \ - --mime-types $(echo $file | jq -r '.mime_types') + $script --file $file fi } uninstall() { - local file=$(cat $1) local script="${script_dir}/env/.local/scripts/uninstall-webapp" if [[ ! -x $script ]]; then @@ -86,7 +80,7 @@ uninstall() { log "Uninstalling webapp from spec: $1" if [[ $dry_run == "0" ]]; then - $script $(echo $file | jq -r '.name') + $script --file $1 fi }