diff options
author | Tharre <tharre3@gmail.com> | 2018-05-09 02:58:18 +0200 |
---|---|---|
committer | Tharre <tharre3@gmail.com> | 2018-05-09 17:28:13 +0200 |
commit | 321d9a8247d50cd634615ffed707aed3f4376108 (patch) | |
tree | 32fbd27e3a9e8c3f41d68232ffe203ef0ce10999 | |
parent | 3cb67ddae1d11e4cda22b9843665b6d3775828da (diff) | |
download | dotfiles-321d9a8247d50cd634615ffed707aed3f4376108.tar.gz dotfiles-321d9a8247d50cd634615ffed707aed3f4376108.tar.xz dotfiles-321d9a8247d50cd634615ffed707aed3f4376108.zip |
Move various scripts and functions into bin/
-rw-r--r-- | .mbsyncrc | 2 | ||||
-rw-r--r-- | .msmtprc | 2 | ||||
-rw-r--r-- | .zshrc | 89 | ||||
-rw-r--r-- | bin/.gitignore | 11 | ||||
-rwxr-xr-x | bin/play | 12 | ||||
-rwxr-xr-x | bin/req_pwd.sh (renamed from .req_pwd.sh) | 0 | ||||
-rwxr-xr-x | bin/reset_usb | 5 | ||||
-rwxr-xr-x | bin/set_xdg_dirs | 13 | ||||
-rwxr-xr-x | bin/setup_borgbackup | 18 | ||||
-rwxr-xr-x | bin/suspend_after | 6 | ||||
-rwxr-xr-x | bin/update_dotfiles | 20 | ||||
-rwxr-xr-x | bin/ut8font_test | 3 | ||||
-rwxr-xr-x | install.sh | 3 |
13 files changed, 94 insertions, 90 deletions
@@ -3,7 +3,7 @@ IMAPAccount tharre3@gmail.com # widely supported at this time Host imaps:imap.gmail.com User tharre3@gmail.com -PassCmd "~/.req_pwd.sh email/tharre3@gmail.com" +PassCmd "req_pwd.sh email/tharre3@gmail.com" # SSLType IMAPS SSLVersion TLSv1.2 CertificateFile /etc/ssl/certs/ca-certificates.crt @@ -11,7 +11,7 @@ host smtp.gmail.com port 587 from tharre3@gmail.com user tharre3@gmail.com -passwordeval "~/.req_pwd.sh email/tharre3@gmail.com" +passwordeval "req_pwd.sh email/tharre3@gmail.com" # Set a default account account default : gmail @@ -108,95 +108,8 @@ function 256color_test { done ) } -function utf8font_test { - curl http://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-demo.txt -} - -# requires youtube-dl, mpv -function play { - # 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 -} - -function set_xdg_dirs { - 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 -} - -# update -function update_dotfiles() { - 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 -} - -function suspend_after() { - trap 'kill $!' INT TERM EXIT - systemd-inhibit --what=handle-lid-switch sleep 1d & - eval "$*" - systemctl suspend -} - -function reset_usb() { - for i in /sys/bus/pci/drivers/[uoex]hci_hcd/*:*; do - echo "${i##*/}" | sudo tee "${i%/*}/"{unbind,bind} - done -} - -function setup_borgbackup() { - setopt ERR_RETURN - - 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 -} - ## PATH -export PATH=$PATH:$HOME/bin +export PATH="$HOME/bin:$PATH" ## alias 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/.req_pwd.sh b/bin/req_pwd.sh index 3a6be86..3a6be86 100755 --- a/.req_pwd.sh +++ b/bin/req_pwd.sh 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 @@ -40,5 +40,8 @@ done # fix .gnupg permissions chmod 700 .gnupg +mkdir -p ~/bin +find "$(pwd)/bin" -maxdepth 1 ! -path . -exec ln -sf {} ~/bin/ \; + # remove broken symlinks find -L "$HOME" -maxdepth 1 -type l -delete |