#!/bin/bash die () { echo "error: $@" >&2 exit 128 } pattern='^[0-9a-zA-Z]{11}$' if [ "$1" == "-h" -o "$1" == "--help" ]; then echo "so-fetch - fetch code from so-db repository" echo echo "Usage:" echo " so-fetch" exit 0 fi ssh_opts= for i in ~/.ssh/so-db.key ~/so-db.key ~/linux/so-db.key /usr/local/etc/so-db.key; do if [ -r "$i" ]; then ssh_opts="$ssh_opts -i $i" fi done if [ -z "$ssh_opts" ]; then echo "so-db.key SSH private key is missing." >&2 echo "Download the so-db.key from PZE and place in linux directory" >&2 exit 128 fi id=$(git config so.id) if [[ "$id" =~ $pattern ]]; then : else read -p "Password: " id if ! [[ "$id" =~ $pattern ]]; then die "invalid password" fi git config so.id "$id" fi echo "FETCH $id" | ssh -o BatchMode=yes -T \ $ssh_opts \ so-db@so.podlesie.net \ | ( read HEAD git unpack-objects git reset --hard "$HEAD" )