Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Fix script

...

Code Block
languagebash
themeRDark
#!/bin/bash

##
## i-doit jobs
##

##
## Copyright (C) 2017-18 synetics GmbH, <https://i-doit.com/>
##
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU Affero General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU Affero General Public License for more details.
##
## You should have received a copy of the GNU Affero General Public License
## along with this program. If not, see <http://www.gnu.org/licenses/>.
##

set -euo pipefail
IFS=$'\n\t'

##
## Configuration
##

CONSOLE_BIN="/usr/local/bin/idoit"
INSTANCE_PATH="/var/www/html/i-doit"
APACHE_USER="www-data"
IDOIT_USERNAME="admin"
IDOIT_PASSWORD="admin"
TENANT_ID="1"

##--------------------------------------------------------------------------------------------------

function execute {
    local prefix=""
    local suffix="--user $IDOIT_USERNAME --password $IDOIT_PASSWORD --tenantId $TENANT_ID"

    test "$(whoami)" != "$APACHE_USER" && prefix="sudo -u $APACHE_USER "

    log "Clear cachesArchive i-doit logbook"
    eval "${prefix}rm -rf ${INSTANCECONSOLE_PATH}/temp/*BIN} logbook-archive $suffix" || \
        abort "Command 'logbook-archive' failed"Unable
   to clearlog caches""

    log "Clear updatesCleanup i-doit rights"
    eval "${prefix}rm -rf ${INSTANCECONSOLE_PATH}/updates/versions/*BIN} auth-cleanup $suffix" || \
        abort "Command 'auth-cleanup' failed"Unable
   to clearlog updates""

    log "ArchivePurge i-doitunfinished logbookobjects"
    eval "${prefix}${CONSOLE_BIN} logbook-archivesystem-objectcleanup --objectStatus 1 $suffix" || \
        abort "Command 'logbooksystem-archiveobjectcleanup' failed"
    log ""

    log "Cleanup i-doit rightsRe-create search index"
    eval "${prefix}${CONSOLE_BIN} authsearch-cleanupindex $suffix" || \
        abort "Command 'auth-cleanup' failed"
    logabort "Command 'search-index' failed"

    log "PurgeSend unfinished objectsnotifications"
    eval "${prefix}${CONSOLE_BIN} system-objectcleanup --objectStatus 1 notifications-send $suffix" || \
        abort "Command 'systemnotifications-objectcleanupsend' failed"
    log ""

    log "Re-create search indexClear caches"
    eval "${prefix}rm -rf ${CONSOLEINSTANCE_BIN} search-index $suffixPATH}/temp/*" || \
        abort "Command 'search-index' failedUnable to clear caches"

    log "SendClear notificationsupdates"
    eval "${prefix}rm -rf ${CONSOLEINSTANCE_BIN} notifications-send $suffixPATH}/updates/versions/*" || \
        abort "Command 'notifications-send' failedUnable to clear updates"
}

function setup {
    test -x "$CONSOLE_BIN" || \
        abort "Script '${CONSOLE_BIN}' not found"

    test -d "$INSTANCE_PATH" || \
        abort "No i-doit instance found under '${INSTANCE_PATH}'"
}

function log {
    echo -e "$1"
}

function finish {
    log "Done. Have fun :-)"
    exit 0
}

function abort {
    echo -e "$1"  1>&2
    echo "Operation failed. Please check what is wrong and try again." 1>&2
    exit 1
}

##--------------------------------------------------------------------------------------------------

if [[ "${BASH_SOURCE[0]}" = "$0" ]]; then
    setup && execute && finish
fi

...