Created
June 7, 2012 11:56
-
-
Save Gen2ly/2888412 to your computer and use it in GitHub Desktop.
Create a github gist repository for sharing scripts/configs on blog
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Create a github gist repository for sharing scripts/configs on blog | |
# Base directory, repository parent directory | |
base_dir=""$HOME"/" | |
repo_par=""$HOME"/.github-gist/" | |
# File list (File list order must match repository order) | |
files=('/home/todd/.scripts/others/ghsync-script' | |
'/home/todd/.scripts/vault/unity-effects' | |
'/home/todd/.scripts/pwr' | |
'/home/todd/.bashrc' | |
'/home/todd/.scripts/ripcd' | |
'/home/todd/.scripts/normalize-audio' | |
'/home/todd/.scripts/template' | |
'/home/todd/.scripts/template-basic' | |
'/home/todd/.scripts/others/vim2html' | |
'/home/todd/.scripts/bugfixes/externalmonitor' | |
'/home/todd/.config/autostart/externalmonitor.desktop' | |
'/etc/pm/sleep.d/90_externalmonitor' | |
'/home/todd/.scripts/sitepass-ls' | |
'/home/todd/.scripts/sitepass-gn' | |
'/home/todd/.scripts/sitepass-cb' | |
'/home/todd/.scripts/bugfixes/touchpad-button-fix' | |
'/home/todd/.scripts/rm' | |
'/home/todd/.scripts/others/mp3cat-mdir' | |
'/home/todd/.scripts/others/g9led-random-color' | |
'/home/todd/.config/autostart/g9led-random-color.desktop' | |
'/etc/pm/sleep.d/95_g9led-random-color' | |
'/home/todd/.scripts/calc' | |
'/home/todd/.scripts/others/atget' | |
'/home/todd/.scripts/rps' | |
'/home/todd/.scripts/others/cmtstrip' | |
'/home/todd/.scripts/others/grok' | |
'/home/todd/.scripts/unpack' | |
'/home/todd/.scripts/pack' | |
'/home/todd/.scripts/others/ff-restore' | |
'/home/todd/.scripts/root/purge-memory' | |
'/home/todd/.scripts/bgcmd' | |
'/home/todd/.scripts/cb-in' | |
'/home/todd/.scripts/cb-out' | |
'/home/todd/.scripts/others/ghsync-gist' | |
'/home/todd/.scripts/root/arch/mp' | |
'/home/todd/.scripts/root/arch/pacpull' | |
'/home/todd/.Arachnophilia/ArachConf/Arach.ini' | |
'/home/todd/.Arachnophilia/Macros/Macros.xml' | |
'/home/todd/.scripts/others/md2wp' | |
'/home/todd/.scripts/pspvidconv' | |
'/home/todd/.scripts/others/devtop' | |
'/home/todd/.scripts/others/memtop' | |
'/home/todd/.local/share/applications/cvlc.desktop' | |
'/home/todd/.scripts/screencast' | |
'/home/todd/.scripts/root/backup/bcksysc' | |
'/home/todd/.q3a/q3ut4/autoexec.cfg' | |
'/home/todd/.scripts/gpuswitch') | |
# Repositories (repo_address) | |
repos=('[email protected]:2839879.git' | |
'[email protected]:2840553.git' | |
'[email protected]:2843630.git' | |
'[email protected]:2844190.git' | |
'[email protected]:2844265.git' | |
'[email protected]:2844272.git' | |
'[email protected]:2844305.git' | |
'[email protected]:2844306.git' | |
'[email protected]:2844801.git' | |
'[email protected]:2844866.git' | |
'[email protected]:2844966.git' | |
'[email protected]:3066195.git' | |
'[email protected]:2844933.git' | |
'[email protected]:2844934.git' | |
'[email protected]:2844935.git' | |
'[email protected]:2844992.git' | |
'[email protected]:2845277.git' | |
'[email protected]:2848140.git' | |
'[email protected]:2848180.git' | |
'[email protected]:2848197.git' | |
'[email protected]:2848198.git' | |
'[email protected]:2851690.git' | |
'[email protected]:2851829.git' | |
'[email protected]:2853010.git' | |
'[email protected]:2853011.git' | |
'[email protected]:2858162.git' | |
'[email protected]:2861045.git' | |
'[email protected]:2861046.git' | |
'[email protected]:2867295.git' | |
'[email protected]:2884577.git' | |
'[email protected]:2886277.git' | |
'[email protected]:2888206.git' | |
'[email protected]:2888207.git' | |
'[email protected]:2888412.git' | |
'[email protected]:2974884.git' | |
'[email protected]:3019486.git' | |
'[email protected]:3050300.git' | |
'[email protected]:3050307.git' | |
'[email protected]:3079785.git' | |
'[email protected]:3123937.git' | |
'[email protected]:3242049.git' | |
'[email protected]:3242078.git' | |
'[email protected]:3398845.git' | |
'[email protected]:3441383.git' | |
'[email protected]:3558352.git' | |
'[email protected]:3628294.git' | |
'[email protected]:3706273.git') | |
# Required program(s) | |
req_progs=(jist) | |
for p in ${req_progs[@]}; do | |
hash "$p" 2>&- || \ | |
{ echo >&2 " Required program \"$p\" not installed."; exit 1; } | |
done | |
addfilechk () { | |
for file in "$@"; do | |
[ ! -f "$file" ] && echo " "$file" doesn't exist" && exit | |
done | |
} | |
extfilechk () { | |
for file in "${files[@]}"; do | |
[ ! -f "$file" ] && echo " "$file" doesn't exist" && exit | |
done | |
} | |
help () | |
{ | |
echo " ${0##*/} <option> <*file> - Add or update gist repo(s) | |
a - Add gist repo for file(s) | |
u - Update all gist repos for all files" | |
} | |
# Options | |
case $1 in | |
a ) # Upload new files to github gist | |
shift | |
addfilechk | |
for file in "$@"; do | |
if [ -z "${file##*.}" ]; then | |
# Upload file (cut second line to use as description); print output | |
url_address="$(jist -p -d "$(sed -n '2p' "$file" | sed 's/^# //')" -f "$file".sh "$file")" | |
else | |
url_address="$(jist -p -d "$(sed -n '2p' "$file" | sed 's/^# //')" "$file")" | |
fi | |
echo " ---" | |
echo " filenm path: "$(readlink -f "$file")"" | |
echo " git address: $(echo "$url_address" | sed -e 's|https://|git@|' -e 's|.com/\(.*\)|.com:\1.git|')" | |
echo " url address: "$url_address"" | |
done | |
echo " ---" | |
echo " Enter filemame path and gist number in script to enable updating them." | |
echo " ---" ;; | |
u ) # Create parent directory for local repos; rm prev. b4 cp'ing new files | |
cd | |
extfilechk | |
[ -d "$repo_par" ] && rm -rf "$repo_par" | |
mkdir -p "$repo_par" | |
# Create local repository directories, cp files | |
for file in "${files[@]}"; do | |
# Create parent directory for files | |
cd "$repo_par" || exit | |
# Create local repo dir. per file (each gist will needs its own repo) | |
repo_dir="$(basename "$file")" | |
[ ! -d "$repo_dir" ] && mkdir "$repo_dir" | |
cd "$repo_dir" | |
# Copy file | |
cp -a "$file" . | |
done | |
# Update gist files | |
n=${#files[@]} # number of elements in array (needed to sync two arrays) | |
for (( i=0; i<n; i++ )); do | |
cd "$repo_par" || exit | |
repo_dir="$(basename "${files[$i]}")" | |
cd "$repo_dir" | |
# Initialize local repository; define remote repo; add file to git | |
git init | |
repo_name="${repo_dir#.*}" # repos names cannot start with a . | |
git remote add "$repo_name" "${repos[$i]}" | |
git add . 2> /dev/null | |
# Record changes to all files, rm those not in index, add commit msg | |
git commit -a -m "Weekly update" || exit | |
# Sync local repository to github gist repository | |
git push --force "$repo_name" master && \ | |
echo " Synced local repository ""${repos[$i]}"" to gist repository" | |
done ;; | |
* ) help ;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment