From 57ee947cdf61aab65b2f2d3ef1d0f3453550cddb Mon Sep 17 00:00:00 2001 From: surtur Date: Fri, 2 Sep 2022 18:11:18 +0200 Subject: [PATCH] nix(home-manager): directly manage some .sh files --- backups/authenticator.sh | 33 ---------------- backups/createarchive.sh | 41 -------------------- home.nix | 84 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+), 74 deletions(-) delete mode 100755 backups/authenticator.sh delete mode 100755 backups/createarchive.sh diff --git a/backups/authenticator.sh b/backups/authenticator.sh deleted file mode 100755 index 33cd3b7..0000000 --- a/backups/authenticator.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/sh - -# adopted from https://wiki.archlinux.org/index.php/Google_Authenticator -# This is the path to the Google Authenticator app file. It's typically located -# in /data under Android. Copy it to your PC in a safe location and specify the -# path to it here. -#DB="/path/to/com.google.android.apps.authenticator/databases/databases" -DB="$1" - - -if [ $# -ne 1 ]; then - printf "authenticator\n" - printf "usage: authenticator \n" - printf "\tThis is the path to the Authenticator app owned SQLite db file.\n" - printf "\tCopy it to your PC to a safe location and specify the path to it here.\n" - exit 1 -fi - - -# On most Android systems with sufficient user access, the Google Authenticator -# database can be copied off the device and accessed directly, as it is an -# sqlite3 database. This shell script will read a Google Authenticator database -# and generate live codes for each key found: - - -sqlite3 "$DB" 'SELECT email,secret FROM accounts;' | while read A -do - NAME=`echo "$A" | cut -d '|' -f 1` - KEY=`echo "$A" | cut -d '|' -f 2` - CODE=`oathtool --totp -b "$KEY"` - echo -e "\e[1;32m$CODE\e[0m - \e[1;33m$NAME\e[0m" -done - diff --git a/backups/createarchive.sh b/backups/createarchive.sh deleted file mode 100755 index 155bc6c..0000000 --- a/backups/createarchive.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/bin/bash - -if [ $# -ne 1 ]; then - printf "createarchive\n" - printf "usage: createarchive \n" - printf "warning: the archive will be moved to "backups" directory (`echo $dest`)\n" - exit 1 -fi - - -# what this does in short: tar, compress, timestamp, shred the tar, mv .xz to pwd and display it -logdate="$(date +%Y%m%dT%H%M%S)" -basedir="$1" -tmpdir=$(mktemp -d "${TMPDIR:-/tmp/}$(basename $0).XXXXXXXXXX") -#/run/user/$(id -u) tmpfs 0700 perms -f="`cd $basedir; pwd | tr '/' ' ' | sed 's/^.* / /' | cut -c2-`" > /dev/null -g="$logdate-$f.tar" -dest=~/MEGA/Private/backups - -doathing() { - cd $basedir/.. - tar cfv "$tmpdir/$g" "$f" && \ - xz -vzk9e "$tmpdir/$g" -S .xz && \ - rsync -avP "$tmpdir/$g.xz" "$dest" && \ - shred -zuv "$tmpdir/$g" "$tmpdir/$g.xz" && \ - printf "\n" - ls -latr "$dest/$g.xz" -} - -if [ ! -d $1 ]; then - echo "$1 is not a directory" - exit 1 -else - echo `pwd` - echo "$f" - echo "$1" - - doathing - trap "rm -rfv $tmpdir" 0 1 3 15 - exit $? -fi diff --git a/home.nix b/home.nix index fb65ad4..157bcbb 100644 --- a/home.nix +++ b/home.nix @@ -71,5 +71,89 @@ source = bin/winprint.sh; executable = true; }; + + ".local/bin/authenticator.sh" = { + text = '' + #!/bin/sh + + # adopted from https://wiki.archlinux.org/index.php/Google_Authenticator + # This is the path to the Google Authenticator app file. It's typically located + # in /data under Android. Copy it to your PC in a safe location and specify the + # path to it here. + #DB="/path/to/com.google.android.apps.authenticator/databases/databases" + DB="$1" + + + if [ $# -ne 1 ]; then + printf "authenticator\n" + printf "usage: authenticator \n" + printf "\tThis is the path to the Authenticator app owned SQLite db file.\n" + printf "\tCopy it to your PC to a safe location and specify the path to it here.\n" + exit 1 + fi + + + # On most Android systems with sufficient user access, the Google Authenticator + # database can be copied off the device and accessed directly, as it is an + # sqlite3 database. This shell script will read a Google Authenticator database + # and generate live codes for each key found: + + + sqlite3 "$DB" 'SELECT email,secret FROM accounts;' | while read A + do + NAME=`echo "$A" | cut -d '|' -f 1` + KEY=`echo "$A" | cut -d '|' -f 2` + CODE=`oathtool --totp -b "$KEY"` + echo -e "\e[1;32m$CODE\e[0m - \e[1;33m$NAME\e[0m" + done + ''; + executable = true; + }; + ".local/bin/createarchive.sh" = { + text = '' + #!/bin/bash + + if [ $# -ne 1 ]; then + printf "createarchive\n" + printf "usage: createarchive \n" + printf "warning: the archive will be moved to "backups" directory (`echo $dest`)\n" + exit 1 + fi + + + # what this does in short: tar, compress, timestamp, shred the tar, mv .xz to pwd and display it + logdate="$(date +%Y%m%dT%H%M%S)" + basedir="$1" + tmpdir=$(mktemp -d "${TMPDIR:-/tmp/}$(basename $0).XXXXXXXXXX") + #/run/user/$(id -u) tmpfs 0700 perms + f="`cd $basedir; pwd | tr '/' ' ' | sed 's/^.* / /' | cut -c2-`" > /dev/null + g="$logdate-$f.tar" + dest=~/MEGA/Private/backups + + doathing() { + cd $basedir/.. + tar cfv "$tmpdir/$g" "$f" && \ + xz -vzk9e "$tmpdir/$g" -S .xz && \ + rsync -avP "$tmpdir/$g.xz" "$dest" && \ + shred -zuv "$tmpdir/$g" "$tmpdir/$g.xz" && \ + printf "\n" + ls -latr "$dest/$g.xz" + } + + if [ ! -d $1 ]; then + echo "$1 is not a directory" + exit 1 + else + echo `pwd` + echo "$f" + echo "$1" + + doathing + trap "rm -rfv $tmpdir" 0 1 3 15 + exit $? + fi + ''; + executable = true; + }; }; }