diff options
| author | Mitch Riedstra <mitch@riedstra.us> | 2019-09-12 23:10:58 -0400 |
|---|---|---|
| committer | Mitch Riedstra <mitch@riedstra.us> | 2019-09-12 23:10:58 -0400 |
| commit | 75ed7b4f86cd883f32b88d5613ff46d8a21f6794 (patch) | |
| tree | d38260dd255458b2a02193d4e0e2e0f6fe9f6027 /shell/update | |
| parent | 879d857e0eafa1f716d9e156862154baf49d7655 (diff) | |
| download | dotfiles-75ed7b4f86cd883f32b88d5613ff46d8a21f6794.tar.gz dotfiles-75ed7b4f86cd883f32b88d5613ff46d8a21f6794.tar.xz | |
Split my shell configuration into multiple files and a build script to generate for multiple shells
Diffstat (limited to 'shell/update')
| -rw-r--r-- | shell/update | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/shell/update b/shell/update new file mode 100644 index 0000000..0621f2a --- /dev/null +++ b/shell/update @@ -0,0 +1,117 @@ + +pulltermcolors() { + file="$HOME/bin/terminal-colors" + if ! [ -d $HOME/bin ] ; then + mkdir $HOME/bin + fi + pull -u ${UPDATE_URL}/terminal-colors -f $file + chmod +x $file +} + +pull() { + url="" + file="" + while [ $# -gt 0 ] ; do + case $1 in + -f) + file="$2" + shift; shift; ;; + -u) + url="$2" + shift; shift; ;; + esac + done + CMD="$(which curl wget fetch 2>/dev/null | tail -n1)" + + case $CMD in + *curl) "$CMD" "$url" > "$file" ;; + *wget) "$CMD" "$url" -O "$file" ;; + *fetch) "$CMD" "$url" -o "$file" ;; + esac +} +pulldotfile() { + file="$1" + pull -u "${UPDATE_URL}${file}" -f "$HOME/.${file}" +} +_make_ssh_dir_if_not_exists() { + auth_keys="$HOME/.ssh/authorized_keys" + if ! [ -d $HOME/.ssh ] ; then mkdir $HOME/.ssh ; fi + chmod 700 $HOME/.ssh + chmod 600 $auth_keys +} +_pullkeys() { + url="$1"; shift + _timestamp="$(timestamp)" + _make_ssh_dir_if_not_exists + auth_keys="$HOME/.ssh/authorized_keys" + mv "$auth_keys" "${auth_keys}.${_timestamp}" || \ + echo "Authorized Keys do not currently exist" + pull -u "$url" -f "$auth_keys" || \ + mv "${auth_keys}.${_timestamp}" "$auth_keys" + ssh-keygen -lf "$auth_keys" || \ + mv "${auth_keys}.${_timestamp}" "$auth_keys" + + chmod 600 $auth_keys +} +pullkeys() { + file="keys/$1"; shift; + url="${UPDATE_URL}${file}" + _pullkeys "$url" +} +pullkeys_github() { + _username="$1"; shift; + url="https://github.com/${_username}.keys" + _pullkeys "$url" +} +updatetmuxconf() { + pulldotfile "tmux.conf" + pulldotfile "tmux_helper.sh" + if ! [ -e $HOME/.tmux.conf.local ] && [ `id -u` -eq 0 ] ; then + # If I ever change the color from green this will have to be updated I guess + grep 'green' $HOME/.tmux.conf | sed -e's/green/red/g' > $HOME/.tmux.conf.local + elif ! [ -e $HOME/.tmux.conf.local ] ; then + touch $HOME/.tmux.conf.local + fi +} +updategitconf() { + file="gitconfig/$1" + pull -u "${UPDATE_URL}${file}" -f "$HOME/.gitconfig" +} +updateshell() { + pulldotfile "mkshrc" + . $HOME/.mkshrc +} +updatevimrc() { + OLDWD="$(pwd)" + cd $HOME + git clone $VIM_GIT_URL .vim + if [ $? -gt 0 ] ; then + cd $HOME/.vim + git pull origin master + else + cd $HOME/.vim + fi + ./setup.sh && \ + ./link-vimrc.sh + cd $OLDWD +} +updatevimrc_basic() { + pull -u "$VIM_BASIC_URL" -f ~/.vimrc +} +placebasicvimrc() { + if [ -z "$1" ] ; then + echo All arguments are passed to SSH, but you need at least one + return + fi + _TMP="$(mktemp)" + if [ -z "$_TMP" ] ; then + echo Cannot continue, temp file cannot be zero length!; + return + fi + pull -u "$VIM_BASIC_URL" -f "$_TMP" + cat "$_TMP" | ssh "$@" "cat - > ~/.vimrc" + rm "$_TMP" +} + + + |
