#!/bin/bash # Instance Commands Handler # Multi-instance lifecycle for multi-instance-capable apps. Mutating verbs route # through the task system (mirroring `app install`): the WebUI queues a task, the # processor re-invokes the CLI with LIBREPORTAL_TASK_EXEC=1, and only then does # the real work run. No new mutating backend API endpoint is introduced. cliHandleInstanceCommands() { local action="$initial_command2" # --local/--lan is pulled out of the positional list rather than given a fixed # slot, so it can be written anywhere after the verb — `instance create # bookstack home --local` reads naturally and still leaves domain#/subdomain # in their documented positions for callers that pass them. local local_only="false" local -a _pos=() local _a for _a in "$initial_command3" "$initial_command4" "$initial_command5" \ "$initial_command6" "$initial_command7"; do case "$_a" in "--local"|"--lan") local_only="true" ;; *) _pos+=("$_a") ;; esac done local type="${_pos[0]}" local name="${_pos[1]}" local domain_idx="${_pos[2]}" local subdomain="${_pos[3]}" case "$action" in "create") if [[ -z "$type" || -z "$name" ]]; then isNotice "Usage: libreportal instance create [domain_index] [subdomain] [--local]" cliShowInstanceHelp return 1 fi if [[ "$LIBREPORTAL_TASK_EXEC" == "1" ]]; then instanceCreate "$type" "$name" "$domain_idx" "$subdomain" "$local_only" else local _cmd="libreportal instance create $type $name" [[ -n "$domain_idx" ]] && _cmd+=" $domain_idx" [[ -n "$subdomain" ]] && _cmd+=" $subdomain" # Re-invocation must carry the flag or the task-side run would # silently build a Traefik-routed instance instead. [[ "$local_only" == "true" ]] && _cmd+=" --local" cliTaskRun "$_cmd" "install" "${type}_$(instanceIdPart "$name")" fi ;; "remove"|"delete") # Here $type holds the instance slug (positional reuse). local slug="$type" if [[ -z "$slug" ]]; then isNotice "Usage: libreportal instance remove " return 1 fi if [[ "$LIBREPORTAL_TASK_EXEC" == "1" ]]; then instanceRemove "$slug" else cliTaskRun "libreportal instance remove $slug" "uninstall" "$slug" fi ;; "list") instanceList "$type" # $type optional = filter by app type ;; "repair") # Rewrites files in the instance's TEMPLATE dir only — no container is # touched, nothing is reinstalled — so it does not go through the task # system the way create/remove do. $type holds the optional slug # (positional reuse), $name an optional --dry-run. instanceRepair "$type" "$name" ;; *) cliShowInstanceHelp ;; esac }