dep

Package manager for embedded C libraries
git clone git://git.finwo.net/app/dep
Log | Files | Refs | README | LICENSE

commit 18a0610263276cfb99da1debcfbdbc7a6226444e
parent f6db5b42393b24000f32d5a6e9af0dc2a8edf75f
Author: finwo <finwo@pm.me>
Date:   Mon, 13 Nov 2017 22:40:08 +0100

Add and Init function

Diffstat:
A.gitignore | 1+
Mdep | 77+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 76 insertions(+), 2 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -0,0 +1 @@ +/.dependencies diff --git a/dep b/dep @@ -1,7 +1,7 @@ #!/usr/bin/env bash # Useful function -# See http://wiki.bash-hackers.org/howto/conffile +# http://wiki.bash-hackers.org/howto/conffile clean_conf () { # check if the file contains something we don't want if egrep -q -v '^#|^[^ ]*=[^;]*' "$1"; then @@ -12,6 +12,15 @@ clean_conf () { fi } +# Useful function thanks to "patrik" +# https://stackoverflow.com/a/8574392 +containsElement () { + local e match="$1" + shift + for e; do [[ "$e" == "$match" ]] && return 0; done + return 1 +} + # Make sure the required stuff exists [ -d ~/.cdeps ] || mkdir -p ~/.cdeps [ -f ~/.cdeps/config ] || touch ~/.cdeps/config @@ -21,11 +30,75 @@ clean_conf () { clean_conf ~/.cdeps/config source ~/.cdeps/config +# Let's see what to do case "$1" in + init) - + + # Sanity check + if [ -f .dependencies ]; then + echo "Project already initialized." >&2 + echo "Remove the .dependencies file if you want to start over." >&2 + exit 1 + fi + + # Fetch the author name + fullname=$(getent passwd $(whoami) | cut -d ':' -f 5 | cut -d ',' -f 1 ) + echo -n "Author [$fullname]: " + read author + [ -n "$author" ] || { + author=$fullname + } + + # Fetch the project name + defaultname=$(basename $(pwd)) + echo -n "Project name [$defaultname]:" + read projectname + [ -n "$projectname" ] || { + projectname=$defaultname + } + + # Write to file + echo "AUTHOR=$author" > .dependencies + echo "NAME=$projectname" >> .dependencies + echo "DEPS=()" >> .dependencies + + # Check for git compliance + if [ -d .git ]; then + read -r -p "Add /lib to .gitignore? [y/N] " response + response=${response,,} + if [[ "$response" =~ ^(yes|y)$ ]]; then + echo "/lib" >> .gitignore + fi + fi + ;; + add) + + # Verify the project is initialized + [ -f .dependencies ] || { + echo "The current folder isn't a project root." >&2 + echo "Initialize it by running '$0 init'." >&2 + exit 1 + } + + # Clean config if needed + clean_conf .dependencies + + # Verify the fiven package name + [ -n "$2" ] || { + echo "No package name given." >&2 + exit 1 + } + + # Check if the given package is known + [ -f "~/.cdeps/packages/$2" ] || { + echo "Package not found" >&2 + exit 1 + } + + echo "DEPS+=(\"$2\")" >> .dependencies ;; install) ;;