summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorTharre <tharre3@gmail.com>2018-05-09 02:58:18 +0200
committerTharre <tharre3@gmail.com>2018-05-09 17:28:13 +0200
commit321d9a8247d50cd634615ffed707aed3f4376108 (patch)
tree32fbd27e3a9e8c3f41d68232ffe203ef0ce10999 /bin
parent3cb67ddae1d11e4cda22b9843665b6d3775828da (diff)
downloaddotfiles-321d9a8247d50cd634615ffed707aed3f4376108.tar.gz
dotfiles-321d9a8247d50cd634615ffed707aed3f4376108.tar.xz
dotfiles-321d9a8247d50cd634615ffed707aed3f4376108.zip
Move various scripts and functions into bin/
Diffstat (limited to 'bin')
-rw-r--r--bin/.gitignore11
-rwxr-xr-xbin/play12
-rwxr-xr-xbin/req_pwd.sh19
-rwxr-xr-xbin/reset_usb5
-rwxr-xr-xbin/set_xdg_dirs13
-rwxr-xr-xbin/setup_borgbackup18
-rwxr-xr-xbin/suspend_after6
-rwxr-xr-xbin/update_dotfiles20
-rwxr-xr-xbin/ut8font_test3
9 files changed, 107 insertions, 0 deletions
diff --git a/bin/.gitignore b/bin/.gitignore
new file mode 100644
index 0000000..5c976d1
--- /dev/null
+++ b/bin/.gitignore
@@ -0,0 +1,11 @@
+*
+
+!.gitignore
+!play
+!req_pwd.sh
+!reset_usb
+!set_xdg_dirs
+!setup_borgbackup
+!suspend_after
+!update_dotfiles
+!ut8font_test
diff --git a/bin/play b/bin/play
new file mode 100755
index 0000000..ed70ce9
--- /dev/null
+++ b/bin/play
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+# requires youtube-dl, mpv
+# Skip DASH manifest for speed purposes. This might actually disable
+# being able to specify things like 'bestaudio' as the requested format,
+# but try anyway.
+# Use "$*" so that quoting the requested song isn't necessary.
+mpv $(youtube-dl --default-search=ytsearch: \
+ --max-downloads 1 \
+ --youtube-skip-dash-manifest \
+ --format="bestaudio/best" \
+ -g "$*") --no-video
diff --git a/bin/req_pwd.sh b/bin/req_pwd.sh
new file mode 100755
index 0000000..3a6be86
--- /dev/null
+++ b/bin/req_pwd.sh
@@ -0,0 +1,19 @@
+#!/bin/sh -e
+# A simple wrapper script to deal with situations where pass, password-store, or
+# my gpg key is not available.
+
+pass "$1" && exit
+
+# maybe gpg-agent is acting up, retry after restarting it
+gpg-connect-agent "KILLAGENT" /bye >&2 >/dev/null
+gpg-connect-agent /bye >&2 >/dev/null
+pass "$1" && exit
+
+# if pass fails, request password manually
+stty -echo
+printf "Password: " >&2
+read passwd
+stty echo
+printf "\n" >&2
+
+printf "$passwd"
diff --git a/bin/reset_usb b/bin/reset_usb
new file mode 100755
index 0000000..2d20d8e
--- /dev/null
+++ b/bin/reset_usb
@@ -0,0 +1,5 @@
+#!/bin/bash -e
+
+for i in /sys/bus/pci/drivers/[uoex]hci_hcd/*:*; do
+ echo "${i##*/}" | sudo tee "${i%/*}/"{unbind,bind}
+done
diff --git a/bin/set_xdg_dirs b/bin/set_xdg_dirs
new file mode 100755
index 0000000..5a365e2
--- /dev/null
+++ b/bin/set_xdg_dirs
@@ -0,0 +1,13 @@
+#!/bin/sh -e
+
+xdg-user-dirs-update --set DESKTOP ~/var/desktop
+xdg-user-dirs-update --set DOWNLOAD ~/var/downloads
+xdg-user-dirs-update --set TEMPLATES ~/var/templates
+xdg-user-dirs-update --set PUBLICSHARE ~/share/public
+xdg-user-dirs-update --set DOCUMENTS ~/var/documents
+xdg-user-dirs-update --set MUSIC ~/media/music
+xdg-user-dirs-update --set PICTURES ~/media/pictures
+xdg-user-dirs-update --set VIDEOS ~/media/videos
+
+rmdir ~/Desktop ~/Downloads ~/Templates ~/Public ~/Documents ~/Music \
+ ~/Pictures ~/Videos
diff --git a/bin/setup_borgbackup b/bin/setup_borgbackup
new file mode 100755
index 0000000..6e857a1
--- /dev/null
+++ b/bin/setup_borgbackup
@@ -0,0 +1,18 @@
+#!/bin/sh -e
+
+BORG_SECRET=~/.borg_secret
+BORG_SSH_KEY=~/.ssh/borg_key
+
+if [ ! -f "$BORG_SECRET" ]; then
+ install -m600 /dev/null "$BORG_SECRET"
+ pass backups/$(hostname) > "$BORG_SECRET"
+fi
+
+if [ ! -f "$BORG_SSH_KEY" ]; then
+ ssh-keygen -q -N "" -f "$BORG_SSH_KEY"
+ KEY=$(< ${BORG_SSH_KEY}.pub)
+
+ printf '%s\n' "command=\"cd /srv/borgbackup/repos/$(hostname);borg serve --restrict-to-path /srv/borgbackup/repos/$(hostname)\",restrict $KEY" | ssh "$1" "cat >> /srv/borgbackup/.ssh/authorized_keys"
+
+ echo "Added key to remote server."
+fi
diff --git a/bin/suspend_after b/bin/suspend_after
new file mode 100755
index 0000000..5f6cce4
--- /dev/null
+++ b/bin/suspend_after
@@ -0,0 +1,6 @@
+#!/bin/bash -e
+
+trap 'kill $!' INT TERM EXIT
+systemd-inhibit --what=handle-lid-switch sleep 1d &
+eval "$*"
+systemctl suspend
diff --git a/bin/update_dotfiles b/bin/update_dotfiles
new file mode 100755
index 0000000..6c45971
--- /dev/null
+++ b/bin/update_dotfiles
@@ -0,0 +1,20 @@
+#!/bin/sh -e
+
+dotfiles="$HOME/dotfiles"
+epoch_file="$dotfiles/.updated"
+epoch_curr=$(date +'%s')
+[ -e "$epoch_file" ] && epoch_old=$(<"$epoch_file")
+epoch_diff=$(($epoch_curr - ${epoch_old:-0}))
+max_time=$((60 * 60 * 24 * 7))
+
+if [ $(($epoch_diff / $max_time)) -ne 0 ]; then
+ echo "Updating dotfiles ..."
+
+ cd "$dotfiles"
+ git pull --rebase --stat origin master
+ echo $epoch_curr > "$epoch_file"
+ ./install.sh
+ cd -
+
+ echo "Finished."
+fi
diff --git a/bin/ut8font_test b/bin/ut8font_test
new file mode 100755
index 0000000..30c6b45
--- /dev/null
+++ b/bin/ut8font_test
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+curl http://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-demo.txt