#!/bin/bash pattern='^[0-9a-zA-Z]{11}$' gen_id () { local id="" for ((i = 0; i < 100; i++)); do id=$(dd if=/dev/urandom bs=8 count=1 status=none \ | base64 | sed 's/=$//') if [[ "$id" =~ $pattern ]]; then break; fi done echo "$id" } if [ "$1" == "-h" -o "$1" == "--help" ]; then echo "so-push - push code to so-db repository" echo echo "Usage:" echo " so-push" 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 id=$(gen_id) git config so.id "$id" fi echo "Password: $id" >&2 ( echo "PUSH $id" git rev-parse HEAD echo "origin/km/so-2021.." | git pack-objects --revs --stdout) \ | ssh -o BatchMode=yes -T \ $ssh_opts \ so-db@so.podlesie.net