more cleanups in bash scripts

This commit is contained in:
Steffen Vogel 2022-08-20 00:06:22 +02:00
parent c323cfb52b
commit 5b005ac95d
46 changed files with 387 additions and 418 deletions

View file

@ -17,6 +17,8 @@
# TODO: delete old snapshots in source and destination fs # TODO: delete old snapshots in source and destination fs
set -e
function usage { function usage {
echo "Usage: $(basename $0) SOURCE [DEST]" echo "Usage: $(basename $0) SOURCE [DEST]"
echo echo
@ -26,53 +28,55 @@ function usage {
exit 1 exit 1
} }
set -e
if [ $# -lt 1 ]; then if [ $# -lt 1 ]; then
echo -e "missing source" echo -e "missing source"
echo echo
usage usage
fi fi
SRC=$(readlink -f "$1") SRC=$(readlink -e "$1")
if [ $SRC == "/" ]; then
SRC=""
fi
if [ -h "$SRC/.backup/destination" ]; then if [ -h "$SRC/.backup/destination" ]; then
DEST=$(readlink -f "$SRC/.backup/destination") DEST=$(readlink -e "$SRC/.backup/destination")
elif [ $# -ne 2 ] ; then elif [ $# -ne 2 ] ; then
echo -e "missing destination" echo -e "missing destination"
echo echo
usage usage
else else
DEST=$(readlink -f $2) DEST=$(readlink -e $2)
mkdir -p "$SRC/.backup/"
mkdir -p "$DEST"
ln -sf "$DEST" "$SRC/.backup/destination"
ln -sf "$SRC" "$DEST/source"
fi fi
# create directories if not existing
mkdir -p "$SRC/.backup/"
mkdir -p "$DEST/"
# create symbolic links if not existing
ln -snf "$DEST/" "$SRC/.backup/destination"
ln -snf "$SRC/" "$DEST/source"
# name for the new snapshot # name for the new snapshot
SNAPSHOT=$(date +%F_%H-%M-%S) SNAPSHOT=$(date +%F_%H-%M-%S)
LATEST="$SRC/.backup/$SNAPSHOT" LATEST="$SRC/.backup/$SNAPSHOT"
# snapshot the current state # snapshot the current state
btrfs subvolume snapshot -r "$SRC" "$LATEST" btrfs subvolume snapshot -r "$SRC/" "$LATEST/"
# send changes # send changes
if [ -h "$DEST/latest-source" ]; then if [ -h "$DEST/latest-source" ]; then
PREVIOUS=$(readlink -f "$DEST/latest-source") PREVIOUS=$(readlink -e "$DEST/latest-source")
btrfs send -p "$PREVIOUS" "$LATEST" | btrfs receive "$DEST" btrfs send -p "$PREVIOUS/" "$LATEST/" | pv | btrfs receive "$DEST/"
else else
btrfs send "$LATEST" | btrfs receive "$DEST" btrfs send "$LATEST/" | pv | btrfs receive "$DEST/"
fi fi
# delete old snapshot in source fs # delete old snapshot in source fs
if [ -n "$PREVIOUS" ]; then if [ -n "$PREVIOUS" ]; then
btrfs subvolume delete "$PREVIOUS" btrfs subvolume delete "$PREVIOUS/"
fi fi
# update links to last backup # update links to last backup
ln -rsfT "$DEST/$SNAPSHOT" "$DEST/latest" ln -rsfT "$DEST/$SNAPSHOT" "$DEST/latest"
ln -sfT "$LATEST" "$DEST/latest-source" ln -sfT "$LATEST" "$DEST/latest-source"

View file

@ -64,7 +64,7 @@ shift $((OPTIND-1))
# parsing backup directory # parsing backup directory
if [ -n "$1" ]; then if [ -n "$1" ]; then
DIR=$(readlink -f $1) DIR=$(readlink -f $1)
else else
DIR=$(pwd) DIR=$(pwd)
fi fi

4
bash/backup-remote-restic.sh Normal file → Executable file
View file

@ -11,8 +11,8 @@
set -e set -e
if [ $# -ne 2 ]; then if [ $# -ne 2 ]; then
echo "Usage: $(basename $0) SOURCE REPO" echo "Usage: $(basename $0) SOURCE REPO"
exit 1 exit 1
fi fi
SRC=$1 SRC=$1

View file

@ -24,11 +24,11 @@
## ##
function usage { function usage {
echo "Usage: $(basename $0) SOURCE DEST" echo "Usage: $(basename $0) SOURCE DEST"
echo echo
echo " SOURCE a path to the subvolume to backup" echo " SOURCE a path to the subvolume to backup"
echo " DEST a path to the backup destination" echo " DEST a path to the backup destination"
exit 1 exit 1
} }
set -e set -e
@ -36,7 +36,7 @@ set -e
if [ $# -ne 2 ]; then if [ $# -ne 2 ]; then
echo -e "invalid args!" echo -e "invalid args!"
echo echo
usage usage
fi fi
DATE=$(date +%F_%H-%M-%S) DATE=$(date +%F_%H-%M-%S)
@ -75,4 +75,3 @@ btrfs subvolume snapshot -r $DEST/.current $DEST/$DATE
# create symlink to latest snapshot # create symlink to latest snapshot
ln -rsfT $DEST/$DATE $DEST/latest ln -rsfT $DEST/$DATE $DEST/latest

View file

@ -2,24 +2,10 @@
## ##
# System Backupscript # System Backupscript
# #
# @copyright 2012 Steffen Vogel # @copyright 2021, Steffen Vogel
# @license http://www.gnu.org/licenses/gpl.txt GNU Public License # @license http://www.gnu.org/licenses/gpl.txt GNU Public License
# @author Steffen Vogel <info@steffenvogel.de> # @author Steffen Vogel <post@steffenvogel.de>
# @link http://www.steffenvogel.de # @link https://www.steffenvogel.de
##
##
# This script is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# any later version.
#
# This script 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this script. If not, see <http://www.gnu.org/licenses/>.
## ##
#============================================================= #=============================================================
@ -34,7 +20,7 @@ BACKUPDIR="/backup"
MYSQL_BACKUPDIR="/backup/mysql" MYSQL_BACKUPDIR="/backup/mysql"
DATA_BACKUPDIR="/backup/data" DATA_BACKUPDIR="/backup/data"
# Wochentag für wöchentliche Backups (1-7; 1 steht für Montag) # Wochentag f<EFBFBD>r w<>chentliche Backups (1-7; 1 steht f<>r Montag)
DOWEEKLY=5 DOWEEKLY=5
# Kompressionsmethode (gzip oder bzip2) # Kompressionsmethode (gzip oder bzip2)
@ -68,7 +54,7 @@ LOGERR=$BACKUPDIR/ERRORS_$HOST-`date +%N`.log
# - quiet : sendet nur Error Logs per Mail # - quiet : sendet nur Error Logs per Mail
MAIL_CONTENT="stdout" MAIL_CONTENT="stdout"
# Maximale Größe des Mail Anhangs # Maximale Gr<EFBFBD><EFBFBD>e des Mail Anhangs
MAIL_MAXATTSIZE="4000" MAIL_MAXATTSIZE="4000"
# Mail Adresse # Mail Adresse
@ -81,7 +67,7 @@ MAIL_ADDR="admin@localhost"
# FTP Benutzer # FTP Benutzer
FTP_USERNAME=yourftpusername FTP_USERNAME=yourftpusername
# FTP Passwort für $FTP_USERNAME # FTP Passwort f<EFBFBD>r $FTP_USERNAME
FTP_PASSWORD=yourftppassword FTP_PASSWORD=yourftppassword
# Hostname oder IP Adresse des FTP Servers # Hostname oder IP Adresse des FTP Servers
@ -91,10 +77,10 @@ FTP_HOST=yourftpserver
# Daten Einstellungen # Daten Einstellungen
#============================================================= #=============================================================
# Liste der täglichen Backupverzeichnisse (durch " " getrennt) # Liste der t<EFBFBD>glichen Backupverzeichnisse (durch " " getrennt)
DATA_DIRNAMES="/home /opt/mails /etc" DATA_DIRNAMES="/home /opt/mails /etc"
# Liste der wöchentlichen Backupverzeichnisse (durch " " getrennt) # Liste der w<EFBFBD>chentlichen Backupverzeichnisse (durch " " getrennt)
DATA_WDIRNAMES="/var/www $DATA_DIRNAMES" DATA_WDIRNAMES="/var/www $DATA_DIRNAMES"
# Liste der monatlichen Backupverzeichnisse (durch " " getrennt) # Liste der monatlichen Backupverzeichnisse (durch " " getrennt)
@ -114,16 +100,16 @@ TARFLAGS="--create --preserve-permissions --dereference --ignore-failed-read --e
# mySQL Benutzer # mySQL Benutzer
MYSQL_USERNAME=yourmysqlusername MYSQL_USERNAME=yourmysqlusername
# mySQL Passwort für $MYSQL_USERNAME # mySQL Passwort f<EFBFBD>r $MYSQL_USERNAME
MYSQL_PASSWORD=yourmysqlpassword MYSQL_PASSWORD=yourmysqlpassword
# Hostname oder IP Adresse des mySQL Servers # Hostname oder IP Adresse des mySQL Servers
MYSQL_HOST=$HOST MYSQL_HOST=$HOST
# Liste der täglichen Backupdatenbanken (durch " " getrennt; "all" für alle Datenbanken) # Liste der t<EFBFBD>glichen Backupdatenbanken (durch " " getrennt; "all" f<>r alle Datenbanken)
MYSQL_DBNAMES="all" MYSQL_DBNAMES="all"
# Liste der wöchentlichen Backupdatenbanken (durch " " getrennt) # Liste der w<EFBFBD>chentlichen Backupdatenbanken (durch " " getrennt)
MYSQL_WDBNAMES=$MYSQL_DBNAMES MYSQL_WDBNAMES=$MYSQL_DBNAMES
# Liste der monatlichen Backupdatenbanken (durch " " getrennt) # Liste der monatlichen Backupdatenbanken (durch " " getrennt)
@ -132,13 +118,13 @@ MYSQL_MDBNAMES="$MYSQL_WDBNAMES"
# Datenbanken zum Excluden # Datenbanken zum Excluden
MYSQL_DBEXCLUDE="" MYSQL_DBEXCLUDE=""
# CREATE DATABASE zu den mySQL Dumps hinzufügen? # CREATE DATABASE zu den mySQL Dumps hinzuf<EFBFBD>gen?
MYSQL_CREATE_DATABASE=yes MYSQL_CREATE_DATABASE=yes
# Komprimierte Verbindung zum mySQL Server # Komprimierte Verbindung zum mySQL Server
MYSQL_COMMCOMP=no MYSQL_COMMCOMP=no
# Maximale Größe des Verbindungspuffer zum mySQL Server (Maximum 1GB) # Maximale Gr<EFBFBD><EFBFBD>e des Verbindungspuffer zum mySQL Server (Maximum 1GB)
MYSQL_MAX_ALLOWED_PACKET= MYSQL_MAX_ALLOWED_PACKET=
# Socketadresse des mySQL Server bei localhost Verbindungen # Socketadresse des mySQL Server bei localhost Verbindungen
@ -174,13 +160,13 @@ if [ "$MYSQL_COMMCOMP" = "yes" ];
MYSQL_OPT="$OPT --compress" MYSQL_OPT="$OPT --compress"
fi fi
# Maximale Größe des Verbindungspuffer zum mySQL Server (Maximum 1GB) # Maximale Gr<EFBFBD><EFBFBD>e des Verbindungspuffer zum mySQL Server (Maximum 1GB)
if [ "$MYSQL_MAX_ALLOWED_PACKET" ]; if [ "$MYSQL_MAX_ALLOWED_PACKET" ];
then then
MYSQL_OPT="$MYSQL_OPT --max_allowed_packet=$MYSQL_MAX_ALLOWED_PACKET" MYSQL_OPT="$MYSQL_OPT --max_allowed_packet=$MYSQL_MAX_ALLOWED_PACKET"
fi fi
# Benötigte Verzeichnisse erstellen # Ben<EFBFBD>tigte Verzeichnisse erstellen
if [ ! -e "$BACKUPDIR" ] if [ ! -e "$BACKUPDIR" ]
then then
mkdir -p "$BACKUPDIR" mkdir -p "$BACKUPDIR"
@ -236,7 +222,7 @@ display () {
end) end)
echo Backup Ende `date` echo Backup Ende `date`
echo ====================================================================== echo ======================================================================
echo Benötigter Speicherplatz für Backups: echo Ben<EFBFBD>tigter Speicherplatz f<>r Backups:
echo Data : `du -hs "$DATA_BACKUPDIR"` echo Data : `du -hs "$DATA_BACKUPDIR"`
echo mySQL: `du -hs "$MYSQL_BACKUPDIR"` echo mySQL: `du -hs "$MYSQL_BACKUPDIR"`
echo All : `du -hs "$BACKUPDIR"` echo All : `du -hs "$BACKUPDIR"`
@ -299,33 +285,33 @@ archive () {
gzip -l "$1.gz" gzip -l "$1.gz"
SUFFIX=".gz" SUFFIX=".gz"
elif [ "$COMP" = "bzip2" ]; then elif [ "$COMP" = "bzip2" ]; then
echo Komprimierungs Informationen für "$1.bz2" echo Komprimierungs Informationen f<EFBFBD>r "$1.bz2"
bzip2 -f -v $1 2>&1 bzip2 -f -v $1 2>&1
SUFFIX=".bz2" SUFFIX=".bz2"
else else
echo "Keine Kompressionsmethode gewählt!" echo "Keine Kompressionsmethode gew<EFBFBD>hlt!"
fi fi
return 0 return 0
} }
# Soll CREATE_DATABASE hinzugefügt werden? # Soll CREATE_DATABASE hinzugef<EFBFBD>gt werden?
if [ "$MYSQL_CREATE_DATABASE" = "no" ]; then if [ "$MYSQL_CREATE_DATABASE" = "no" ]; then
MYSQL_OPT="$MYSQL_OPT --no-create-db" MYSQL_OPT="$MYSQL_OPT --no-create-db"
else else
MYSQL_OPT="$MYSQL_OPT --databases" MYSQL_OPT="$MYSQL_OPT --databases"
fi fi
# Wähle alle Datenbanken aus # W<EFBFBD>hle alle Datenbanken aus
if [ "$MYSQL_DBNAMES" = "all" ]; then if [ "$MYSQL_DBNAMES" = "all" ]; then
MYSQL_DBNAMES="`mysql --user=$MYSQL_USERNAME --password=$MYSQL_PASSWORD --host=$MYSQL_HOST --batch --skip-column-names -e "show databases"| sed 's/ /%/g'`" MYSQL_DBNAMES="`mysql --user=$MYSQL_USERNAME --password=$MYSQL_PASSWORD --host=$MYSQL_HOST --batch --skip-column-names -e "show databases"| sed 's/ /%/g'`"
# Schließe Datenbanken aus # Schließe Datenbanken aus
for exclude in $MYSQL_DBEXCLUDE for exclude in $MYSQL_DBEXCLUDE
do do
MYSQL_DBNAMES=`echo $MYSQL_DBNAMES | sed "s/\b$exclude\b//g"` MYSQL_DBNAMES=`echo $MYSQL_DBNAMES | sed "s/\b$exclude\b//g"`
done done
MYSQL_MDBNAMES=$MYSQL_DBNAMES MYSQL_MDBNAMES=$MYSQL_DBNAMES
fi fi
display start # Zeige Start Informationen display start # Zeige Start Informationen
@ -340,7 +326,7 @@ fi
#================================================ #================================================
if [ $DOM = "01" ]; then if [ $DOM = "01" ]; then
# Erstellen benötigte Verzeichnisse # Erstellen ben<EFBFBD>tigte Verzeichnisse
if [ ! -e "$MYSQL_BACKUPDIR/monthly/$M" ] if [ ! -e "$MYSQL_BACKUPDIR/monthly/$M" ]
then then
mkdir -p "$MYSQL_BACKUPDIR/monthly/$M" mkdir -p "$MYSQL_BACKUPDIR/monthly/$M"
@ -374,7 +360,7 @@ display datastart
for DATA_MDIR in $DATA_MDIRNAMES for DATA_MDIR in $DATA_MDIRNAMES
do do
# Bereite $DATA_MDIR für den Dateinamen vor # Bereite $DATA_MDIR f<EFBFBD>r den Dateinamen vor
DATA_MDIR_DISP="`echo $DATA_MDIR | cut -b 2- | sed 's/\//_/g' | sed 's/ //g'" DATA_MDIR_DISP="`echo $DATA_MDIR | cut -b 2- | sed 's/\//_/g' | sed 's/ //g'"
echo Monthly Backup of $DATA_MDIR... echo Monthly Backup of $DATA_MDIR...
@ -391,11 +377,11 @@ fi
#================================================ #================================================
# Wöchentliches Backup # W<EFBFBD>chentliches Backup
#================================================ #================================================
if [ $DNOW = $DOWEEKLY ]; then if [ $DNOW = $DOWEEKLY ]; then
# Erstellen benötigte Verzeichnisse # Erstellen ben<EFBFBD>tigte Verzeichnisse
if [ ! -e "$MYSQL_BACKUPDIR/weekly/week_$W" ] if [ ! -e "$MYSQL_BACKUPDIR/weekly/week_$W" ]
then then
mkdir -p "$MYSQL_BACKUPDIR/weekly/week_$W" mkdir -p "$MYSQL_BACKUPDIR/weekly/week_$W"
@ -406,7 +392,7 @@ if [ ! -e "$DATA_BACKUPDIR/weekly/week_$W" ]
mkdir -p "$DATA_BACKUPDIR/weekly/week_$W" mkdir -p "$DATA_BACKUPDIR/weekly/week_$W"
fi fi
# Lösche alte Backups # L<EFBFBD>sche alte Backups
echo Rotating 5 weeks Backups... echo Rotating 5 weeks Backups...
display dl display dl
if [ "$W" -le 05 ];then if [ "$W" -le 05 ];then
@ -442,7 +428,7 @@ display datastart
for DATA_WDIR in $DATA_WDIRNAMES for DATA_WDIR in $DATA_WDIRNAMES
do do
# Bereite $DATA_WDIR für den Dateinamen vor # Bereite $DATA_WDIR f<EFBFBD>r den Dateinamen vor
DATA_DIR_DISP="`echo $DATA_WDIR | cut -b 2- | sed 's/\//_/g' | sed 's/ //g'" DATA_DIR_DISP="`echo $DATA_WDIR | cut -b 2- | sed 's/\//_/g' | sed 's/ //g'"
echo Weekly Backup of $DATA_WDIR... echo Weekly Backup of $DATA_WDIR...
@ -458,9 +444,9 @@ display dataend
fi fi
#================================================ #================================================
# Tägliches Backup # T<EFBFBD>gliches Backup
#================================================ #================================================
# Erstellen benötigte Verzeichnisse # Erstellen ben<EFBFBD>tigte Verzeichnisse
if [ ! -e "$MYSQL_BACKUPDIR/daily/$DOW" ] if [ ! -e "$MYSQL_BACKUPDIR/daily/$DOW" ]
then then
mkdir -p "$MYSQL_BACKUPDIR/daily/$DOW" mkdir -p "$MYSQL_BACKUPDIR/daily/$DOW"
@ -471,7 +457,7 @@ if [ ! -e "$DATA_BACKUPDIR/daily/$DOW" ]
mkdir -p "$DATA_BACKUPDIR/daily/$DOW" mkdir -p "$DATA_BACKUPDIR/daily/$DOW"
fi fi
# Lösche alte Backups # L<EFBFBD>sche alte Backups
echo Rotating last weeks Backup... echo Rotating last weeks Backup...
display l display l
eval rm -fv "$MYSQL_BACKUPDIR/daily/$DOW/*" eval rm -fv "$MYSQL_BACKUPDIR/daily/$DOW/*"
@ -497,7 +483,7 @@ display datastart
for DATA_DIR in $DATA_DIRNAMES for DATA_DIR in $DATA_DIRNAMES
do do
# Bereite $DATA_DIR für den Dateinamen vor # Bereite $DATA_DIR f<EFBFBD>r den Dateinamen vor
DATA_DIR_DISP="`echo $DATA_DIR | cut -b 2- | sed 's/\//_/g' | sed 's/ //g'" DATA_DIR_DISP="`echo $DATA_DIR | cut -b 2- | sed 's/\//_/g' | sed 's/ //g'"
echo Daily Backup of $DATA_DIR... echo Daily Backup of $DATA_DIR...
@ -519,39 +505,39 @@ if [ "$POSTBACKUP" ]; then
fi fi
#Clean up IO redirection #Clean up IO redirection
exec 1>&6 6>&- # Stelle Standartausgabe wieder her und schließe Datei #6 exec 1>&6 6>&- # Stelle Standartausgabe wieder her und schlie<EFBFBD>e Datei #6
exec 1>&7 7>&- # Stelle Standartausgabe wieder her und schließe Datei #7 exec 1>&7 7>&- # Stelle Standartausgabe wieder her und schlie<EFBFBD>e Datei #7
if [ "$MAIL_CONTENT" = "files" ] if [ "$MAIL_CONTENT" = "files" ]
then then
if [ -s "$LOGERR" ] if [ -s "$LOGERR" ]
then then
# Füge bei Fehlern Error Log hinzu # F<EFBFBD>ge bei Fehlern Error Log hinzu
MYSQL_BACKUPFILES="$MYSQL_BACKUPFILES $LOGERR" MYSQL_BACKUPFILES="$MYSQL_BACKUPFILES $LOGERR"
ERRORNOTE="ACHTUNG Backup Fehler: " ERRORNOTE="ACHTUNG Backup Fehler: "
fi fi
# Ermittel SQL Dump Größe # Ermittel SQL Dump Gr<EFBFBD><EFBFBD>e
MAIL_ATTSIZE=`du -c $MYSQL_BACKUPFILES | grep "[[:digit:][:space:]]total$" |sed s/\s*total//` MAIL_ATTSIZE=`du -c $MYSQL_BACKUPFILES | grep "[[:digit:][:space:]]total$" |sed s/\s*total//`
if [ $MAIL_MAXATTSIZE -ge $MAIL_ATTSIZE ] if [ $MAIL_MAXATTSIZE -ge $MAIL_ATTSIZE ]
then then
BACKUPFILES=`echo "$BACKUPFILES" | sed -e "s# # -a #g"` # enable multiple attachments BACKUPFILES=`echo "$BACKUPFILES" | sed -e "s# # -a #g"` # enable multiple attachments
mutt -s "$ERRORNOTE Backup Log and SQL Dump für $HOST - $DATE" $BACKUPFILES $MAIL_ADDR < $LOGFILE #senden via mutt mutt -s "$ERRORNOTE Backup Log and SQL Dump f<EFBFBD>r $HOST - $DATE" $BACKUPFILES $MAIL_ADDR < $LOGFILE #senden via mutt
else else
cat "$LOGFILE" | mail -s "ACHTUNG! - SQL Dump ist zu groß um gemailt zu werden auf $HOST - $DATE" $MAIL_ADDR cat "$LOGFILE" | mail -s "ACHTUNG! - SQL Dump ist zu gro<EFBFBD> um gemailt zu werden auf $HOST - $DATE" $MAIL_ADDR
fi fi
elif [ "$MAIL_CONTENT" = "log" ] elif [ "$MAIL_CONTENT" = "log" ]
then then
cat "$LOGFILE" | mail -s "Backup Log für $HOST - $DATE" $MAIL_ADDR cat "$LOGFILE" | mail -s "Backup Log f<EFBFBD>r $HOST - $DATE" $MAIL_ADDR
if [ -s "$LOGERR" ] if [ -s "$LOGERR" ]
then then
cat "$LOGERR" | mail -s "$ERRORNOTE Error Log für: $HOST - $DATE" $MAIL_ADDR cat "$LOGERR" | mail -s "$ERRORNOTE Error Log f<EFBFBD>r: $HOST - $DATE" $MAIL_ADDR
fi fi
elif [ "$MAIL_CONTENT" = "quiet" ] elif [ "$MAIL_CONTENT" = "quiet" ]
then then
if [ -s "$LOGERR" ] if [ -s "$LOGERR" ]
then then
cat "$LOGERR" | mail -s "$ERRORNOTE Error Log für $HOST - $DATE" $MAIL_ADDR cat "$LOGERR" | mail -s "$ERRORNOTE Error Log f<EFBFBD>r $HOST - $DATE" $MAIL_ADDR
cat "$LOGFILE" | mail -s "Log für $HOST - $DATE" $MAIL_ADDR cat "$LOGFILE" | mail -s "Log f<EFBFBD>r $HOST - $DATE" $MAIL_ADDR
fi fi
else else
if [ -s "$LOGERR" ] if [ -s "$LOGERR" ]
@ -574,7 +560,7 @@ if [ -s "$LOGERR" ]
STATUS=0 STATUS=0
fi fi
# Löschen der Logfiles # L<EFBFBD>schen der Logfiles
eval rm -f "$LOGFILE" eval rm -f "$LOGFILE"
eval rm -f "$LOGERR" eval rm -f "$LOGERR"

94
bash/cartodb/import_tcx.sh Executable file
View file

@ -0,0 +1,94 @@
#!/bin/bash
##
# Import your sport activities from tapiriik.com to cartoco.com.
#
# Prerequisistes:
# - rclone
# - curl
# - jq
# - xsqlproc
#
# @copyright 2021, Steffen Vogel
# @license http://www.gnu.org/licenses/gpl.txt GNU Public License
# @author Steffen Vogel <post@steffenvogel.de>
# @link https://www.steffenvogel.de
##
CARTODB_API_KEY=$(pass apis/cartodb)
CARTODB_USER=stv0g
CARTODB_EP="https://${CARTODB_USER}.carto.com/api/v2/sql?api_key=${CARTODB_API_KEY}"
TCXDIR=~/Tracks
STYLESHEET=$(mktemp)
JQFILTER=$(mktemp)
cat << EOF > ${JQFILTER}
if has("error") then
"Error: " + .error[0]
else
"Success: Rows added: " + (.total_rows|tostring)
end
EOF
cat << EOF > ${STYLESHEET}
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:tcx="http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2">
<xsl:output method="text" />
<xsl:template match="/tcx:TrainingCenterDatabase/tcx:Activities/tcx:Activity">
<xsl:if test="count(//tcx:LongitudeDegrees) > 0">
<xsl:text>q=INSERT INTO laps (number, starttime, averageheartratebpm, maximumheartratebpm, calories, distancemeters, intensity, totaltimeseconds, the_geom) VALUES</xsl:text>
<xsl:for-each select="tcx:Lap">
<xsl:if test="//tcx:LongitudeDegrees">
(
<xsl:value-of select="position()" />,
TIMESTAMP '<xsl:value-of select="@StartTime" />',
<xsl:value-of select="tcx:AverageHeartRateBpm/tcx:Value" />,
<xsl:value-of select="tcx:MaximumHeartRateBpm/tcx:Value" />,
<xsl:value-of select="tcx:Calories" />,
<xsl:value-of select="tcx:DistanceMeters" />,
'<xsl:value-of select="tcx:Intensity" />',
<xsl:value-of select="tcx:TotalTimeSeconds" />,
ST_SetSRID(ST_GeomFromText('MULTILINESTRING((<xsl:for-each select="tcx:Track/tcx:Trackpoint">
<xsl:if test="tcx:Position/tcx:LongitudeDegrees">
<xsl:value-of select="tcx:Position/tcx:LongitudeDegrees" /><xsl:text> </xsl:text>
<xsl:value-of select="tcx:Position/tcx:LatitudeDegrees" />
<xsl:if test="position() != last()">,</xsl:if>
</xsl:if>
</xsl:for-each>))'), 4326)
)<xsl:if test="position() != last()">,</xsl:if>
</xsl:if>
</xsl:for-each>;
</xsl:if>
</xsl:template>
<xsl:template match="text()"/>
</xsl:stylesheet>
EOF
FILES_BEFORE=$(ls -1 -d ${TCXDIR}/*.tcx)
echo "##### Starting download from Dropbox #####"
rclone sync drpbx:/Apps/tapiriik/ ${TCXDIR}
FILES_AFTER=$(ls -1 -d ${TCXDIR}/*.tcx)
FILES_NEW=$(comm -23 <(echo "${FILES_AFTER}") <(echo "${FILES_BEFORE}"))
echo
echo "##### Starting import to CartoCB / PostGIS #####"
echo "${FILES_NEW}" | while read FILE; do
TEMPFILE=$(mktemp)
xsltproc -o "${TEMPFILE}" "${STYLESHEET}" "${FILE}"
printf "%s %-64s" "$(date +'%Y/%m/%d %H:%M:%S')" "$(basename "${FILE}"):"
if [ -s ${TEMPFILE} ]; then
curl -sSX POST --data @${TEMPFILE} ${CARTODB_EP} | jq -rf ${JQFILTER}
else
echo "Note: There are no trackpoints. Skipped"
fi
done
rm ${STYLESHEET} ${JQFILTER}

47
bash/cartodb/tcx2gpx.sh Executable file
View file

@ -0,0 +1,47 @@
#!/bin/bash
##
# Convert TCX files to GPX
#
# @copyright 2021, Steffen Vogel
# @license http://www.gnu.org/licenses/gpl.txt GNU Public License
# @author Steffen Vogel <post@steffenvogel.de>
# @link https://www.steffenvogel.de
##
SRC=${1:-${DROPBOX}/Apps/tapiriik}
DEST=${2:-${DROPBOX}/Apps/cartodb}
SPORTS=""
# Convert all TXC into GPX files
for FILE in ${SRC}/*.tcx; do
BASE=$(basename "${FILE// /_}" .tcx)
INPUT="${FILE}"
OUTPUT="${BASE}.gpx"
SPORT="${BASE##*_}"
SPORT="${SPORT%% *}"
SPORTS="$SPORTS $SPORT"
echo "Converting $INPUT to $OUTPUT of Sport $SPORT"
mkdir -p "${DEST}/${SPORT}"
${BABEL} -t -r -w -i gtrnctr -f "${INPUT}" -x track,speed -o gpx -F "${DEST}/${SPORT}/${OUTPUT}"
done
SPORTS=$(echo $SPORTS | tr ' ' '\n' | sort -u | tr '\n' ' ')
# Merge all activities per sport
for SPORT in ${SPORTS}; do
FILES=""
for FILE in ${DEST}/${SPORT}/*.gpx; do
FILES="$FILES -f $FILE"
done
echo "Merging into $SPORT.gpx"
${BABEL} -t -r -w -i gpx ${FILES} -o gpx -F ${DEST}/${SPORT}.gpx
done

0
bash/cronic.sh Normal file → Executable file
View file

17
bash/crop.sh Executable file
View file

@ -0,0 +1,17 @@
#!/bin/bash
DPI=600
for INPUT in $@; do
OUTPUT=${INPUT%.*}_crop.pdf
WIDTH_PTS=$(identify -density ${DPI} -format "%w" ${INPUT})
HEIGHT_PTS=$(identify -density ${DPI} -format "%h" ${INPUT})
BON_WIDTH_INCH=$(bc <<< "scale=2; 8/2.54") # inch
BON_WIDTH_PTS=$(bc <<< "${BON_WIDTH_INCH} * ${DPI}")
OFFSET_X_PTS=$(bc <<< "${WIDTH_PTS} / 2 - ${BON_WIDTH_PTS} / 2")
convert -density ${DPI} -crop "${BON_WIDTH_PTS}x${HEIGHT_PTS}+${OFFSET_X_PTS}+0" +repage -compress JPEG ${INPUT} ${OUTPUT}
done

View file

@ -2,25 +2,11 @@
## ##
# Deviant Background Changer # Deviant Background Changer
# #
# @copyright 2012 Steffen Vogel # @copyright 2021, Steffen Vogel
# @license http://www.gnu.org/licenses/gpl.txt GNU Public License # @license http://www.gnu.org/licenses/gpl.txt GNU Public License
# @author Steffen Vogel <info@steffenvogel.de> # @author Steffen Vogel <post@steffenvogel.de>
# @link http://www.steffenvogel.de/2009/11/28/deviantart-wallpapers/ # @link https://www.steffenvogel.de/2009/11/28/deviantart-wallpapers/
# @version 1.1 # @version 1.1
##
##
# This script is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# any later version.
#
# This script 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this script. If not, see <http://www.gnu.org/licenses/>.
## ##
# Path to save downloaded images # Path to save downloaded images

0
bash/dump.sh Normal file → Executable file
View file

0
bash/dyndns-update.sh Normal file → Executable file
View file

52
bash/fan-ctl.sh Normal file → Executable file
View file

@ -8,8 +8,8 @@
IPMIHOST=169.254.0.1 IPMIHOST=169.254.0.1
IPMIUSER=root IPMIUSER=root
IPMIPW=3LpnMcnY99cybeGM IPMIPW=XXXXX # Please change
IPMIEK=6055530028595864123105836429105276020000 IPMIEK=XXXXX # Please change
FANSPEEDHEX=${1:-0x08} # See https://i.imgur.com/u1HMyqI.png FANSPEEDHEX=${1:-0x08} # See https://i.imgur.com/u1HMyqI.png
MAXTEMP=60 MAXTEMP=60
@ -18,15 +18,15 @@ HYSTERESIS=5
FANFILE=/var/run/autofan FANFILE=/var/run/autofan
function ipmi() { function ipmi() {
ipmitool -I lanplus -H "$IPMIHOST" -U "$IPMIUSER" -P "$IPMIPW" -y "$IPMIEK" $@ ipmitool -I lanplus -H "$IPMIHOST" -U "$IPMIUSER" -P "$IPMIPW" -y "$IPMIEK" $@
} }
# For R710, which doesn't have cpu temps, try this line instead: # For R710, which doesn't have cpu temps, try this line instead:
# if ! TEMPS=$(ipmi sdr type temperature | grep -i inlet | grep -Po '\d{2,3}' 2> /dev/null); # if ! TEMPS=$(ipmi sdr type temperature | grep -i inlet | grep -Po '\d{2,3}' 2> /dev/null);
# thanks @bumbaclot # thanks @bumbaclot
if ! TEMPS=$(ipmi sdr type temperature | grep -vi inlet | grep -vi exhaust | grep -Po '\d{2,3}' 2> /dev/null); then if ! TEMPS=$(ipmi sdr type temperature | grep -vi inlet | grep -vi exhaust | grep -Po '\d{2,3}' 2> /dev/null); then
echo "FAILED TO READ TEMPERATURE SENSOR!" >&2 echo "FAILED TO READ TEMPERATURE SENSOR!" >&2
logger -t "fanctl" -p user.err -i "Error: Could not read temperature sensor" logger -t "fanctl" -p user.err -i "Error: Could not read temperature sensor"
fi fi
HIGHTEMP=0 HIGHTEMP=0
@ -35,36 +35,36 @@ LOWTEMP=1
echo "Temps: ${TEMPS}" echo "Temps: ${TEMPS}"
for TEMP in $TEMPS; do for TEMP in $TEMPS; do
if [[ $TEMP > $MAXTEMP ]]; then if [[ $TEMP > $MAXTEMP ]]; then
HIGHTEMP=1 HIGHTEMP=1
fi fi
if [[ $TEMP > $(($MAXTEMP - $HYSTERESIS)) ]]; then if [[ $TEMP > $(($MAXTEMP - $HYSTERESIS)) ]]; then
LOWTEMP=0 LOWTEMP=0
fi fi
done done
if [[ -r "$FANFILE" ]]; then if [[ -r "$FANFILE" ]]; then
AUTO=$(< "$FANFILE") AUTO=$(< "$FANFILE")
else else
AUTO=1 AUTO=1
fi fi
echo "Low: ${LOWTEMP}" echo "Low: ${LOWTEMP}"
echo "High: ${HIGHTEMP}" echo "High: ${HIGHTEMP}"
if [[ $HIGHTEMP == 1 ]]; then if [[ $HIGHTEMP == 1 ]]; then
# Automatic fan control # Automatic fan control
ipmi raw 0x30 0x30 0x01 0x01 >& /dev/null || echo "FAILED TO SET FAN CONTROL MODE" >&2; exit 1 ipmi raw 0x30 0x30 0x01 0x01 >& /dev/null || echo "FAILED TO SET FAN CONTROL MODE" >&2; exit 1
echo "1" > "$FANFILE" echo "1" > "$FANFILE"
if [[ $AUTO == 0 ]]; then if [[ $AUTO == 0 ]]; then
logger -t "fanctl" -p user.info -i "Setting fan control to automatic" logger -t "fanctl" -p user.info -i "Setting fan control to automatic"
fi fi
elif [[ $LOWTEMP == 1 ]]; then elif [[ $LOWTEMP == 1 ]]; then
# Manual fan control # Manual fan control
ipmi raw 0x30 0x30 0x01 0x00 >& /dev/null || echo "FAILED TO SET FAN CONTROL SPEED" >&2 ipmi raw 0x30 0x30 0x01 0x00 >& /dev/null || echo "FAILED TO SET FAN CONTROL SPEED" >&2
ipmi raw 0x30 0x30 0x02 0xff "$FANSPEEDHEX" >& /dev/null || echo "FAILED TO SET FAN SPEED" >&2 ipmi raw 0x30 0x30 0x02 0xff "$FANSPEEDHEX" >& /dev/null || echo "FAILED TO SET FAN SPEED" >&2
echo "0" > "$FANFILE" echo "0" > "$FANFILE"
if [[ $AUTO == 1 ]]; then if [[ $AUTO == 1 ]]; then
logger -t "fanctl" -p user.info -i "Setting fan control to manual" logger -t "fanctl" -p user.info -i "Setting fan control to manual"
fi fi
fi fi

View file

@ -1,2 +0,0 @@
#!/bin/bash
ffmpeg -i "$1" -f mp4 -vcodec mpeg4 -maxrate 1000 -b 700 -qmin 3 -qmax 5 -bufsize 4096 -g 300 -acodec aac -ar 44100 -ab 192 -s 320x240 -aspect 4:3 "$1.mp4"

View file

@ -1,2 +0,0 @@
#!/bin/bash
gpsbabel -i geo -f $1 -o garmin -F /dev/ttyS0

27
bash/get-panoramas.sh Executable file
View file

@ -0,0 +1,27 @@
#!/bin/bash
##
# Find images taken with little time diff (panoramas)
#
# @copyright 2021, Steffen Vogel
# @license http://www.gnu.org/licenses/gpl.txt GNU Public License
# @author Steffen Vogel <post@steffenvogel.de>
# @link https://www.steffenvogel.de
##
MIN_DIFF=5
LAST_TS=0
mkdir panorama
for i in *.JPG; do
TS=`stat -c %Y $i`
let DIFF=$TS-$LAST_TS
if [ "$DIFF" -lt "$MIN_DIFF" ]; then
echo $i
cp $i panorama/$i
fi
LAST_TS=$TS
done

View file

@ -1,41 +0,0 @@
#!/bin/bash
##
# Find images taken with little time diff (panoramas)
#
# @copyright 2012 Steffen Vogel
# @license http://www.gnu.org/licenses/gpl.txt GNU Public License
# @author Steffen Vogel <info@steffenvogel.de>
# @link http://www.steffenvogel.de/
##
##
# This script is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# any later version.
#
# This script 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this script. If not, see <http://www.gnu.org/licenses/>.
##
MIN_DIFF=5
LAST_TS=0
mkdir panorama
for i in *.JPG; do
TS=`stat -c %Y $i`
let DIFF=$TS-$LAST_TS
if [ "$DIFF" -lt "$MIN_DIFF" ]; then
echo $i
cp $i panorama/$i
fi
LAST_TS=$TS
done

View file

@ -2,10 +2,9 @@
# Must be called with two command-line args. # Must be called with two command-line args.
# Example: git-svn-relocate.sh http://old.server https://new.server # Example: git-svn-relocate.sh http://old.server https://new.server
if [ $# -ne 2 ] if [ $# -ne 2 ]; then
then echo "Please invoke this script with two command-line arguments (old and new SVN URLs)."
echo "Please invoke this script with two command-line arguments (old and new SVN URLs)." exit $E_NO_ARGS
exit $E_NO_ARGS
fi fi
# Prepare URLs for regex search and replace. # Prepare URLs for regex search and replace.

View file

@ -7,50 +7,46 @@
# Use at your own risk. For the love of cthulhu, back # Use at your own risk. For the love of cthulhu, back
# your repo up before letting this loose on it. # your repo up before letting this loose on it.
if [ $# -ne 1 ] if [ $# -ne 1 ]; then
then echo "Usage: `basename $0` {new subversion url}"
echo "Usage: `basename $0` {new subversion url}" exit -1
exit -1
fi fi
if [[ $1 = "--help" || $1 = "-h" ]] if [[ $1 = "--help" || $1 = "-h" ]]; then
then echo
echo echo "Usage: `basename $0` {new subversion url}"
echo "Usage: `basename $0` {new subversion url}" echo
echo echo " Changes the url of the subversion repository a git-svn repo is connected to."
echo " Changes the url of the subversion repository a git-svn repo is connected to." echo " Analogous to svn switch. Potentially a weapon of mass destruction. Use with care."
echo " Analogous to svn switch. Potentially a weapon of mass destruction. Use with care." echo " Run this from within your git repo. You only need one argument: the new url of the svn repo."
echo " Run this from within your git repo. You only need one argument: the new url of the svn repo." echo " git-svn-switch will attempt to verify that the url is at least a svn repo before starting the switch"
echo " git-svn-switch will attempt to verify that the url is at least a svn repo before starting the switch" echo " but don't depend on it to stop you from doing summat daft."
echo " but don't depend on it to stop you from doing summat daft." echo
echo exit 1
exit 1
fi fi
# get the current subversion url # get the current subversion url
SRC=`git svn info --url` SRC=`git svn info --url`
if [ -n "$SRC" ] if [ -n "$SRC" ]; then
then FROM=`echo $SRC | sed "s|/trunk||"`
FROM=`echo $SRC | sed "s|/trunk||"` REPO=`svn info $1`
REPO=`svn info $1` echo "Checking $REPO is actually a subversion repository..."
echo "Checking $REPO is actually a subversion repository..." if [ -n "$REPO" ]; then
if [ -n "$REPO" ] echo "The new URL looks valid."
then echo "Rewriting the git history with the new url..."
echo "The new URL looks valid." SED_FILTER="sed 's;git-svn-id: "$FROM";git-svn-id: "$1";g'"
echo "Rewriting the git history with the new url..." git gc
SED_FILTER="sed 's;git-svn-id: "$FROM";git-svn-id: "$1";g'" git filter-branch --msg-filter "$SED_FILTER" $(cat .git/packed-refs | awk '// {print $2}' | grep -v 'pack-refs')
git gc
git filter-branch --msg-filter "$SED_FILTER" $(cat .git/packed-refs | awk '// {print $2}' | grep -v 'pack-refs')
#Couple of pointless checkouts - on some repos the log changes seem to need flushing by an operation like this #Couple of pointless checkouts - on some repos the log changes seem to need flushing by an operation like this
git checkout trunk git checkout trunk
git checkout master git checkout master
echo "Rebuild git-svn internals and updating the repo" echo "Rebuild git-svn internals and updating the repo"
rm -rf .git/svn rm -rf .git/svn
sed -i~ 's|'$FROM'|'$1'|g' .git/config sed -i~ 's|'$FROM'|'$1'|g' .git/config
git svn rebase git svn rebase
else else
echo "Error: $1 Does not appear to be a subversion repository." echo "Error: $1 Does not appear to be a subversion repository."
fi fi
else else
echo "Error: This doesn't appear to be a git working directory, or it's a git repo that hasn't been created using a git-svn bridge" echo "Error: This doesn't appear to be a git working directory, or it's a git repo that hasn't been created using a git-svn bridge"
fi fi

View file

@ -1,2 +0,0 @@
#!/bin/bash
gpsbabel -t -i garmin -f /dev/ttyS0 -o gpx -F /home/steffen/Desktop/track.gpx

View file

@ -1,2 +0,0 @@
#!/bin/bash
gpsbabel -w -t -r -i garmin -f /dev/ttyS0 -o kml -F /home/steffen/.googleearth/gps2pc.kml

View file

@ -1,22 +0,0 @@
#!/bin/bash
FILTER=$(mktemp)
cat > ${FILTER} <<EOF
.server |
map(
select(
.hdd_size >= 3000 and
.ram >= 32 and
.bandwith >= 1000 and
.traffic == "unlimited" and
.cpu_benchmark >= 9000 and
(.setup_price | tonumber) == 0 and
(.price | tonumber) <= 50 and
(.specials | map(ascii_downcase ) | index("ssd"))
)
) |
sort_by(.price | tonumber) | reverse
EOF
curl https://www.hetzner.de/a_hz_serverboerse/live_data.json | jq -f $FILTER

14
bash/ip-rule-restore.sh Normal file → Executable file
View file

@ -16,13 +16,13 @@ for V in -4 -6; do
$IPR flush $IPR flush
ip $V route flush table default ip $V route flush table default
if [ $V == -4 ]; then if [ $V == -4 ]; then
ip $V route add 141.98.136.128/29 dev ${GW_IF} table default ip $V route add 141.98.136.128/29 dev ${GW_IF} table default
ip $V route add default via 141.98.136.129 table default ip $V route add default via 141.98.136.129 table default
else else
ip $V route add 2a09:11c0:f0:bbf0::/64 dev ${GW_IF} table default ip $V route add 2a09:11c0:f0:bbf0::/64 dev ${GW_IF} table default
ip $V route add default via 2a09:11c0:f0:bbf0::1 dev ${GW_IF} src 2a09:11c0:f0:bbf0::3 table default ip $V route add default via 2a09:11c0:f0:bbf0::1 dev ${GW_IF} src 2a09:11c0:f0:bbf0::3 table default
fi fi
$IPR add pref 200 not fwmark 0x1000 lookup main $IPR add pref 200 not fwmark 0x1000 lookup main
$IPR add pref 240 not fwmark 0x1001 lookup dn42 $IPR add pref 240 not fwmark 0x1001 lookup dn42

View file

@ -1,2 +0,0 @@
#!/bin/sh
ffmpeg -i "$1" -f mp4 -vcodec mpeg4 -maxrate 1000 -b 700 -qmin 3 -qmax 5 -bufsize 4096 -g 300 -acodec aac -ar 44100 -ab 192 -s 320x240 -aspect 4:3 $2

0
bash/luks-open.sh Normal file → Executable file
View file

View file

@ -1,5 +0,0 @@
#!/bin/bash
for i in *.m4a; do
echo "Converting: ${i%.m4a}.mp3"
faad -o - "$i" | lame - "${i%.m4a}.mp3"
done

View file

@ -2,24 +2,10 @@
## ##
# Mount MS Sharepoint folders of the RWTH L²P System in gvfs # Mount MS Sharepoint folders of the RWTH L²P System in gvfs
# #
# @copyright 2012 Steffen Vogel # @copyright 2021, Steffen Vogel
# @license http://www.gnu.org/licenses/gpl.txt GNU Public License # @license http://www.gnu.org/licenses/gpl.txt GNU Public License
# @author Steffen Vogel <info@steffenvogel.de> # @author Steffen Vogel <post@steffenvogel.de>
# @link http://www.steffenvogel.de/ # @link https://www.steffenvogel.de
##
##
# This script is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# any later version.
#
# This script 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this script. If not, see <http://www.gnu.org/licenses/>.
## ##
function usage { function usage {

View file

@ -26,10 +26,10 @@
# followed by: # followed by:
# mount /home # mount /home
# #
# @copyright 2013 Steffen Vogel # @copyright 2021, Steffen Vogel
# @license http://www.gnu.org/licenses/gpl.txt GNU Public License # @license http://www.gnu.org/licenses/gpl.txt GNU Public License
# @author Steffen Vogel <post@steffenvogel.de> # @author Steffen Vogel <post@steffenvogel.de>
# @link http://www.steffenvogel.de # @link https://www.steffenvogel.de
## ##
if [ "$(basename $0)" == "mount.luks" ]; then if [ "$(basename $0)" == "mount.luks" ]; then
@ -39,9 +39,9 @@ if [ "$(basename $0)" == "mount.luks" ]; then
shift 2 shift 2
OPTS=$@ OPTS=$@
UUID=$(cryptsetup luksUUID $DEV) UUID=$(cryptsetup luksUUID $DEV)
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo -e "$DEV is not a LUKS device" echo -e "$DEV is not a LUKS device"
exit 1 exit 1
fi fi
@ -61,9 +61,9 @@ elif [ "$(basename $0)" == "umount.luks" ]; then
shift shift
OPTS=$@ OPTS=$@
umount -i $OPTS $DEV umount -i $OPTS $DEV
# NOTE: The umount option '-i' is essentially required. It skips this # NOTE: The umount option '-i' is essentially required. It skips this
# helper script which would cause otherwise an endless self recursion # helper script which would cause otherwise an endless self recursion
cryptsetup luksClose $UUID cryptsetup luksClose $UUID
fi fi

View file

@ -1,6 +0,0 @@
#!/bin/sh
xinput set-int-prop "Logitech USB Trackball" "Wheel Emulation" 8 1
xinput set-int-prop "Logitech USB Trackball" "Wheel Emulation Button" 8 8
xinput set-int-prop "Logitech USB Trackball" "Wheel Emulation Timeout" 16 200
xinput set-int-prop "Logitech USB Trackball" "Wheel Emulation X Axis" 8 6 7
xinput set-int-prop "Logitech USB Trackball" "Wheel Emulation Y Axis" 8 4 5

View file

@ -1,5 +0,0 @@
#!/bin/bash
sudo /etc/init.d/apache2 restart
sudo /etc/init.d/mysql restart
firefox -new-tab http://localhost/workspace/ &
cd ~/workspace/

View file

@ -18,8 +18,8 @@ host=wg.0l.de
server=127.0.0.1 server=127.0.0.1
case $reason in case $reason in
BOUND|RENEW|REBIND|TIMEOUT) BOUND|RENEW|REBIND|TIMEOUT)
$NS update -d $new_ip_address -k $key -z $zone -n $server -i $interface $host ;; $NS update -d $new_ip_address -k $key -z $zone -n $server -i $interface $host ;;
RELEASE) RELEASE)
$NS delete -d $old_ip_address -k $key -z $zone -n $server $host ;; $NS delete -d $old_ip_address -k $key -z $zone -n $server $host ;;
esac esac

View file

@ -2,7 +2,12 @@
## ##
# Bind9 nsupdate wrapper # Bind9 nsupdate wrapper
# #
# @copyright 2013, Andrew Leonard
# @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
# @author Andrew Leonard <sysadmin@andyleonard.com>
# @author Steffen Vogel <post@steffenvogel.de>
# @link https://www.steffenvogel.de # @link https://www.steffenvogel.de
##
function usage { function usage {
@ -65,7 +70,7 @@ shift $((OPTIND-1))
# parsing host # parsing host
if [ -n "$1" ]; then if [ -n "$1" ]; then
HOST=$1 HOST=$1
else else
echo -e "missing host" echo -e "missing host"
echo echo

View file

@ -1,19 +0,0 @@
#!/bin/bash
if [ `gconftool --get /apps/panel/toplevels/bottom_panel_screen0/monitor` == 1 ]; then
gconftool --type int --set /apps/panel/toplevels/bottom_panel_screen0/monitor 0
else
gconftool --type int --set /apps/panel/toplevels/bottom_panel_screen0/monitor 1
fi
if [ `gconftool --get /apps/panel/toplevels/top_panel_screen0/monitor` == 1 ]; then
gconftool --type int --set /apps/panel/toplevels/top_panel_screen0/monitor 0
else
gconftool --type int --set /apps/panel/toplevels/top_panel_screen0/monitor 1
fi
if [ `gconftool --get /apps/panel/toplevels/panel_0/monitor` == 1 ]; then
gconftool --type int --set /apps/panel/toplevels/panel_0/monitor 0
else
gconftool --type int --set /apps/panel/toplevels/panel_0/monitor 1
fi

View file

@ -1,2 +0,0 @@
#!/bin/bash
gpsbabel -w -t -r -i kml -f /home/steffen/.googleearth/pc2gps.kml -o garmin -F /dev/ttyS0

View file

@ -1,5 +0,0 @@
#/bin/bash
gksudo modprobe uinput
wminput -c /etc/cwiid/wminput/presentation &
openoffice.org -show /home/steffen/Schule/Informatik/Künstliche\ Intelligenz/Künstliche\ Intelligenz.odp

View file

@ -1,47 +0,0 @@
#!/bin/bash
##
# Perform resursive AXFR queries to fetch all hostnames of a zone
#
# @copyright 2021, Steffen Vogel
# @license http://www.gnu.org/licenses/gpl.txt GNU Public License
# @author Steffen Vogel <post@steffenvogel.de>
# @link https://www.steffenvogel.de
##
print_hosts() {
ZONE=$1; shift 1
OPTS="$@"
SUBZONES=""
HOSTS=""
IFS=$'\n'
RECORDS=$(dig +nocmd $ZONE axfr +noall +answer ${OPTS})
for RECORD in ${RECORDS}; do
NAME=$(echo ${RECORD} | tr -s '\t ' '\t' | cut -f1)
TYPE=$(echo ${RECORD} | tr -s '\t ' '\t' | cut -f4)
if [ -z "${NAME}" -o "${NAME}" == *'*'* ]; then
continue
fi
case ${TYPE} in
NS) SUBZONES="${SUBZONES} ${NAME}" ;;
A|AAAA|CNAME) HOSTS="${NAME} ${HOSTS}" ;;
esac
done
UNIQUE_SUBZONES=$(echo ${SUBZONES} | tr ' ' '\n' | sort -u)
for SUBZONE in ${UNIQUE_SUBZONES}; do
if [ ${SUBZONE} != ${ZONE} ]; then
HOSTS="$(print_hosts ${SUBZONE}) ${HOSTS}"
fi
done
UNIQUE_HOSTS=$(echo ${HOSTS} | tr ' ' '\n' | sort -u)
for HOST in ${UNIQUE_HOSTS}; do
echo ${HOST%.}
done
}
print_hosts $@

0
bash/restic-btrfs-snapshots.sh Normal file → Executable file
View file

8
bash/sep.sh Executable file
View file

@ -0,0 +1,8 @@
#!/bin/bash
for file in *.PDF; do
name=$(basename -s .PDF $file)
pdfseparate $file "$name-%d.pdf"
done

0
bash/smart-read.sh Normal file → Executable file
View file

0
bash/update-roa.sh Normal file → Executable file
View file

0
bash/update-xmltv.sh Normal file → Executable file
View file

View file

@ -1,11 +0,0 @@
#!/bin/bash
### BEGIN INIT INFO
# Provides: uptime
# Required-Start: $remote_fs
# Required-Stop: $remote_fs
# Default-Stop: 0 1 6
# Short-Description: Log uptime of server before shutdown
### END INIT INFO
echo $(date +%s) $(cat /proc/uptime) >> /var/log/uptime.log

8
bash/virsh-start-all.sh → bash/virsh-all.sh Normal file → Executable file
View file

@ -1,13 +1,15 @@
#!/bin/bash #!/bin/bash
## ##
# Start all libvirt VMs # Perform an action for all libvirt VMs
# #
# @copyright 2021, Steffen Vogel # @copyright 2021, Steffen Vogel
# @license http://www.gnu.org/licenses/gpl.txt GNU Public License # @license http://www.gnu.org/licenses/gpl.txt GNU Public License
# @author Steffen Vogel <post@steffenvogel.de> # @author Steffen Vogel <post@steffenvogel.de>
# @link http://www.steffenvogel.de # @link https://www.steffenvogel.de
## ##
ACTION=${ACTION:-start}
for VM in $(virsh list --inactive --name); do for VM in $(virsh list --inactive --name); do
virsh start ${VM} virsh ${ACTION} ${VM}
done done

View file

@ -4,24 +4,10 @@
# #
# includes MAC lookup via DNS and ARP # includes MAC lookup via DNS and ARP
# #
# @copyright 2012 Steffen Vogel # @copyright 2021, Steffen Vogel
# @license http://www.gnu.org/licenses/gpl.txt GNU Public License # @license http://www.gnu.org/licenses/gpl.txt GNU Public License
# @author Steffen Vogel <info@steffenvogel.de> # @author Steffen Vogel <post@steffenvogel.de>
# @link http://www.steffenvogel.de/ # @link https://www.steffenvogel.de/
##
##
# This script is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# any later version.
#
# This script 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this script. If not, see <http://www.gnu.org/licenses/>.
## ##
IP_REGEX="[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}" IP_REGEX="[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}"

16
bash/zfs-load-keys.sh Normal file → Executable file
View file

@ -13,13 +13,13 @@ IFS="
" "
for dataset in $(zfs list -H -p -o name,encryptionroot | \ for dataset in $(zfs list -H -p -o name,encryptionroot | \
awk -F "\t" '{if ($1 == $2) { print $1 }}') awk -F "\t" '{if ($1 == $2) { print $1 }}')
do do
if [ "$(zfs get -H -p -o value keylocation "$dataset")" = "prompt" ] && if [ "$(zfs get -H -p -o value keylocation "$dataset")" = "prompt" ] &&
[ "$(zfs get -H -p -o value keystatus "$dataset")" = "unavailable" ] [ "$(zfs get -H -p -o value keystatus "$dataset")" = "unavailable" ]
then then
systemd-ask-password --id="zfs:$dataset" \ systemd-ask-password --id="zfs:$dataset" \
"Enter passphrase for '$dataset':" | \ "Enter passphrase for '$dataset':" | \
zfs load-key "$dataset" zfs load-key "$dataset"
fi fi
done done

View file

@ -10,12 +10,12 @@
IP=192.168.1.1 IP=192.168.1.1
USER=admin USER=admin
PW=XXXXX # Change me
# change password here
#PW=
OLD_IP=`wget http://checkip.dyndns.org/ -O /dev/stdout 2&gt;/dev/null | sed "s/.*Current IP Address: \([0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\).*/\1/"` OLD_IP=`wget http://checkip.dyndns.org/ -O /dev/stdout 2&gt;/dev/null | sed "s/.*Current IP Address: \([0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\).*/\1/"`
echo "Alte IP: $OLD_IP" echo "Alte IP: $OLD_IP"
curl http://$USER:$PW@$IP/Forms/DiagADSL_1 -d "LineInfoDisplay=&amp;DiagDSLDisconnect=PPPoE+Trennung" curl http://$USER:$PW@$IP/Forms/DiagADSL_1 -d "LineInfoDisplay=&amp;DiagDSLDisconnect=PPPoE+Trennung"
NEW_IP=`wget http://checkip.dyndns.org/ -O /dev/stdout 2&gt;/dev/null | sed "s/.*Current IP Address: \([0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\).*/\1/"` NEW_IP=`wget http://checkip.dyndns.org/ -O /dev/stdout 2&gt;/dev/null | sed "s/.*Current IP Address: \([0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\).*/\1/"`
echo "Neue IP: $NEW_IP" echo "Neue IP: $NEW_IP"