From f2e43d0910a8cd6ed41febbe5981006e38861385 Mon Sep 17 00:00:00 2001 From: szaimen <42591237+szaimen@users.noreply.github.com> Date: Sun, 23 Feb 2020 18:05:25 +0100 Subject: [PATCH] create is_app_installed (#1103) Co-authored-by: Daniel Hansson --- apps/collabora.sh | 8 ++++---- apps/fulltextsearch.sh | 39 ++++++++++++++++----------------------- apps/previewgenerator.sh | 2 +- apps/talk.sh | 4 ++-- lib.sh | 14 ++++++++++++-- 5 files changed, 35 insertions(+), 32 deletions(-) diff --git a/apps/collabora.sh b/apps/collabora.sh index c8c93e2a..e2443c62 100644 --- a/apps/collabora.sh +++ b/apps/collabora.sh @@ -58,7 +58,7 @@ then fi # Disable RichDocuments (Collabora App) if activated - if [ -d "$NC_APPS_PATH"/richdocuments ] + if is_app_installed richdocuments then occ_command app:remove richdocuments fi @@ -74,7 +74,7 @@ then docker_prune_this 'collabora/code' # Disable RichDocuments (Collabora App) if activated - if [ -d "$NC_APPS_PATH"/richdocuments ] + if is_app_installed richdocuments then occ_command app:remove richdocuments fi @@ -120,7 +120,7 @@ then fi # Disable OnlyOffice (Collabora App) if activated -if [ -d "$NC_APPS_PATH"/onlyoffice ] +if is_app_installed onlyoffice then occ_command app:remove onlyoffice fi @@ -271,7 +271,7 @@ else fi # Set config for RichDocuments (Collabora App) -if [ -d "$NC_APPS_PATH"/richdocuments ] +if is_app_installed richdocuments then occ_command config:app:set richdocuments wopi_url --value=https://"$SUBDOMAIN" chown -R www-data:www-data "$NC_APPS_PATH" diff --git a/apps/fulltextsearch.sh b/apps/fulltextsearch.sh index 5dd726bf..24e6e78a 100644 --- a/apps/fulltextsearch.sh +++ b/apps/fulltextsearch.sh @@ -39,22 +39,19 @@ then print_text_in_color "$ICyan" "Uninstalling Fulltextsearch..." # Reset Full Text Search to be able to index again, and also remove the app to be able to install it again - if [ -d $NC_APPS_PATH/fulltextsearch ] + if is_app_installed fulltextsearch then print_text_in_color "$ICyan" "Removing old version of Full Text Search and resetting the app..." - sudo -u www-data php $NCPATH/occ fulltextsearch:reset - occ_command app:disable fulltextsearch - rm -rf $NC_APPS_PATH/fulltextsearch + occ_command_no_check fulltextsearch:reset + occ_command app:remove fulltextsearch fi - if [ -d $NC_APPS_PATH/fulltextsearch_elasticsearch ] + if is_app_installed fulltextsearch_elasticsearch then - occ_command app:disable fulltextsearch_elasticsearch - rm -rf $NC_APPS_PATH/fulltextsearch_elasticsearch + occ_command app:remove fulltextsearch_elasticsearch fi - if [ -d $NC_APPS_PATH/files_fulltextsearch ] + if is_app_installed files_fulltextsearch then - occ_command app:disable files_fulltextsearch - rm -rf $NC_APPS_PATH/files_fulltextsearch + occ_command app:remove files_fulltextsearch fi # Remove nc_fts docker if installed @@ -67,22 +64,19 @@ then print_text_in_color "$ICyan" "Reinstalling FullTextSearch..." # Reset Full Text Search to be able to index again, and also remove the app to be able to install it again - if [ -d $NC_APPS_PATH/fulltextsearch ] + if is_app_installed fulltextsearch then print_text_in_color "$ICyan" "Removing old version of Full Text Search and resetting the app..." - sudo -u www-data php $NCPATH/occ fulltextsearch:reset - occ_command app:disable fulltextsearch - rm -rf $NC_APPS_PATH/fulltextsearch + occ_command_no_check fulltextsearch:reset + occ_command app:remove fulltextsearch fi - if [ -d $NC_APPS_PATH/fulltextsearch_elasticsearch ] + if is_app_installed fulltextsearch_elasticsearch then - occ_command app:disable fulltextsearch_elasticsearch - rm -rf $NC_APPS_PATH/fulltextsearch_elasticsearch + occ_command app:remove fulltextsearch_elasticsearch fi - if [ -d $NC_APPS_PATH/files_fulltextsearch ] + if is_app_installed files_fulltextsearch then - occ_command app:disable files_fulltextsearch - rm -rf $NC_APPS_PATH/files_fulltextsearch + occ_command app:remove files_fulltextsearch fi # Remove nc_fts docker if installed @@ -103,12 +97,11 @@ then fi # Disable and remove Nextant + Solr -if [ -d "$NC_APPS_PATH"/nextant ] +if is_app_installed nextant then # Remove Nextant msg_box "We will now remove Nextant + Solr and replace it with Full Text Search" - occ_command app:disable nextant - rm -rf $NC_APPS_PATH/nextant + occ_command app:remove nextant # Remove Solr service solr stop diff --git a/apps/previewgenerator.sh b/apps/previewgenerator.sh index 7e930de4..c60905dd 100644 --- a/apps/previewgenerator.sh +++ b/apps/previewgenerator.sh @@ -46,7 +46,7 @@ then install_and_enable_app previewgenerator # check if the previewgenerator is installed and enabled - if [ -d "$NC_APPS_PATH/previewgenerator" ] + if is_app_installed previewgenerator then # enable previews occ_command config:system:set enable_previews --value=true --type=boolean diff --git a/apps/talk.sh b/apps/talk.sh index b8f1dab5..29bc2f64 100644 --- a/apps/talk.sh +++ b/apps/talk.sh @@ -166,7 +166,7 @@ check_open_port "$TURN_PORT" "$TURN_DOMAIN" # Enable Spreed (Talk) STUN_SERVERS_STRING="[\"$TURN_DOMAIN:$TURN_PORT\"]" TURN_SERVERS_STRING="[{\"server\":\"$TURN_DOMAIN:$TURN_PORT\",\"secret\":\"$TURN_SECRET\",\"protocols\":\"udp,tcp\"}]" -if [ ! -d "$NC_APPS_PATH"/spreed ] +if ! is_app_installed spreed then install_and_enable_app spreed occ_command config:app:set spreed stun_servers --value="$STUN_SERVERS_STRING" --output json @@ -174,7 +174,7 @@ then chown -R www-data:www-data "$NC_APPS_PATH" fi -if [ -d "$NC_APPS_PATH"/spreed ] +if is_app_installed spreed then msg_box "Nextcloud Talk is now installed. For more information about Nextcloud Talk and its mobile apps visit: https://nextcloud.com/talk/" diff --git a/lib.sh b/lib.sh index 32542187..74035418 100644 --- a/lib.sh +++ b/lib.sh @@ -694,9 +694,19 @@ else fi } +#example: is_app_installed documentserver_community +is_app_installed() { +if [ -d "$NC_APPS_PATH/$1" ] +then + return 0 +else + return 1 +fi +} + install_and_enable_app() { # Download and install $1 -if [ ! -d "$NC_APPS_PATH/$1" ] +if ! is_app_installed "$1" then print_text_in_color "$ICyan" "Installing $1..." # occ_command not possible here because it uses check_command and will exit if occ_command fails @@ -713,7 +723,7 @@ or when a new version of the app is released with the following command: rm -Rf "$NCPATH/apps/$1" else # Enable $1 - if [ -d "$NC_APPS_PATH/$1" ] + if is_app_installed "$1" then occ_command app:enable "$1" chown -R www-data:www-data "$NC_APPS_PATH"