Skip to content
Snippets Groups Projects
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
freedombone-upgrade 3.08 KiB
#!/bin/bash
#
# .---.                  .              .
# |                      |              |
# |--- .--. .-.  .-.  .-.|  .-. .--.--. |.-.  .-. .--.  .-.
# |    |   (.-' (.-' (   | (   )|  |  | |   )(   )|  | (.-'
# '    '     --'  --'  -' -  -' '  '   -' -'   -' '   -  --'
#
#                    Freedom in the Cloud
#
# Command to upgrade the system

# License
# =======
#
# Copyright (C) 2015-2016 Bob Mottram <bob@freedombone.net>
#
# 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/>.

PROJECT_NAME='freedombone'

PROJECT_DIR="$HOME/${PROJECT_NAME}"

# An optional configuration file which overrides some of these variables
CONFIGURATION_FILE="$HOME/${PROJECT_NAME}.cfg"

PROJECT_REPO="https://github.com/bashrc/${PROJECT_NAME}"

CURRENT_BRANCH=master

# clear temporary files
rm -rf /tmp/*

UTILS_FILES=/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*
for f in $UTILS_FILES
do
    source $f
done

read_config_param PROJECT_REPO
read_config_param DEVELOPMENT_BRANCH

DEVELOPMENT_BRANCH=master
write_config_param "DEVELOPMENT_BRANCH" "$DEVELOPMENT_BRANCH"

if [ $DEVELOPMENT_BRANCH ]; then
    if [ ${#DEVELOPMENT_BRANCH} -gt 0 ]; then
        CURRENT_BRANCH=$DEVELOPMENT_BRANCH
    fi
fi

if grep -q "cat /root/dbpass" /usr/bin/backupdatabases; then
    # update to using the password manager
    sed -i "s|cat /root/dbpass|freedombone-pass -u root -a mariadb|g" /usr/bin/backupdatabases
fi

update-ca-certificates

# remove any keyserver log files
if [ -d /var/lib/sks/DB ]; then
    cd /var/lib/sks/DB
    db_archive -d
fi

if [ ! -d $PROJECT_DIR ]; then
    git_clone $PROJECT_REPO $PROJECT_DIR
fi

if [ -d $PROJECT_DIR ]; then
    if [ -f $CONFIGURATION_FILE ]; then
        cd $PROJECT_DIR
        rm -rf $PROJECT_DIR/locale/*
        if [[ "$CURRENT_BRANCH" == *"master" ]]; then
            git_pull $PROJECT_REPO
        else
            git_pull $PROJECT_REPO origin/$DEVELOPMENT_BRANCH
        fi
        git checkout stretch
        make install
        if [ -d /usr/share/${PROJECT_NAME} ]; then
            chown -R root:root /usr/share/${PROJECT_NAME}
            chmod -R +r /usr/share/${PROJECT_NAME}
        fi

        ${PROJECT_NAME} -c $CONFIGURATION_FILE
        if [ ! "$?" = "0" ]; then
            lockdown_permissions
            exit 453536
        fi

        lockdown_permissions
        defrag_filesystem
    fi
fi

# If logging was left on then turn it off
${PROJECT_NAME}-logging off

if [ -f /usr/bin/reset-tripwire ]; then
    echo '

' | reset-tripwire
fi

# deliberately there is no 'exit 0' here