dotfiles

configuration files for shell, text editor, graphical environment, etc.
git clone git://src.adamsgaard.dk/dotfiles
Log | Files | Refs | README | LICENSE Back to index

commit a522b50c772b1d0eba3d890a993bb5eda0a5cc02
parent 902eee60004574549cd4fc41946ddb493251b124
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date:   Thu,  8 Aug 2019 12:37:45 +0200

Convert upload to posix shell, update ssh config, add ve as submodule

Diffstat:
M.gitmodules | 3+++
M.local/bin/upload | 233+++++++++++++++++++++++++++++++++++++++++--------------------------------------
A.local/lib/ve | 1+
M.ssh/config | 36++++++++++++++++++++----------------
4 files changed, 146 insertions(+), 127 deletions(-)

diff --git a/.gitmodules b/.gitmodules @@ -19,3 +19,6 @@ [submodule ".local/lib/sent"] path = .local/lib/sent url = https://git.suckless.org/sent +[submodule ".local/lib/ve"] + path = .local/lib/ve + url = git@gitlab.com:admesg/ve.git diff --git a/.local/bin/upload b/.local/bin/upload @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/bin/sh set -e version=1.0 @@ -9,139 +9,150 @@ user="ad" port="12346" remotedir="/var/www/html/files_nonpub" -function show_help { - echo "usage: ${0##*/} [OPTIONS] FILE1 [FILE2...[FILE N]]" - echo "will upload each FILE to $user@$host:$remotedir" - echo "If no FILE is specified, this program will expect stdin." - echo "OPTIONS are one or more of the following:" - echo " -h, --help show this message" - echo " -v, --version show version and license information" - echo " -n, --notify also show diagnostic output with notify-send" - echo " -- do not consider any following arguments as options" - echo " -b, --border if an image, add a 10% white border to FILES" - echo " -r, --resize if an image, resize FILES to fit 800x800 pixels" - echo " without changing its width-to-height ratio" - echo " -s, --sharpen if an image, sharpen all FILES" - echo "the optional operations are performed in the order listed above." - echo "${0##*/} requires imagemagick and rsync to be installed on the system." +show_help() { + echo "usage: ${0##*/} [OPTIONS] FILE1 [FILE2...[FILE N]]" + echo "will upload each FILE to $user@$host:$remotedir" + echo "If no FILE is specified, this program will expect stdin, and FILE1" + echo "will be used as the filename during upload." + echo + echo "OPTIONS are one or more of the following:" + echo " -h, --help show this message" + echo " -v, --version show version and license information" + echo " -n, --notify also show diagnostic output with notify-send" + echo " -- do not consider any following arguments as options" + echo " -b, --border if an image, add a 10% white border to FILES" + echo " -r, --resize if an image, resize FILES to fit 800x800 pixels" + echo " without changing its width-to-height ratio" + echo " -s, --sharpen if an image, sharpen all FILES" + echo "the optional operations are performed in the order listed above." + echo "${0##*/} requires imagemagick and rsync to be installed on the system." } -function show_version { - echo "${0##*/} version $version" - echo "Licensed under the GNU Public License, v3+" - echo "written by Anders Damsgaard, anders@adamsgaard.dk" - echo "https://gitlab.com/admesg/dotfiles" +show_version() { + echo "${0##*/} version $version" + echo "Licensed under the GNU Public License, v3+" + echo "written by Anders Damsgaard, anders@adamsgaard.dk" + echo "https://gitlab.com/admesg/dotfiles" } -function check_if_image { - identify "$1" &>/dev/null || die "Error: $1 is not an image" +check_if_image() { + identify "$1" >/dev/null 2>&1 || die "Error: $1 is not an image" } -function add_sharpening { - check_if_image "$2" - convert "$1" \ - -unsharp 2x0.5+0.7+0 \ - -quality 95 \ - "$1" +add_sharpening() { + check_if_image "$2" + convert "$1" \ + -unsharp 2x0.5+0.7+0 \ + -quality 95 \ + "$1" } -function add_border { - check_if_image "$2" - convert "$1" \ - -bordercolor White -border 10%x10% \ - -unsharp 2x0.5+0.7+0 \ - -quality 95 \ - "$1" +add_border() { + check_if_image "$2" + convert "$1" \ + -bordercolor White -border 10%x10% \ + -unsharp 2x0.5+0.7+0 \ + -quality 95 \ + "$1" } -function add_resize { - check_if_image "$2" - convert "$1" \ - -resize 800x800\> \ - -quality 95 \ - "$1" +add_resize() { + check_if_image "$2" + convert "$1" \ + -resize 800x800\> \ + -quality 95 \ + "$1" } -function upload_file { - infile="$1" - basename="$2" - newbasename="${basename// /_}" - rsync -rvz --progress --chmod=Fu=rw,Fog=r -e "ssh -p $port" "$infile" \ - "${user}@${host}:${remotedir}/$newbasename" - url="https://$host/files_nonpub/${newbasename}" - echo - msg="Uploaded to $url (copied to clipboard)" - printf "%s\n" "$msg" - [ "$notify" = 1 ] && notify-send "$msg" - - if [ "$(uname)" = "Darwin" ]; then - printf "%s" "$url" | pbcopy - else - printf "%s" "$url" | xclip - fi +preprocess_file() { + [ "$border" = 1 ] && add_border "$1" "$2" + [ "$resize" = 1 ] && add_resize "$1" "$2" + [ "$sharpen" = 1 ] && add_sharpening "$1" "$2" } -function die { - printf '%s\n' "$1" >&2 - exit 1 +upload_file() { + infile="$1" + basename="$2" + newbasename="$(echo "$basename" | sed 's/ /_/g')" + rsync -rvz --progress --chmod=Fu=rw,Fog=r -e "ssh -p $port" "$infile" \ + "${user}@${host}:${remotedir}/$newbasename" + url="https://$host/files_nonpub/${newbasename}" + echo + msg="Uploaded to $url (copied to clipboard)" + printf "%s\n" "$msg" + [ "$notify" = 1 ] && notify-send "$msg" + + if [ "$(uname)" = "Darwin" ]; then + printf "%s" "$url" | pbcopy + else + printf "%s" "$url" | xclip + fi +} + +die() { + printf '%s\n' "$1" >&2 + exit 1 } -# parse input arguments (http://mywiki.wooledge.org/BashFAQ/035) notify=0 border=0 resize=0 sharpen=0 while :; do - case "$1" in - -h|-\?|--help) - show_help - exit 0 - ;; - -v|--version) - show_version - exit 0 - ;; - -n|--notify) - notify=1 - ;; - -b|--border) - border=1 - ;; - -r|--resize) - resize=1 - ;; - -s|--sharpen) - sharpen=1 - ;; - --) # end all options - shift - break - ;; - -?*) - die 'Error: Unknown option specified' - ;; - *) # No more options - break - esac - shift + case "$1" in + -h|-\?|--help) + show_help + exit 0 + ;; + -v|--version) + show_version + exit 0 + ;; + -n|--notify) + notify=1 + ;; + -b|--border) + border=1 + ;; + -r|--resize) + resize=1 + ;; + -s|--sharpen) + sharpen=1 + ;; + --) # end all options + shift + break + ;; + -?*) + die 'Error: Unknown option specified' + ;; + *) # No more options + break + esac + shift done if [ $# -lt 1 ]; then - msg="$(cat)" - tempfile="$(mktemp)" - printf "%s" "$msg" > "$tempfile" - upload_file "$tempfile" "${tempfile##*.}" + show_help + exit 1 +fi + +if [ ! -f "$1" ]; then + msg="$(cat)" + tempfile="$(mktemp)" + printf "%s" "$msg" > "$tempfile" + + preprocess_file "$tempfile" "$1" + upload_file "$tempfile" "$(basename "$1")" else - # loop over FILE[S] - for f in "$@"; do - tempfile="$(mktemp)" - [ ! -f "$f" ] && die "Error: $f is not a file" - cp "$f" "$tempfile" - - [ "$border" = 1 ] && add_border "$tempfile" "$f" - [ "$resize" = 1 ] && add_resize "$tempfile" "$f" - [ "$sharpen" = 1 ] && add_sharpening "$tempfile" "$f" - - upload_file "$tempfile" "$(basename "$f")" - done + # loop over FILE[S] + for f in "$@"; do + [ ! -f "$f" ] && die "Error: $f is not a file" + + tempfile="$(mktemp)" + cp "$f" "$tempfile" + preprocess_file "$tempfile" "$1" + upload_file "$tempfile" "$(basename "$f")" + done fi diff --git a/.local/lib/ve b/.local/lib/ve @@ -0,0 +1 @@ +Subproject commit c3288feb03125b18f98b46cd0d82f9ff5ced5182 diff --git a/.ssh/config b/.ssh/config @@ -1,13 +1,13 @@ AddKeysToAgent yes Host * - ForwardX11Trusted no - ForwardX11 no + ForwardX11Trusted no + ForwardX11 no Host home - Hostname 85.191.223.149 - User ad - Port 12344 + Hostname 85.191.223.149 + User ad + Port 12344 #Host ad-server # Hostname 192.168.0.57 @@ -15,20 +15,24 @@ Host home # Port 12344 Host ad-server-wifi - Hostname 192.168.0.45 - User ad - Port 12344 + Hostname 192.168.0.45 + User ad + Port 12344 Host adamsgaard.dk - Hostname adamsgaard.dk - User ad - Port 12344 + Hostname adamsgaard.dk + User ad + Port 12344 Host debvm - Hostname adamsgaard.dk - User ad - Port 12346 + Hostname adamsgaard.dk + User ad + Port 12346 Host aur.archlinux.org - IdentityFile ~/.ssh/aur - User aur + IdentityFile ~/.ssh/aur + User aur + +Host raspberrypi + Hostname 192.168.0.142 + User pi