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

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

View file

@ -75,4 +75,3 @@ btrfs subvolume snapshot -r $DEST/.current $DEST/$DATE
# create symlink to latest snapshot
ln -rsfT $DEST/$DATE $DEST/latest

View file

@ -2,24 +2,10 @@
##
# System Backupscript
#
# @copyright 2012 Steffen Vogel
# @copyright 2021, 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/>.
# @author Steffen Vogel <post@steffenvogel.de>
# @link https://www.steffenvogel.de
##
#=============================================================
@ -34,7 +20,7 @@ BACKUPDIR="/backup"
MYSQL_BACKUPDIR="/backup/mysql"
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
# Kompressionsmethode (gzip oder bzip2)
@ -68,7 +54,7 @@ LOGERR=$BACKUPDIR/ERRORS_$HOST-`date +%N`.log
# - quiet : sendet nur Error Logs per Mail
MAIL_CONTENT="stdout"
# Maximale Größe des Mail Anhangs
# Maximale Gr<EFBFBD><EFBFBD>e des Mail Anhangs
MAIL_MAXATTSIZE="4000"
# Mail Adresse
@ -81,7 +67,7 @@ MAIL_ADDR="admin@localhost"
# FTP Benutzer
FTP_USERNAME=yourftpusername
# FTP Passwort für $FTP_USERNAME
# FTP Passwort f<EFBFBD>r $FTP_USERNAME
FTP_PASSWORD=yourftppassword
# Hostname oder IP Adresse des FTP Servers
@ -91,10 +77,10 @@ FTP_HOST=yourftpserver
# Daten Einstellungen
#=============================================================
# Liste der täglichen Backupverzeichnisse (durch " " getrennt)
# Liste der t<EFBFBD>glichen Backupverzeichnisse (durch " " getrennt)
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"
# Liste der monatlichen Backupverzeichnisse (durch " " getrennt)
@ -114,16 +100,16 @@ TARFLAGS="--create --preserve-permissions --dereference --ignore-failed-read --e
# mySQL Benutzer
MYSQL_USERNAME=yourmysqlusername
# mySQL Passwort für $MYSQL_USERNAME
# mySQL Passwort f<EFBFBD>r $MYSQL_USERNAME
MYSQL_PASSWORD=yourmysqlpassword
# Hostname oder IP Adresse des mySQL Servers
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"
# Liste der wöchentlichen Backupdatenbanken (durch " " getrennt)
# Liste der w<EFBFBD>chentlichen Backupdatenbanken (durch " " getrennt)
MYSQL_WDBNAMES=$MYSQL_DBNAMES
# Liste der monatlichen Backupdatenbanken (durch " " getrennt)
@ -132,13 +118,13 @@ MYSQL_MDBNAMES="$MYSQL_WDBNAMES"
# Datenbanken zum Excluden
MYSQL_DBEXCLUDE=""
# CREATE DATABASE zu den mySQL Dumps hinzufügen?
# CREATE DATABASE zu den mySQL Dumps hinzuf<EFBFBD>gen?
MYSQL_CREATE_DATABASE=yes
# Komprimierte Verbindung zum mySQL Server
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=
# Socketadresse des mySQL Server bei localhost Verbindungen
@ -174,13 +160,13 @@ if [ "$MYSQL_COMMCOMP" = "yes" ];
MYSQL_OPT="$OPT --compress"
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" ];
then
MYSQL_OPT="$MYSQL_OPT --max_allowed_packet=$MYSQL_MAX_ALLOWED_PACKET"
fi
# Benötigte Verzeichnisse erstellen
# Ben<EFBFBD>tigte Verzeichnisse erstellen
if [ ! -e "$BACKUPDIR" ]
then
mkdir -p "$BACKUPDIR"
@ -236,7 +222,7 @@ display () {
end)
echo Backup Ende `date`
echo ======================================================================
echo Benötigter Speicherplatz für Backups:
echo Ben<EFBFBD>tigter Speicherplatz f<>r Backups:
echo Data : `du -hs "$DATA_BACKUPDIR"`
echo mySQL: `du -hs "$MYSQL_BACKUPDIR"`
echo All : `du -hs "$BACKUPDIR"`
@ -299,27 +285,27 @@ archive () {
gzip -l "$1.gz"
SUFFIX=".gz"
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
SUFFIX=".bz2"
else
echo "Keine Kompressionsmethode gewählt!"
echo "Keine Kompressionsmethode gew<EFBFBD>hlt!"
fi
return 0
}
# Soll CREATE_DATABASE hinzugefügt werden?
# Soll CREATE_DATABASE hinzugef<EFBFBD>gt werden?
if [ "$MYSQL_CREATE_DATABASE" = "no" ]; then
MYSQL_OPT="$MYSQL_OPT --no-create-db"
else
MYSQL_OPT="$MYSQL_OPT --databases"
fi
# Wähle alle Datenbanken aus
# W<EFBFBD>hle alle Datenbanken aus
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'`"
# Schließe Datenbanken aus
# Schließe Datenbanken aus
for exclude in $MYSQL_DBEXCLUDE
do
MYSQL_DBNAMES=`echo $MYSQL_DBNAMES | sed "s/\b$exclude\b//g"`
@ -340,7 +326,7 @@ fi
#================================================
if [ $DOM = "01" ]; then
# Erstellen benötigte Verzeichnisse
# Erstellen ben<EFBFBD>tigte Verzeichnisse
if [ ! -e "$MYSQL_BACKUPDIR/monthly/$M" ]
then
mkdir -p "$MYSQL_BACKUPDIR/monthly/$M"
@ -374,7 +360,7 @@ display datastart
for DATA_MDIR in $DATA_MDIRNAMES
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'"
echo Monthly Backup of $DATA_MDIR...
@ -391,11 +377,11 @@ fi
#================================================
# Wöchentliches Backup
# W<EFBFBD>chentliches Backup
#================================================
if [ $DNOW = $DOWEEKLY ]; then
# Erstellen benötigte Verzeichnisse
# Erstellen ben<EFBFBD>tigte Verzeichnisse
if [ ! -e "$MYSQL_BACKUPDIR/weekly/week_$W" ]
then
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"
fi
# Lösche alte Backups
# L<EFBFBD>sche alte Backups
echo Rotating 5 weeks Backups...
display dl
if [ "$W" -le 05 ];then
@ -442,7 +428,7 @@ display datastart
for DATA_WDIR in $DATA_WDIRNAMES
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'"
echo Weekly Backup of $DATA_WDIR...
@ -458,9 +444,9 @@ display dataend
fi
#================================================
# Tägliches Backup
# T<EFBFBD>gliches Backup
#================================================
# Erstellen benötigte Verzeichnisse
# Erstellen ben<EFBFBD>tigte Verzeichnisse
if [ ! -e "$MYSQL_BACKUPDIR/daily/$DOW" ]
then
mkdir -p "$MYSQL_BACKUPDIR/daily/$DOW"
@ -471,7 +457,7 @@ if [ ! -e "$DATA_BACKUPDIR/daily/$DOW" ]
mkdir -p "$DATA_BACKUPDIR/daily/$DOW"
fi
# Lösche alte Backups
# L<EFBFBD>sche alte Backups
echo Rotating last weeks Backup...
display l
eval rm -fv "$MYSQL_BACKUPDIR/daily/$DOW/*"
@ -497,7 +483,7 @@ display datastart
for DATA_DIR in $DATA_DIRNAMES
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'"
echo Daily Backup of $DATA_DIR...
@ -519,39 +505,39 @@ if [ "$POSTBACKUP" ]; then
fi
#Clean up IO redirection
exec 1>&6 6>&- # Stelle Standartausgabe wieder her und schließe Datei #6
exec 1>&7 7>&- # Stelle Standartausgabe wieder her und schließe Datei #7
exec 1>&6 6>&- # Stelle Standartausgabe wieder her und schlie<EFBFBD>e Datei #6
exec 1>&7 7>&- # Stelle Standartausgabe wieder her und schlie<EFBFBD>e Datei #7
if [ "$MAIL_CONTENT" = "files" ]
then
if [ -s "$LOGERR" ]
then
# Füge bei Fehlern Error Log hinzu
# F<EFBFBD>ge bei Fehlern Error Log hinzu
MYSQL_BACKUPFILES="$MYSQL_BACKUPFILES $LOGERR"
ERRORNOTE="ACHTUNG Backup Fehler: "
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//`
if [ $MAIL_MAXATTSIZE -ge $MAIL_ATTSIZE ]
then
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
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
elif [ "$MAIL_CONTENT" = "log" ]
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" ]
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
elif [ "$MAIL_CONTENT" = "quiet" ]
then
if [ -s "$LOGERR" ]
then
cat "$LOGERR" | mail -s "$ERRORNOTE Error Log für $HOST - $DATE" $MAIL_ADDR
cat "$LOGFILE" | mail -s "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<EFBFBD>r $HOST - $DATE" $MAIL_ADDR
fi
else
if [ -s "$LOGERR" ]
@ -574,7 +560,7 @@ if [ -s "$LOGERR" ]
STATUS=0
fi
# Löschen der Logfiles
# L<EFBFBD>schen der Logfiles
eval rm -f "$LOGFILE"
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,26 +2,12 @@
##
# Deviant Background Changer
#
# @copyright 2012 Steffen Vogel
# @copyright 2021, Steffen Vogel
# @license http://www.gnu.org/licenses/gpl.txt GNU Public License
# @author Steffen Vogel <info@steffenvogel.de>
# @link http://www.steffenvogel.de/2009/11/28/deviantart-wallpapers/
# @author Steffen Vogel <post@steffenvogel.de>
# @link https://www.steffenvogel.de/2009/11/28/deviantart-wallpapers/
# @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
BG_PATH="/home/steffen/backgrounds"

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

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

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

@ -8,8 +8,8 @@
IPMIHOST=169.254.0.1
IPMIUSER=root
IPMIPW=3LpnMcnY99cybeGM
IPMIEK=6055530028595864123105836429105276020000
IPMIPW=XXXXX # Please change
IPMIEK=XXXXX # Please change
FANSPEEDHEX=${1:-0x08} # See https://i.imgur.com/u1HMyqI.png
MAXTEMP=60

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,8 +2,7 @@
# Must be called with two command-line args.
# Example: git-svn-relocate.sh http://old.server https://new.server
if [ $# -ne 2 ]
then
if [ $# -ne 2 ]; then
echo "Please invoke this script with two command-line arguments (old and new SVN URLs)."
exit $E_NO_ARGS
fi

View file

@ -7,14 +7,12 @@
# Use at your own risk. For the love of cthulhu, back
# your repo up before letting this loose on it.
if [ $# -ne 1 ]
then
if [ $# -ne 1 ]; then
echo "Usage: `basename $0` {new subversion url}"
exit -1
fi
if [[ $1 = "--help" || $1 = "-h" ]]
then
if [[ $1 = "--help" || $1 = "-h" ]]; then
echo
echo "Usage: `basename $0` {new subversion url}"
echo
@ -29,13 +27,11 @@ fi
# get the current subversion url
SRC=`git svn info --url`
if [ -n "$SRC" ]
then
if [ -n "$SRC" ]; then
FROM=`echo $SRC | sed "s|/trunk||"`
REPO=`svn info $1`
echo "Checking $REPO is actually a subversion repository..."
if [ -n "$REPO" ]
then
if [ -n "$REPO" ]; then
echo "The new URL looks valid."
echo "Rewriting the git history with the new url..."
SED_FILTER="sed 's;git-svn-id: "$FROM";git-svn-id: "$1";g'"

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

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

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
#
# @copyright 2012 Steffen Vogel
# @copyright 2021, 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/>.
# @author Steffen Vogel <post@steffenvogel.de>
# @link https://www.steffenvogel.de
##
function usage {

View file

@ -26,10 +26,10 @@
# followed by:
# mount /home
#
# @copyright 2013 Steffen Vogel
# @copyright 2021, Steffen Vogel
# @license http://www.gnu.org/licenses/gpl.txt GNU Public License
# @author Steffen Vogel <post@steffenvogel.de>
# @link http://www.steffenvogel.de
# @link https://www.steffenvogel.de
##
if [ "$(basename $0)" == "mount.luks" ]; then

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

@ -2,7 +2,12 @@
##
# 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
##
function usage {

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
##
# Start all libvirt VMs
# Perform an action for all libvirt VMs
#
# @copyright 2021, Steffen Vogel
# @license http://www.gnu.org/licenses/gpl.txt GNU Public License
# @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
virsh start ${VM}
virsh ${ACTION} ${VM}
done

View file

@ -4,24 +4,10 @@
#
# 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
# @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/>.
# @author Steffen Vogel <post@steffenvogel.de>
# @link https://www.steffenvogel.de/
##
IP_REGEX="[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}"

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

View file

@ -10,12 +10,12 @@
IP=192.168.1.1
USER=admin
# change password here
#PW=
PW=XXXXX # Change me
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"
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/"`
echo "Neue IP: $NEW_IP"