~moody/usrup

c580000fca7a1fbe560f4ea6ca08c96a546ac094 — Jacob Moody 3 years ago
Initial commit
4 files changed, 129 insertions(+), 0 deletions(-)

A LICENSE
A README.md
A example.sh
A usrup.sh
A  => LICENSE +19 -0
@@ 1,19 @@
Copyright (c) 20XX Jacob Moody

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

A  => README.md +33 -0
@@ 1,33 @@
## Usrup

Usrup is a small script for managing you $HOME/src directory.
I find it often that in addition to packages installed with
my package manager I have programs I clone and use that
I would like to keep up to date. The script usrup.sh will do
the following:

* Define some helpful functions
* Change directories in to the parent source dir
* Source a user defined file for defining what repos exist and building them

The actions defined in the user supplied file will run the build commands.
Each build is executed in parallel, when finished the script will print
'done'. It's important to note that Usrup is not a build system for your
project, but rather a system for updating and invoking the different
build systems of various objects.

### Config

The example.sh contains example of some various different repo
configurations. `git_repo_do` and `usrup_do` are defined as the action functions.
There are also utility functions provided as a short hand alias for common
build systems. The comments in `usrup.sh` contain some more detailed information.


### Running

`sh usrup.sh /home/moody/src /home/moody/lib/usrupconfig.sh`

This defines `/home/moody/src` as the parent dir with with the projects
underneeth it and uses `/home/moody/lib/usrupconfig.sh` for defining the build
methods for each project.

A  => example.sh +13 -0
@@ 1,13 @@
#!/bin/sh

# Build a repo called folderName using meson, do not install
git_repo_do folderName meson_build

# Build the repo and install using sudo
git_repo_do folderName meson_build meson_install

#Define custom build instructions for a repo
git_repo_do otherFolder 'SOMEVAR=value make' 'PREFIX=/usr/local sudo make install'

#Always build and install a project using make
usrup_do thirdFolder false make make_install

A  => usrup.sh +64 -0
@@ 1,64 @@
#!/bin/sh

#Check if git repo is currently up to date.
git_up_to_date(){
	git status | grep -q 'up to date'
}

#If git repo is out of date update it,
#if not, bail and return an error.
#Implements update_func for usrup_do.
git_update_if_needed(){
	git fetch
	if git_up_to_date; then
		return 1
	fi
	git pull origin master 2> /dev/null >/dev/null
}

meson_build(){
	meson build
	ninja -C build
}

meson_install(){
	sudo ninja -C build install
}

make_install(){
	sudo make install
}

#usage: usrup_do subdir is_up_to_date_func build_or_install_commands...
usrup_do(){
	prog=$1
	cd "$1"
	shift
	if ! eval "$1"; then
		cd ..
		return 1
	fi
	shift
	for i in $*; do
		if ! eval $i >/dev/null; then
			echo building $prog failed
			cd ..
			return 1
		fi
	done
	cd ..
}

#usage: git_repo_do subdir build_or_install_commands...
git_repo_do(){
	dir=$1
	shift
	usrup_do $dir git_update_if_needed $* &
}

cd $1

. $2

wait
echo done