You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

292 lines
8.1 KiB

#!/bin/bash
# Author: Tealk
# Repo: https://codeberg.org/Tealk/shell-administration-script
function CONFIG() {
rootdir=$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")
cd "${rootdir}" || exit
local title="Config File"
if [ -f "config.sh" ]; then
mv config.sh config
fi
if [ -f "/usr/bin/manage.sh" ]; then
mv /usr/bin/manage.sh /usr/bin/manage
fi
# shellcheck disable=SC1091
if ! source config >/dev/null 2>&1; then
# shellcheck source=.manage/dependencies
source .manage/dependencies
# shellcheck source=.manage/config_sample
source .manage/config_sample
if [[ "yes" == $(ASKYN "There is no Config file, create one?") ]]; then
cp .manage/config_sample config
SYMLINK
printf "Everything has been set up successfully. now you can edit config and then run the script again."
exit 1
else
reason="No config file"
ERROR exit
fi
else
if ! [ "${VERSION}" = "9" ]; then
reason="The Config is outdated please have a look into the config.sample and update."
ERROR exit
fi
fi
}
# shellcheck disable=SC2120
function SYMLINK() {
if [ ! -f "/usr/bin/manage" ]; then
if [[ "yes" == $(ASKYN "Make script executable without enter path? (create /usr/bin/manage)") ]]; then
# shellcheck disable=SC2016
printf '#!/bin/bash\nchmod +x %s/manage\nbash %s/manage "$1"\n' "$rootdir" "$rootdir" >/usr/bin/manage
if [ ! -f "/usr/bin/manage" ]; then
reason="can't create file /usr/bin/manage"
ERROR exit
else
chmod +x /usr/bin/manage
printf "%b %b %s\\n" "${COL_LIGHT_GREEN}Symlink was created and the script can now be called from anywhere via ${COL_NC}'manage'"
fi
fi
else
if [[ "yes" == $(ASKYN "Remove (/usr/bin/manage)?") ]]; then
if ! rm "/usr/bin/manage"; then
reason="can't remove file /usr/bin/manage"
ERROR exit
else
chmod +x /usr/bin/manage
printf "%b %b %s\\n" "${COL_LIGHT_GREEN}Symlink was removed ${COL_NC}"
fi
fi
fi
}
function ASKYN() {
read -r -t 300 -p "$1 ([y]es or [n]o): "
case ${REPLY,,} in
y | yes)
echo "yes"
;;
*)
echo "no"
;;
esac
}
function UPUPDATER() {
if [ "${SELFUPDATE}" = 'stable' ] || [ "${SELFUPDATE}" = 'develop' ]; then # ask to apply update
# shellcheck source=.manage/web/upgrade
source .manage/git/check selfupdate || exit
# shellcheck source=.manage/web/download
source .manage/git/download selfupdate || exit
fi
}
function CHMODX() {
if ! find .manage/ -type f -exec chmod +x {} \; >/dev/null 2>&1; then
reason="can't set file execute permissions in .manage/"
ERROR
fi
}
function ERROR() {
printf "%b %b %s\\n" "${OVER}" "${CROSS}" "${title}"
if [ -n "$reason" ]; then
printf "%b %b %s\\n" "\t${COL_LIGHT_RED}${reason}${COL_NC}"
fi
if [[ ! "yes" == $(ASKYN "Ignore errors and continue?") ]] || [[ $1 == "exit" ]]; then
exit 1
fi
}
case "$1" in
backup)
CONFIG
# shellcheck source=.manage/fullbackup
source .manage/fullbackup || exit
exit 1
;;
symlink)
CONFIG
SYMLINK
exit 1
;;
*)
CONFIG
UPUPDATER
CHMODX
while :; do
clear
echo " M A I N - M E N U"
echo ""
echo "1. Exit"
echo "2. Nextcloud"
echo "3. Update phpMyAdmin"
echo "4. Update MediaWiki"
echo "5. Update Collabora"
echo "6. Update BookStack"
echo "7. Update Friendica"
echo "8. Update FreshRSS"
echo "9. Update Writefreely"
echo -n "Please enter option: "
read -r opt
clear
case ${opt} in
1)
echo "Bye ${USER}"
exit 1
;;
2)
NEXTCLOUD
# shellcheck source=.manage/nextcloud
source .manage/nextcloud || exit
exit 1
;;
3)
printf "%b %b %s\\n" "Update phpMyAdmin"
PHPMYADMIN
read -rp "Enter versions number: e.g. 5.1.1: " VERSION
# shellcheck source=.manage/web/backup
source .manage/web/backup || exit
# shellcheck source=.manage/web/download
source .manage/web/download || exit
# shellcheck source=.manage/web/unpack
source .manage/web/unpack || exit
# shellcheck source=.manage/web/copyoldfiles
source .manage/web/copyoldfiles || exit
# shellcheck source=.manage/web/permissions
source .manage/web/permissions || exit
printf "%b %b %s\\n" "${DONE}"
exit 1
;;
4)
printf "%b %b %s\\n" "Update Media Wiki"
MEDIAWIKI
read -rp "Enter versions number: e.g. 1.36.1: " VERSION
# shellcheck source=.manage/web/backup
source .manage/web/backup || exit
# shellcheck source=.manage/web/download
source .manage/web/download || exit
# shellcheck source=.manage/web/unpack
source .manage/web/unpack || exit
# shellcheck source=.manage/web/copyoldfiles
source .manage/web/copyoldfiles || exit
# shellcheck source=.manage/web/permissions
source .manage/web/permissions || exit
# shellcheck source=.manage/web/upgrade
source .manage/web/upgrade || exit
printf "%b %b %s\\n" "${DONE}"
exit 1
;;
5)
printf "%b %b %s\\n" "Update Collabora"
COLLABORA
# shellcheck source=.manage/docker/check
source .manage/docker/check || exit
# shellcheck source=.manage/docker/pull
source .manage/docker/pull || exit
if ! [[ ${uptodate} = *"up to date"* ]]; then
# shellcheck source=.manage/docker/stop
source .manage/docker/stop || exit
# shellcheck source=.manage/docker/remove
source .manage/docker/remove || exit
# shellcheck source=.manage/docker/run
source .manage/docker/run || exit
fi
printf "%b %b %s\\n" "${DONE}"
exit 1
;;
6)
printf "%b %b %s\\n" "Update Bookstack"
BOOKSTACK
# shellcheck source=.manage/git/check
source .manage/git/check || exit
# shellcheck source=.manage/composer/check
source .manage/composer/check || exit
# shellcheck source=.manage/web/backup
source .manage/web/backup git || exit
# shellcheck source=.manage/git/download
source .manage/git/download || exit
if ! [[ ${uptodate} = "" ]]; then
# shellcheck source=.manage/web/upgrade
source .manage/composer/upgrade || exit
# shellcheck source=.manage/web/cleanup
source .manage/web/cleanup || exit
fi
# shellcheck source=.manage/web/permissions
source .manage/web/permissions || exit
printf "%b %b %s\\n" "${DONE}"
exit 1
;;
7)
printf "%b %b %s\\n" "Update Friendica"
FRIENDICA
read -rp "Enter branch name: e.g. stable or 2021.06-rc: " VERSION
# shellcheck source=.manage/git/check
source .manage/git/check || exit
# shellcheck source=.manage/web/backup
source .manage/web/backup git || exit
# shellcheck source=.manage/git/download
source .manage/git/download || exit
if ! [[ ${uptodate} = "" ]]; then
# shellcheck source=.manage/web/upgrade
source .manage/composer/upgrade || exit
# shellcheck source=.manage/git/download
source .manage/git/download addon || exit
fi
# shellcheck source=.manage/web/permissions
source .manage/web/permissions || exit
printf "%b %b %s\\n" "${DONE}"
exit 1
;;
8)
printf "%b %b %s\\n" "Update FreshRSS"
FRESHRSS
# shellcheck source=.manage/git/check
source .manage/git/check || exit
# shellcheck source=.manage/web/backup
source .manage/web/backup git || exit
# shellcheck source=.manage/git/download
source .manage/git/download || exit
# shellcheck source=.manage/web/permissions
source .manage/web/permissions || exit
printf "%b %b %s\\n" "${DONE}"
exit 1
;;
9)
printf "%b %b %s\\n" "Update Writefreely"
WRITEFREELY
read -rp "Enter versions number: e.g. 1.13.1: " VERSION
# shellcheck source=.manage/web/maintenance
source .manage/web/maintenance on || exit
# shellcheck source=.manage/web/backup
source .manage/web/backup || exit
# shellcheck source=.manage/git/download
source .manage/web/download || exit
# shellcheck source=.manage/web/unpack
source .manage/web/unpack || exit
# shellcheck source=.manage/web/copyoldfiles
source .manage/web/copyoldfiles || exit
# shellcheck source=.manage/web/permissions
source .manage/web/permissions chownonly || exit
# shellcheck source=.manage/web/maintenance
source .manage/web/maintenance off || exit
# shellcheck source=.manage/web/upgrade
source .manage/web/upgrade || exit
printf "%b %b %s\\n" "${DONE}"
exit 1
;;
*)
echo "${opt} is an invaild option select a valide one please."
sleep 2
;;
esac
done
;;
esac