Skip to content

Instantly share code, notes, and snippets.

View wernerb's full-sized avatar
🏠
Working from home

Werner Buck wernerb

🏠
Working from home
View GitHub Profile
@wernerb
wernerb / wgetmirror.sh
Last active December 27, 2015 23:29
Uses strictly wget and grep to mirror a remote HTTP location recursively. Deletes old files. Supports http auth and self-signed certificates. Strictly POSIX compliant so that it works in "dash" as well as in "bash". Handy to use on arm devices that need syncing but do not have rsync or ssh. Currently used to sync multiple kobo ereaders.
View wgetmirror.sh
#!/bin/bash
################ CONFIG ###################
username="user"
#HTTP Auth username
password="password"
#HTTP Auth password
basedirname="/directory/to/Sync"
#CA certificate in PEM format
certificate="/directory/to/cert.crt"
#url = Set to the https server running an nginx or apache file listing. Make sure its urlencoded and don't forget trailing slash.
@wernerb
wernerb / sync.sh
Last active September 4, 2023 18:02
Sync folder with Google Drive. Recursively downloads with wget and Google Drive public links. Used to sync ebooks to my eReaders (Kobo). Be warned that public links are dangerous as they could allow someone to download your files. Be sure to use this only in secure environments. This has been tested to be used in POSIX shells as well as in bash.
View sync.sh
#!/bin/sh
#input sharelink here. Example: https://drive.google.com/folderview?id=0B1g-MbiD2F6vdtOT92b3MoerO&usp=sharing
SHARELINK="https://drive.google.com/folderview?id=idU&usp=sharing"
DESTINATION="/full/path/to/folder"
# Change following to false when you don't want to delete files when they are missing from google drive. This can
REMOVEFILES=true
# Begin code
@wernerb
wernerb / keybase.md
Created March 24, 2014 21:29
My keybase.io proof
View keybase.md

Keybase proof

I hereby claim:

  • I am wernerb on github.
  • I am buck (https://keybase.io/buck) on keybase.
  • I have a public key whose fingerprint is 70BB 5523 42D5 3EC8 C22D F4C5 3634 04C4 8767 E6F6

To claim this, I am signing this object:

View gist:9852594
### Keybase proof
I hereby claim:
* I am wernerb on github.
* I am buck (https://keybase.io/buck) on keybase.
* I have a public key whose fingerprint is 82BA F93B ADC2 9352 411B D2D2 2E3F 8B94 6AF1 B74E
To claim this, I am signing this object:
@wernerb
wernerb / async.sh
Created June 29, 2014 21:25
Executes commands asynchronously while keeping stdout/stderr. Does not use tail -f, stops when the command stops. Works in POSIX shells.
View async.sh
############
# Executes commands asynchronously while keeping stdout/stderr.
# If the shell quits or fails then the script can be started again and it
# will read in stdout again from the beginning and continue.
#
# Author: Werner Buck
############
# Command to execute asynchronously.
View jcloudsinit.sh
#!/bin/bash
set +u
shopt -s xpg_echo
shopt -s expand_aliases
unset PATH JAVA_HOME LD_LIBRARY_PATH
function abort {
echo "aborting: $@" 1>&2
exit 1
}
function default {
@wernerb
wernerb / jclouds_posix.sh
Last active August 29, 2015 14:03
This is a POSIX compatible init script for jclouds
View jclouds_posix.sh
#!/bin/sh
export INSTANCE_NAME="test"
export INSTANCE_HOME="/tmp/test"
export LOG_DIR="$INSTANCE_HOME"
forget () {
mkdir -p "$LOG_DIR"
if test ! -f "$LOG_DIR/pid" ; then
nohup "$INSTANCE_HOME/$INSTANCE_NAME.sh" > "$LOG_DIR/stdout.log" 2> "$LOG_DIR/stderr.log" &
echo $! > "$LOG_DIR/pid"
else
@wernerb
wernerb / genssh.scala
Created July 15, 2014 15:46
Generate SSH public keypair from SSH RSA/DSA/EC private key in Scala
View genssh.scala
import java.io.{DataOutputStream, ByteArrayOutputStream, StringReader}
import java.security.interfaces.{ECPublicKey, DSAParams, DSAPublicKey, RSAPublicKey}
import java.security._
import java.security.spec.X509EncodedKeySpec
import org.apache.commons.codec.binary.Base64
import org.bouncycastle.openssl.{PEMKeyPair, PEMParser}
object genPubSSHKey {
/**
View desiredstate.yaml
---
clusters:
#Static website running nginx and displaying the
smallweb:
state:
provider: private
instance-template: small-centos-6.5
nodes: 3
dependencies: []
cluster-groups: []
@wernerb
wernerb / wbuck.zsh-theme
Created December 18, 2014 11:01
Theme for oh-my-zsh.
View wbuck.zsh-theme
# oh-my-zsh w-buck Bureau Theme
### CUSTOM
_COL="red"
_HR="(" #❯
_HL=")" #❮
_LEFT="%{$fg[$_COL]%}$_HR%{$reset_color%}"
_RIGHT="%{$fg[$_COL]%}$_HL%{$reset_color%}"
### NVM