feat: Adds functionality to use a json file for install or uninstall webapp scripts.

This commit is contained in:
2025-09-28 18:57:56 -04:00
parent a05e8f41bd
commit 1a3442dee7
3 changed files with 46 additions and 12 deletions

View File

@@ -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 can act as a stand alone application and launched from an application
launcher. launcher.
USAGE: install-webapp [-n <name>] [-u <url>] [-i <icon>] [-e <exec-cmd>] [-m <mime-types>] [-h] [args...] USAGE: install-webapp [-n <name>] [-u <url>] [-i <icon>] [-e <exec-cmd>] [-m <mime-types>] [-f <file>] [-h] [args...]
OPTIONS: OPTIONS:
-n | --name: The name of the application. -n | --name: The name of the application.
@@ -16,6 +16,7 @@ OPTIONS:
-i | --icon: The icon for the application. -i | --icon: The icon for the application.
-e | --exec: Custom execution command (optional). -e | --exec: Custom execution command (optional).
-m | --mime-types: MIME-types for the application (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. -h | --help: Show usage information.
EXAMPLES: EXAMPLES:
@@ -32,6 +33,10 @@ Calling the app with named arguments:
--url "https://awesome.com" \\ --url "https://awesome.com" \\
--icon "https://awesome.com/assets/icon.png" --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 It is also possible to use only positional arguments with out their key. They can be passed in the order as
they're listed. 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 Interactive sessions do not give the option to use a custom execution command or supply the
MIME types, which are less frequently used options. 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 EOF
} }
@@ -56,6 +71,7 @@ declare -a icon_ref
declare -a custom_exec # Optional custom exec command declare -a custom_exec # Optional custom exec command
declare -a mime_types # Optional mime types declare -a mime_types # Optional mime types
declare -a help_flag declare -a help_flag
declare -a file_mode
declare INTERACTIVE_MODE=false declare INTERACTIVE_MODE=false
zparseopts -D -F -K -- \ zparseopts -D -F -K -- \
@@ -64,6 +80,7 @@ zparseopts -D -F -K -- \
{i,-icon}:=icon_ref \ {i,-icon}:=icon_ref \
{e,-exec}:=custom_exec \ {e,-exec}:=custom_exec \
{m,-mime-types}:=mime_types \ {m,-mime-types}:=mime_types \
{f,-file}:=file_mode \
{h,-help}=help_flag {h,-help}=help_flag
[ ${#help_flag[@]} -gt 0 ] && usage && exit 0 [ ${#help_flag[@]} -gt 0 ] && usage && exit 0
@@ -75,6 +92,16 @@ zparseopts -D -F -K -- \
[ -n "$4" ] && custom_exec+=("$4") [ -n "$4" ] && custom_exec+=("$4")
[ -n "$5" ] && mime_types+=("$5") [ -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. # 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 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" 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 fi
# Ensure valid execution # 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!" echo "You must set app name, app URL, and icon URL!"
exit 1 exit 1
fi fi

View File

@@ -3,7 +3,18 @@
# Uninstall's a web app, including it's icon. # Uninstall's a web app, including it's icon.
app_dir="$HOME/.local/share/applications" 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 if [[ -z "$file" ]]; then
echo -e "Must supplye a web app name to uninstall.\n\n" echo -e "Must supplye a web app name to uninstall.\n\n"

12
webapp
View File

@@ -46,7 +46,7 @@ log() {
} }
install() { install() {
local file=$(cat $1) local file=$1
local script="${script_dir}/env/.local/scripts/install-webapp" local script="${script_dir}/env/.local/scripts/install-webapp"
if [[ ! -x $script ]]; then if [[ ! -x $script ]]; then
@@ -65,17 +65,11 @@ install() {
log "Installing webapp from spec: $1" log "Installing webapp from spec: $1"
if [[ $dry_run == "0" ]]; then if [[ $dry_run == "0" ]]; then
$script \ $script --file $file
--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')
fi fi
} }
uninstall() { uninstall() {
local file=$(cat $1)
local script="${script_dir}/env/.local/scripts/uninstall-webapp" local script="${script_dir}/env/.local/scripts/uninstall-webapp"
if [[ ! -x $script ]]; then if [[ ! -x $script ]]; then
@@ -86,7 +80,7 @@ uninstall() {
log "Uninstalling webapp from spec: $1" log "Uninstalling webapp from spec: $1"
if [[ $dry_run == "0" ]]; then if [[ $dry_run == "0" ]]; then
$script $(echo $file | jq -r '.name') $script --file $1
fi fi
} }