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.

272 lines
6.3 KiB

#!/bin/bash
# Author: Tealk
# Repo: https://codeberg.org/Tealk/shell-administration-script
# shellcheck disable=SC2034
function APPUPDATE() {
local title="Update Nextcloud Apps"
printf " %b %s...\\n" "${INFO}" "${title}"
if ! sudo -u "${WEBUSER}" "${PHP}" "${FULLPATH}"/occ app:update --all; then
reason="can't update APPs because $?"
ERROR
else
printf "%b %b %s\\n" "${OVER}" "${TICK}" "${title}"
fi
}
function WARTUNGON() {
local title="Enable maintenance mode"
printf " %b %s...\\n" "${INFO}" "${title}"
if ! sudo -u "${WEBUSER}" "${PHP}" "${FULLPATH}"/occ maintenance:mode --on >/dev/null 2>&1; then
reason="can't enter maintenance mode because $?"
ERROR
else
if ! grep "'maintenance' => true," "${FULLPATH}"/config/config.php >/dev/null 2>&1; then
reason="can't enter maintenance mode"
ERROR
else
printf "%b %b %s\\n" "${OVER}" "${TICK}" "${title}"
fi
fi
}
function WARTUNGOFF() {
local title="Disable maintenance mode"
printf " %b %s...\\n" "${INFO}" "${title}"
if ! sudo -u "${WEBUSER}" "${PHP}" "${FULLPATH}"/occ maintenance:mode --off >/dev/null 2>&1; then
reason="can't disable maintenance mode because $?"
ERROR
else
if ! grep "'maintenance' => true," "${FULLPATH}"/config/config.php >/dev/null 2>&1; then
reason="can't enter maintenance mode"
ERROR
else
printf "%b %b %s\\n" "${OVER}" "${TICK}" "${title}"
fi
fi
}
function LDAPAUSLESEN() {
if [ -d "${LDAPPATH}" ]; then
rm "${LDAPPATH}/ldap.txt"
sudo -u "${WEBUSER}" "${PHP}" "${FULLPATH}"/occ ldap:show-remnants | sudo tee -a "${LDAPPATH}/ldap.txt"
grep -E -o '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}' "${LDAPPATH}"/ldap.txt >"${LDAPPATH}"/ldapuser.txt
if [[ "yes" == $(ASKYN "Copy user data to backup directory?") ]]; then
LDAPKOPIEREN
else
NCMENU
fi
else
mkdir "${LDAPPATH}"
LDAPAUSLESEN
fi
}
function LDAPKOPIEREN() {
mkdir "${LDAPPATH}"/users_"${DATE}"
grep -v '^ *#' <"${LDAPPATH}"/ldapuser.txt | while IFS= read -r line; do
uuid="Copy user ${line}"
if [ -d "${DATAPATH}"/"${line}" ]; then
printf " %b %s..." "${INFO}" "${uuid}"
cp -r "${DATAPATH}"/"${line}" "${LDAPPATH}"/users_"${DATE}"/"${line}"
printf "%b %b %s\\n" "${OVER}" "${TICK}" "${uuid}"
else
printf "%b %b %s\\n" "${OVER}" "${CROSS}" "${uuid}"
fi
cp "${LDAPPATH}"/ldap.txt "${LDAPPATH}"/users_"${DATE}"/
done
if [[ "yes" == $(ASKYN "Delete user permanently?") ]]; then
LDAPLOESCHEN
else
NCMENU
fi
}
function LDAPLOESCHEN() {
grep -v '^ *#' <"${LDAPPATH}"/ldapuser.txt | while IFS= read -r line; do
sudo -u "${WEBUSER}" "${PHP}" "${FULLPATH}"/occ user:delete "${line}"
done
find "${LDAPPATH}" -type d -name "users_*" -mtime +"${LDAPCLEANUP}" -exec rm -R "{}" \;
}
function USERLOESCHEN() {
read -rp "UserID? " UUID
sudo -u "${WEBUSER}" "${PHP}" "${FULLPATH}"/occ user:delete "${UUID}"
}
function LASTS() {
read -rp "UserID? " UUID
sudo -u "${WEBUSER}" "${PHP}" "${FULLPATH}"/occ user:lastseen "${UUID}"
}
#It might happen that we add from time to time new indices to already existing database tables, for example to improve performance.
function INDICES() {
sudo -u "${WEBUSER}" "${PHP}" "${FULLPATH}"/occ db:add-missing-indices
}
#The files:scan command scans for new files and updates the file cache.
function SCAN() {
read -rp "UserID, all or unscanned " UUID
if [[ ${UUID} = "all" ]]; then
sudo -u "${WEBUSER}" "${PHP}" "${FULLPATH}"/occ files:scan --all
elif [[ ${UUID} = "unscanned" ]]; then
sudo -u "${WEBUSER}" "${PHP}" "${FULLPATH}"/occ files:scan --unscanned --all
else
sudo -u "${WEBUSER}" "${PHP}" "${FULLPATH}"/occ files:scan "${UUID}"
fi
}
function BIGINT() {
sudo -u "${WEBUSER}" "${PHP}" "${FULLPATH}"/occ db:convert-filecache-bigint
}
function PRIMKEY() {
sudo -u "${WEBUSER}" "${PHP}" "${FULLPATH}"/occ db:add-missing-primary-keys
}
#tidies up the server’s file cache by deleting all file entries that have no matching entries in the storage table.
function CLEANUP() {
sudo -u "${WEBUSER}" "${PHP}" "${FULLPATH}"/occ files:cleanup
}
function REPORT() {
sudo -u "${WEBUSER}" "${PHP}" "${FULLPATH}"/occ user:report
}
function SEARCH() {
read -rp "Enter first name: " VNAME
sudo -u "${WEBUSER}" "${PHP}" "${FULLPATH}"/occ ldap:search "${VNAME}"
}
function CUSTOMCOMMAND() {
read -rp "Enter command: occ " COMMAND PARAMETER
sudo -u "${WEBUSER}" "${PHP}" "${FULLPATH}"/occ "${COMMAND}" "${PARAMETER}"
}
while :; do
clear
echo " N E X T C L O U D - M E N U"
echo ""
echo "1. Exit"
echo "2. Update"
echo "3. App Update"
echo "4. Maintenance ON"
echo "5. Maintenance OFF"
echo "6. Readout deleted LDAP User"
echo "7. Backup deleted LDAP User"
echo "8. Remove deleted LDAP User"
echo "9. Remove User"
echo "10. Last seen"
echo "11. Add missing indices"
echo "12. Add missing primary keys"
echo "13. BigInt identifiers"
echo "14. Scan"
echo "15. CleanUp"
echo "16. User report"
echo "17. LDAP search"
echo "18. Custom Command"
echo -n "Please enter option: "
read -r opt
clear
case ${opt} in
1)
echo "Bye ${USER}"
exit 1
;;
2)
printf "%b %b %s\\n" "Update Nextcloud"
# shellcheck source=web/download
source .manage/web/download || exit
# shellcheck source=web/maintenance
source .manage/web/maintenance on || exit
# shellcheck source=web/backup
source .manage/web/backup || exit
# shellcheck source=web/unpack
source .manage/web/unpack || exit
# shellcheck source=web/copyoldfiles
source .manage/web/copyoldfiles || exit
# shellcheck source=web/permissions
source .manage/web/permissions || exit
# shellcheck source=web/upgrade
source .manage/web/upgrade || exit
# shellcheck source=web/maintenance
source .manage/web/maintenance off || exit
# shellcheck source=web/maintenance
source .manage/web/maintenance indices || exit
printf "%b %b %s\\n" "${DONE}"
exit 1
;;
3)
APPUPDATE
exit 1
;;
4)
WARTUNGON
exit 1
;;
5)
WARTUNGOFF
exit 1
;;
6)
LDAPAUSLESEN
exit 1
;;
7)
LDAPKOPIEREN
exit 1
;;
8)
LDAPLOESCHEN
exit 1
;;
9)
USERLOESCHEN
exit 1
;;
10)
LASTS
exit 1
;;
11)
INDICES
exit 1
;;
12)
BIGINT
exit 1
;;
13)
PRIMKEY
exit 1
;;
14)
SCAN
exit 1
;;
15)
CLEANUP
exit 1
;;
16)
REPORT
exit 1
;;
17)
SEARCH
exit 1
;;
18)
CUSTOMCOMMAND
exit 1
;;
*)
echo "${opt} is an invaild option select a valide one please."
sleep 2
;;
esac
done