diff --git a/README.md b/README.md index 677c5a0..54627e0 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Bash Scripts collection +TODO: Need install packages for each script + ## Permanent enviroment variables in ~/.profile Append file `~/.profile` with this variables: @@ -49,3 +51,16 @@ Scan rootkits into system with rkhunter Scan virus and malware into system with clamav * Usage: `./scan_clam.sh` + +### updates_notifier.sh + +TODO! + +## Some tips + +* https://www.appsloveworld.com/bash/100/6/how-have-both-local-and-remote-variable-inside-an-ssh-command +* https://stackoverflow.com/questions/27932694/shell-script-ssh-server-eof (script detect expire users) +* use xargs: https://www.baeldung.com/linux/xargs-multiple-arguments +* load env vars in cron: https://www.baeldung.com/linux/load-env-variables-in-cron-job +* crontab need path sometimes: https://askubuntu.com/questions/117978/script-doesnt-run-via-crontab-but-works-fine-standalone +* errors and best practices: https://tecadmin.net/resolved-unary-operator-expected-error-in-bash/ diff --git a/backup_gitea.sh b/backup_gitea.sh new file mode 100644 index 0000000..f486139 --- /dev/null +++ b/backup_gitea.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +PATH=$PATH:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin + +GOTIFY_TOKEN="token" +GOTIFY_MESSAGE="Backup task init: **"`date +"%d/%m/%Y %H:%M:%S"`"** \r" +GITEA_DIR="/path/to/gitea" +BACKUP_FILE="gitea-backup_"`date +\%Y\%m\%d`".zip" +REMOTE_SERVER="remote.example.com" +REMOTE_PATH="/path/to/remote/store/backups/" + +# gitea +su - gitea -s /bin/bash -c "$GITEA_DIR/gitea dump -c $GITEA_DIR/custom/conf/app.ini --file $BACKUP_FILE --tempdir $GITEA_DIR/" +rsync -AaxzPh --remove-source-files "$GITEA_DIR/$BACKUP_FILE" "$REMOTE_SERVER:$REMOTE_PATH" + +GOTIFY_MESSAGE="${GOTIFY_MESSAGE} Backup task end: **"`date +"%d/%m/%Y %H:%M:%S"`"** \r" + +# send gotify notification +sh ./gotifypush.sh "Gitea $(hostname) Backup" "$GOTIFY_MESSAGE" 5 "$GOTIFY_TOKEN" diff --git a/f2b_unban_ip.sh b/f2b_unban_ip.sh new file mode 100755 index 0000000..6eeb993 --- /dev/null +++ b/f2b_unban_ip.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +#Use ./unbanipcloud.sh +echo $# + +JAIL_NAME=$ES7_F2B_JAIL_NAME +REMOTE_SERVER="estudiset.nextcloud.handycat" +UNBAN_IP=$1 + +if [ $# -eq 0 ]; then + echo "Falta la IP a desbloquejar com a argument. Per exemple: $0 X.X.X.X" + exit 1 +elif [ $# -eq 2 ]; then + JAIL_NAME=$2 +fi + +# unban with fail2ban +out=$(ssh $REMOTE_SERVER "sudo fail2ban-client set $JAIL_NAME unbanip $UNBAN_IP") + +if [ "$out" -eq "1" ]; then + echo "La IP [$UNBAN_IP] s'ha desbloquejat correctament" +else + echo "No s'ha trobat la IP [$UNBAN_IP] a la llista de bloquejos" +fi diff --git a/utils/logger.sh b/utils/logger.sh deleted file mode 100644 index f0dfa11..0000000 --- a/utils/logger.sh +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/bash - -#Use ./logger.sh - -# uncomment when use script from cron -PATH=$PATH:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin - -# variables -REMOTE_PATH="$ES7_LOGS_PATH$2" -PUBLIC_LOG_URL="$ES7_LOGS_URL/$2" - -# get file name in case of $1 is a path -file=$(basename -- "$1") -extension=${file##*.} -base=$(basename "${file%.*}") - -# create remote folder to store logs if not exist -# \$ allow read remote variable value -ssh $ES7_LOGS_SERVER_SSH "sudo mkdir -p $REMOTE_PATH && sudo chown -R \$(whoami): $REMOTE_PATH" - -# Copy local logfile to remote destination -scp $1 "$ES7_LOGS_SERVER_SSH:$REMOTE_PATH" - -# set correct permissions -ssh $ES7_LOGS_SERVER_SSH "chmod 644 $REMOTE_PATH$file" - -# Clear x days old remote logs -ssh $ES7_LOGS_SERVER_SSH 'bash -s' << EOF -find $REMOTE_PATH -maxdepth 1 -mtime +$E7S_LOGS_PRESERVE_DAYS -exec "rm" -R {} \; -EOF - -# return final log url -# change to txt if log is another text format -if [ $extension != "txt" ]; then - ssh $ES7_LOGS_SERVER_SSH "mv $REMOTE_PATH$file $REMOTE_PATH$base.txt" -fi - -echo "${PUBLIC_LOG_URL}${base}.txt"