diff --git a/README.md b/README.md index 9405b51..81629e7 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,7 @@ burrow topic # add or update a topic file burrow create-config # generate a default config file burrow edit-config # open your config file for editing burrow update-git # pull latest git repo for gopher dir, if exists +burrow update-burrow # update git repo or pull latest version from github ``` - `create-config` will auto-generate a configuration file at @@ -71,6 +72,11 @@ by including a `.template` file in your topics directory. - `update-git` will silently attempt to update a git repository at the location of your gopher hole. It is appropriate for use by a cron job. +- `update-burrow` will attempt to pull the latest version of burrow from git if +your local folder is a git repository. If not, it will attempt to update each +file in the burrow directory with the same named file in the master branch of +the git repository for burrow on Github. + _`man burrow` or `burrow -h` for more information._ ## Config diff --git a/burrow b/burrow index b6ea372..57a955e 100755 --- a/burrow +++ b/burrow @@ -1,6 +1,6 @@ #!/usr/bin/env bash -version="v1.2.5" +version="v1.2.6" shopt -s extglob configfiles="$HOME/.config/burrow/config $HOME/.config/burrow $HOME/.burrow" @@ -42,6 +42,7 @@ arg_topic=0 arg_create_config=0 arg_edit_config=0 arg_update_git=0 +arg_update_burrow=0 # silence directory movements pushd () { @@ -63,6 +64,7 @@ COMMANDS: create-config Create a default configuration file edit-config Edit your configuration file update-git Silently pulls gopher git repo if it exists + update-burrow Auto-update this application in its local folder OPTIONAL FLAGS: -h, --help Show this help @@ -130,6 +132,7 @@ function parse_input { "create-config") arg_create_config=1 ;; "edit-config") arg_edit_config=1 ;; "update-git") arg_update_git=1 ;; + "update-burrow") arg_update_burrow=1 ;; *) echo "Unknown command: $arg";; esac done @@ -397,11 +400,43 @@ function update_git { popd } +function update_burrow { + burrow_src="${BASH_SOURCE[0]}" + while [ -h "${burrow_src}" ]; do + burrow_dir="$( cd -P "$( dirname "${burrow_src}" )" && pwd )" + burrow_src="$(readlink "${burrow_src}")" + [[ ${burrow_src} != /* ]] && burrow_src="${burrow_dir}/${burrow_src}" + done + burrow_dir="$( cd -P "$( dirname "${burrow_src}" )" && pwd )" + pushd "${burrow_dir}" + if [[ $(git rev-parse --is-inside-work-tree 2> /dev/null) ]]; then + read -r -p "Do you want to update your burrow git repository? [y/N] " response + if [[ "$response" =~ ^([yY][eE][sS]|[yY])+$ ]] + then + git pull -q + else + die "Aborting." 0 + fi + else + github_src="https://raw.githubusercontent.com/jamestomasino/burrow/master/" + read -r -p "Do you want to fetch the latest burrow executable? [y/N] " response + if [[ "$response" =~ ^([yY][eE][sS]|[yY])+$ ]] + then + for filename in ./burrow*; do + curl -sfLO "${github_src}${filename}" + done + else + die "Aborting." 0 + fi + fi + popd +} + function main { parse_input "$@" if [[ $arg_shortlist -gt 0 ]]; then - out="phlog topic recipe edit-config create-config update-git -v -h -d" + out="phlog topic recipe edit-config create-config update-burrow update-git -v -h -d" # include long options only if using gnu getopt getopt -T > /dev/null if [ $? -eq 4 ]; then @@ -436,6 +471,10 @@ function main { fi done + if [[ ${arg_update_burrow} -gt 0 ]]; then + update_burrow + fi + if [[ ${arg_update_git} -gt 0 ]]; then update_git fi diff --git a/burrow.1 b/burrow.1 index 32cfade..b543727 100644 --- a/burrow.1 +++ b/burrow.1 @@ -1,4 +1,4 @@ -.TH BURROW 1 "06 Mar 2018" "version 1.2.5" +.TH BURROW 1 "06 Mar 2018" "version 1.2.6" .SH NAME burrow \- a helper for building and managing a gopher hole .SH SYNOPSIS @@ -30,6 +30,16 @@ If the gopher directory resides within a git repository, this action will do a silent .B git-pull which is useful for crons. +.TP +.B update-burrow +Burrow will attempt to auto-update. If the local folder where burrow is +installed is a git repository, burrow will pull the latest commit from the +remote branch. If the local directory is not a git remote, burrow will attempt +to update local files with their counterpart on the Github remote repository. +The local directory will only attempt to update files in this way which are +named +.I burrow +or some variation of that name. .SH OPTIONS .TP .B -v, --version