test scripts and examples

This commit is contained in:
Roger Pàmies Fabra 2023-07-20 09:42:40 +02:00
parent a7bef2e015
commit 6a7de97c63
6 changed files with 153 additions and 4 deletions

46
backup_nextcloud.sh Executable file
View File

@ -0,0 +1,46 @@
#!/bin/bash
# A script to perform incremental backups using rsync
set -o errexit
set -o nounset
set -o pipefail
readonly SOURCE_DIR="/home/roger/prova"
readonly BACKUP_DIR="/home/roger/backups"
readonly DATETIME="$(date '+%Y-%m-%d_%H:%M:%S')"
readonly BACKUP_PATH="${BACKUP_DIR}/${DATETIME}"
readonly LATEST_LINK="${BACKUP_DIR}/latest"
mkdir -p "${BACKUP_DIR}"
rsync -av --delete \
"${SOURCE_DIR}/" \
--link-dest "${LATEST_LINK}" \
--exclude=".cache" \
"${BACKUP_PATH}"
rm -rf "${LATEST_LINK}"
ln -s "${BACKUP_PATH}" "${LATEST_LINK}"
#rsync -AaxzvPh --delete /home/roger/prova/ --link-dest /home/roger/latest /home/roger/prova_inc1
#ln -s /home/roger/prova_inc1 /home/roger/latest
# add file into prova
rsync -rti --delete --dry-run /home/roger/prova/ /home/roger/latest/ 2>&1 | grep -v '^[^*]d' | head -
n1
#rsync -rtiv --link-dest "../latest/" "/home/roger/prova/" "/home/roger/provabkp_inc1"
sending incremental file list
created directory /home/roger/backups/provabkp_inc1
cd+++++++++ prova/
>f+++++++++ prova/file1.txt
>f+++++++++ prova/file2.txt
>f+++++++++ prova/file3.txt
>f+++++++++ prova/file4.txt

10
colors.sh Executable file
View File

@ -0,0 +1,10 @@
#! /usr/bin/env bash
RED="\e[31m"
GREEN="\e[32m"
ENDCOLOR="\e[0m"
echo -e "${RED}This is some red text, ${ENDCOLOR}"
echo -e "${GREEN}And this is some green text${ENDCOLOR}"
#https://misc.flogisoft.com/bash/tip_colors_and_formatting

17
nextcloud_updater.sh Executable file
View File

@ -0,0 +1,17 @@
sudo -u www-data php /mnt/md0/nextcloud/updater/updater.phar --no-interaction
if no sudo:
su -l www-data -s /bin/bash -c 'php /opt/nextcloud/updater/updater.phar --no-interaction'
----- no updates ----
Nextcloud Updater - version: v20.0.0beta4-11-g68fa0d4
Current version is 23.0.12.
No update available.
Nothing to do.
--------

View File

@ -73,12 +73,14 @@ elevate_cmd () {
}
remote_update () {
ssh $1 << EOF
ssh -t $1 << EOF
$(typeset -f has_sudo)
$(typeset -f elevate_cmd)
elevate_cmd apt update -qq
elevate_cmd apt upgrade -y
elevate_cmd apt autoremove
elevate_cmd apt-get update -qq
elevate_cmd echo 'debconf debconf/frontend select Noninteractive' | elevate_cmd debconf-set-selections
elevate_cmd apt-get upgrade -y
elevate_cmd apt-get autoremove
elevate_cmd echo 'debconf debconf/frontend select Dialog' | elevate_cmd debconf-set-selections
EOF
}

70
spinner.sh Executable file
View File

@ -0,0 +1,70 @@
#!/usr/bin/env bash
FRAME=("⠋" "⠙" "⠹" "⠸" "⠼" "⠴" "⠦" "⠧" "⠇" "⠏")
FRAME_INTERVAL=0.1
RED="\e[31m"
GREEN="\e[32m"
ENDCOLOR="\e[0m"
start_spinner() {
#local step=0
local CMD=$1
local STEP=$2
tput civis -- invisible
#while [ "$step" -lt "${#CMDS[@]}" ]; do
#${CMDS[$step]} & pid=$!
$CMD & pid=$!
#status=$($CMD & pid=$!)
#status=$?
#pid=$!
while ps -p $pid &>/dev/null; do
#while kill -0 $pid 2>/dev/null; do
#echo -ne "\\r[ ] ${STEPS[$step]} ..."
echo -ne "\\r[ ] $STEP ..."
for k in "${!FRAME[@]}"; do
echo -ne "\\r[ ${FRAME[k]} ] "
sleep $FRAME_INTERVAL
done
done
wait "$pid"; status=$!
#echo "${PIPESTATUS[0]} ${PIPESTATUS[1]}"
#echo -ne "\\r[ ✔ ] ${STEPS[$step]}\\n"
#re='^[0-9]+$'
#if ! [[ $status =~ $re ]]; then
# echo $status
#else
if [ $status -eq 0 ]; then
echo -ne "\\r[ ${GREEN}${ENDCOLOR} ] $STEP\\n"
else
echo -ne "\\r[ ${RED}${ENDCOLOR} ] $STEP\\n"
fi
#fi
#step=$((step + 1))
#done
tput cnorm -- normal
}
start_spinner "apt update -qq" "Search for updates"
start_spinner "apt upgrade -qq -y" "Apply updates"
start_spinner "./testsleep.sh" "Testing fail" #ha de donar FAIL!!
start_spinner "rm *.mp3" "Testing fail"
./testsleep.sh
echo $?
#/usr/bin/scp me@website.com:file somewhere 2>/dev/null &
#apt update -qq > /dev/null 2>/dev/null & pid=$! # Process Id of the previous running command
#spin='-\|/'
#i=0
#while kill -0 $pid 2>/dev/null
#do
# i=$(( (i+1) %4 ))
# printf "\r${spin:$i:1}"
# sleep .1
#done

4
testsleep.sh Executable file
View File

@ -0,0 +1,4 @@
#!/usr/bin/env bash
sleep 3
exit 1