dot dot dotfiles
at main 65 lines 1.7 kB view raw
1#!/bin/bash 2read -p "User name for 'https://github.com': " UNAME 3read -s -p "Password -- NOT PAT! -- for 'https://$UNAME@github.com' " PASS 4echo "" 5 6# encryption: 7GITTOK="aaagit.txt" 8openssl des3 -salt -md sha256 -pbkdf2 -d \ 9 -in <path/to/encrypted/file> -out "$GITTOK" -pass pass:$PASS 10 11PASS="" 12PAT=$(cat "$GITTOK") 13rm "$GITTOK" 14 15# get git remote address: 16if [ "$1" == "" ]; then 17 BRANCH=$(git branch --show-current) 18else 19 BRANCH=$1 20fi 21 22REMOTE=$(git remote -v | head -n 1) 23# REMOTE="origin https://github.com/<org>/<repo> (fetch)" (or similar) 24 25# function to cut string by delimiter 26cut () { 27 local s=$REMOTE$1 28 while [[ $s ]]; do 29 array+=( "${s%%"$1"*}" ); 30 s=${s#*"$1"}; 31 done; 32} 33# cut terminal bit "(fetch)" from remote, returning first part as array[0]: 34array=(); 35cut " " 36REMOTE="${array[0]}" 37 38# cut remainder around "github.com", returning 2nd part as "/<org>/<repo>" 39array=(); 40cut "github.com" 41 42# convert REMOTE given above to 43# REMOTE="https://<UNAME>:<PAT>@github.com/<org>/<repo>" (or similar) 44printf -v REMOTE "https://%s:%s@github.com%s" "$UNAME" "$PAT" "${array[1]}" 45#echo $REMOTE $BRANCH 46 47git push $REMOTE $BRANCH 48# need to git pull for some reason in order to properly reset head to remote 49git pull &>/dev/null 50# clear variables: 51PAT="" 52REMOTE="" 53 54# repeat push for other remotes 55if [[ "$BRANCH" == "main" ]]; then 56 git remote -v | while read -r name url type; do 57 # only "push"" remotes to avoid duplicates, and also exclude origin = github 58 if [[ "$type" == "(push)" ]] && [[ "$name" != "origin" ]]; then 59 echo "" 60 echo -n "--------Pushing to $name- " 61 git push "$url" 62 fi 63done 64fi 65echo ""