dep

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

commit cff1c2388e9e914a2089abf4a29d47e9d26cb1eb
parent 26f47d8df0d9939ffb5f379ade882446faf63c94
Author: finwo <finwo@pm.me>
Date:   Wed, 25 Jan 2023 18:25:22 +0100

Project restart: basic composing of executable

Diffstat:
A.github/FUNDING.yml | 3+++
M.gitignore | 8++++----
MCODE_OF_CONDUCT.md | 1+
MLICENSE | 2+-
AMakefile | 29+++++++++++++++++++++++++++++
DREADME.md | 82-------------------------------------------------------------------------------
Dbuild.sh | 17-----------------
Ddist/dep | 294-------------------------------------------------------------------------------
Ddist/dep-repo | 90-------------------------------------------------------------------------------
Dinstall.sh | 51---------------------------------------------------
Apackage.ini | 12++++++++++++
Dsrc/dep | 275-------------------------------------------------------------------------------
Dsrc/dep-repo | 90-------------------------------------------------------------------------------
Asrc/ini.sh | 76++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dsrc/logo.txt | 4----
Asrc/main.sh | 17+++++++++++++++++
Asrc/shopt.sh | 7+++++++
17 files changed, 150 insertions(+), 908 deletions(-)

diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml @@ -0,0 +1,3 @@ +# f4d2ed80-57b6-46e6-b245-5049428a931d +github: finwo +liberapay: finwo diff --git a/.gitignore b/.gitignore @@ -1,4 +1,4 @@ -/.dep -/lib -*.swp -bashpp +/bak/ +/bashpp +/util/ +/dep diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md @@ -1,3 +1,4 @@ +<!-- 46b43825-f791-485e-9445-415ee7bbbf2d --> # Contributor Code of Conduct This project adheres to No Code of Conduct. We are all adults. We accept anyone's contributions. Nothing else matters. diff --git a/LICENSE b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2019 finwo +Copyright (c) 2023 finwo 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 diff --git a/Makefile b/Makefile @@ -0,0 +1,29 @@ +SRC=$(wildcard src/*.sh) + +# Idea: +# include lib/.dep/libraries.mk + +default: main + +bashpp: + curl https://raw.githubusercontent.com/iwonbigbro/bashpp/master/bin/bashpp > bashpp + chmod +x bashpp + +util/ini.sh: src/ini.sh src/shopt.sh + mkdir -p util + echo '#!/usr/bin/env bash' > $@ + ./bashpp -I src -v src/ini.sh | tee -a $@ > /dev/null + chmod +x $@ + +.PHONY: main +main: $(SRC) bashpp util/ini.sh + @$(eval NAME=$(shell util/ini.sh package.ini package.name)) + echo '#!/usr/bin/env bash' > "$(NAME)" + ./bashpp -D __NAME=$(NAME) -I src -v src/main.sh | tee -a "$(NAME)" > /dev/null + chmod +x "$(NAME)" + +.PHONY: clean +clean: + @$(eval NAME=$(shell util/ini.sh package.ini package.name)) + rm -f $(NAME) + rm -rf util/ini.sh diff --git a/README.md b/README.md @@ -1,82 +0,0 @@ -# DEP - -general-purpose project dependency manager - ---- - -## Installation - -To install dep onto your machine, first verify the `/usr/local/bin` folder is in your `$PATH` variable. - -After that, run the following command as root to install the dep scripts onto your machine: - -```bash -curl https://raw.githubusercontent.com/cdeps/dep/master/install.sh | bash -``` - ---- - -## Usage - -### Initialize a project with DEP - -```bash -dep init -``` - -Go into the repository you want to initialize and run `dep init`. This will create the file `.dep` which contains all that is needed for dep to work with. - -### Add a dependency - -```bash -dep add <package-name> -``` - -### Install dependencies - -```bash -dep install -``` - -You can also install a single package without adding it to the dependencies by running `dep install <package-name>` - -### Remove a dependency - -This is not implemented yet - -### Update packages from repositories - -```bash -dep repo update -``` - -### Show which repositories are used - -```bash -dep repo list -``` - -### Add a repository - -```bash -dep repo add <url> -``` - -### Clean repository cache - -```bash -dep repo clean -``` - -## TODO - -- Add remove-dep tool -- Make the source nicer to read -- Better documentation -- Pick a proper name -- Focus on C instead of general purpose? - -## Contribute - -TODO: No Code of Conduct -TODO: patreon page diff --git a/build.sh b/build.sh @@ -1,17 +0,0 @@ -#!/usr/bin/env bash - -# Load pre-processor -[ -f bashpp ] || { - curl https://raw.githubusercontent.com/iwonbigbro/bashpp/master/bin/bashpp > bashpp - chmod +x bashpp -} - -# Refresh dist dir -rm -rf dist -mkdir dist - -# Build outputs -./bashpp src/dep > dist/dep -./bashpp src/dep-repo > dist/dep-repo -chmod +x dist/dep -chmod +x dist/dep-repo diff --git a/dist/dep b/dist/dep @@ -1,294 +0,0 @@ -#!/usr/bin/env bash - -# Useful function -# 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 - echo "Config file ($1) is unclean, cleaning it..." >&2 - # filter the original to a new file - mv $1 $1.bak - egrep '^#|^[^ ]*=[^;&]*' "$1.bak" > "$1" - 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 ~/.dep ] || mkdir -p ~/.dep -[ -d ~/.dep/cache ] || mkdir -p ~/.dep/cache -[ -f ~/.dep/config ] || touch ~/.dep/config -[ -f ~/.dep/repositories ] || { - echo "https://github.com/cdeps/dep-repository/archive/master.tar.gz" > ~/.dep/repositories -} - -# Load the user's configuration -clean_conf ~/.dep/config -source ~/.dep/config - -# Let's see what to do -case "$1" in - - init) - - # Sanity check - if [ -f .dep ]; then - echo "Project already initialized." >&2 - echo "Remove the .dep 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\"" > .dep - echo "NAME=\"$projectname\"" >> .dep - echo "DEPS=()" >> .dep - - # 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 .dep ] || { - 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 .dep - - # Verify the fiven package name - [ -n "$2" ] || { - echo "No package name given." >&2 - exit 1 - } - - # Check if the given package is known - [ -d ~/.dep/packages/$2 ] || { - echo "Package not found" >&2 - exit 1 - } - - # No further checks yet, add it to the list - echo "DEPS+=(\"$2\")" >> .dep - ;; - install) - - # Verify the project is initialized - [ -f .dep ] || { - 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 .dep - - # If no arguments were given, install all - [ -n "$2" ] || { - - # Clear file-building steps - rm -rf lib/.dep - mkdir -p lib/.dep - - # Load config - source .dep - - # Prepare build files - if [ -d build ]; then - for file in $(find build -type f -regex '.*/[0-9][0-9]*-.*' | sort); do - outname=$(basename $file) - echo "Adding $file to $outname" - cat $file >> lib/.dep/$outname - done - fi - - # Install dependencies - for dependency in "${DEPS[@]}"; do - $0 $1 $dependency || { - echo "Installing dependencies failed" >&2 - echo "Error thrown during '$dependency' or one of it's dependencies" >&2 - exit 1 - } - done - - # Delete directed buildfiles - for file in $(find lib/.dep -type f -regex '.*/[0-9][0-9]*-.*' | sort); do - outname=$(basename $file | cut -c 4-) - rm -f $outname - done - - # Write directed buildfiles - for file in $(find lib/.dep -type f -regex '.*/[0-9][0-9]*-.*' | sort); do - outname=$(basename $file | cut -c 4-) - echo "Writing $file to $outname" - cat $file >> $outname - done - - exit 0 - } - - # Notify we're working on this dependency - echo "Installing: $2" - echo " Verifying package" - - # Make sure we know the dependency - [ -d ~/.dep/packages/$2 ] || { - echo " Package not found" >&2 - exit 1 - } - - # Check the config exists - [ -f ~/.dep/packages/$2/config ] || { - echo " Package does not contain a config" >&2 - exit 1 - } - - # Load the package config - clean_conf ~/.dep/packages/$2/config - source ~/.dep/packages/$2/config - - # Verify tarball is set - [ -n "$tarball" ] || { - echo " Tarball is not configured for this package" >&2 - exit 1 - } - - # Verify the sha256 is set - [ -n "$sha256" ] || { - echo " Sha256 checksum for this package is not configured" >&2 - exit 1 - } - - # Don't DDoS github, check the cache first - cachefile=$(echo ~/.dep/cache/$2) - if [ -f $cachefile ]; then - echo " Cache detected" - SUM=$(sha256sum -b $cachefile | cut -d " " -f 1) - [[ "$sha256" == "$SUM" ]] || { - echo " Checksum did not match, updating cache" - curl -fL# "$tarball" > $cachefile - [ $? -eq 0 ] || { - echo " Could not fetch tarball" >&2 - exit 1 - } - } - else - echo " Cache not available, downloading" - mkdir -p $(dirname $cachefile) - curl -fL# "$tarball" > $cachefile - [ $? -eq 0 ] || { - echo " Could not fetch tarball" >&2 - exit 1 - } - fi - - # Verify checksum - SUM=$(sha256sum -b $cachefile | cut -d " " -f 1) - [[ "$sha256" == "$SUM" ]] || { - echo " Checksum did not match" >&2 - exit 1 - } - - # Extract to the lib folder - orgdir=$(pwd) - mkdir -p lib/$2 - cd lib/$2 - tar --strip-components=1 -xzf $cachefile - cd $orgdir - - # Process the library's dependencies if needed - if [ -f lib/$2/.dep ]; then - clean_conf lib/$2/.dep - source lib/$2/.dep - for dependency in "${DEPS[@]}"; do - $0 $1 $dependency exit 1 - done - fi - - # Process included build-files - for file in $(find ~/.dep/packages/$2 -type f -regex '.*/[0-9][0-9]*-.*' | sort); do - outname=$(basename $file) - echo " Adding $file to $outname" - cat $file >> lib/.dep/$outname - done - ;; - license) - cat <<EOF -The MIT License (MIT) - -Copyright (c) 2019 finwo - -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. -EOF - ;; - - help) - echo "Usage: $0 command" - echo "" - echo "Commands:" - echo " help Show this help info" - echo " repo [help] Repository management" - echo " init Initialize the current directory as a dep project" - echo " add <package> Add a dependency" - echo " install [package] Install a package or all project dependencies" - echo "" - ;; - - *) - # Check for user-defined - if command -v $0-$1 &>/dev/null; then - $0-$1 "${@:2}" - else - $0 help - exit 1 - fi - ;; -esac diff --git a/dist/dep-repo b/dist/dep-repo @@ -1,90 +0,0 @@ -#!/usr/bin/env bash - -# Make sure the required stuff exists -[ -d ~/.dep ] || mkdir -p ~/.dep -[ -f ~/.dep/repositories ] || { - echo "https://github.com/cdeps/dep-repository/archive/master.tar.gz" > ~/.dep/repositories -} - -# Regex for validating URLs -# https://stackoverflow.com/a/3184819 -urlcheck='^(https?|ftp|file)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]$' - -case "$1" in - help) - echo "Usage: $0 command" - echo "" - echo "Commands:" - echo " help Show this help info" - echo " list List all repositories in use" - echo " add <url> Add a repository" - echo " clean Remove dependency cache" - echo " update Update dependency cache" - echo "" - ;; - - list) - cat ~/.dep/repositories - ;; - - add) - - # The user must give a url we're using - if [[ -z "$2" ]]; then - echo "No repository url given" >&2 - exit 1 - fi - - # The url must be valid - [[ "$2" =~ $urlcheck ]] || { - echo "Given url is not valid" >&2 - exit 1 - } - - # Save, further checks haven't been written - echo "$2" >> ~/.dep/repositories - echo "The following URL was added: $2" - ;; - - clean) - - # Remove all packages - rm -rf ~/.dep/packages && { - echo "All packages have been removed" - echo "Please run '$0 update' to fetch up-to-date versions" - } || { - echo "Unable to remove all packages" >&2 - echo "Please check the permissions for ~/.dep/packages" >&2 - exit 1 - } - - ;; - - update) - - # Make sure the extraction folder exists - [ -d ~/.dep/packages ] || { - mkdir -p ~/.dep/packages - } - - # Simply download all package references - cd ~/.dep/packages - for i in $(cat ~/.dep/repositories); do - curl -fL# "$i" | tar --strip-components=1 -xzf - - done - - ;; - remove) - - # Notify this is a todo - echo "This call is not implemented yet" >&2 - echo "To remove a repository, please manually edit the following file:" >&2 - echo " ~/.dep/repositories" >&2 - exit 1 - - ;; - *) - echo "Usage: $0 (list|add|clean|update|remove)" - exit 1 - ;; -esac diff --git a/install.sh b/install.sh @@ -1,51 +0,0 @@ -#!/usr/bin/env bash - -# # Verify root privileges -# if [[ $EUID -ne 0 ]]; then -# echo "This script must be run as root" >&2 -# exit 1 -# fi - -# Print banner -cat <<EOF - ,_, DEP - )v( - \_/ general-purpose - =="== dependency manager - -EOF - -# Default settings -PREFIX=/usr/local - -# Parse arguments -while [ "$#" -gt 0 ]; do - case "$1" in - --prefix) - shift - PREFIX="$1" - ;; - esac - shift -done - -# Install repo binary -function bin { - [ -f "./$1" ] && { - echo "Copying $1" - cp "./$1" "$PREFIX/bin/$1" - } || curl -L# "https://raw.githubusercontent.com/cdeps/dep/master/dist/$1" > "$PREFIX/bin/$1" - chmod +x "$PREFIX/bin/$1" -} - -# Ensure our dependencies -command -v curl &>/dev/null || { - echo "cUrl needs to be installed to use dep" -} - -# Default install directory -mkdir -p "$PREFIX/bin" - -# Install our binaries -bin dep -bin dep-repo diff --git a/package.ini b/package.ini @@ -0,0 +1,12 @@ +[package] +name=dep +deps=lib + +src=http://tarball + +[dependencies] +bashpp=https://github.com/iwonbigbro/bashpp/archive/refs/heads/master.tar.gz + +# TEST + +; test diff --git a/src/dep b/src/dep @@ -1,275 +0,0 @@ -#!/usr/bin/env bash - -# Useful function -# 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 - echo "Config file ($1) is unclean, cleaning it..." >&2 - # filter the original to a new file - mv $1 $1.bak - egrep '^#|^[^ ]*=[^;&]*' "$1.bak" > "$1" - 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 ~/.dep ] || mkdir -p ~/.dep -[ -d ~/.dep/cache ] || mkdir -p ~/.dep/cache -[ -f ~/.dep/config ] || touch ~/.dep/config -[ -f ~/.dep/repositories ] || { - echo "https://github.com/cdeps/dep-repository/archive/master.tar.gz" > ~/.dep/repositories -} - -# Load the user's configuration -clean_conf ~/.dep/config -source ~/.dep/config - -# Let's see what to do -case "$1" in - - init) - - # Sanity check - if [ -f .dep ]; then - echo "Project already initialized." >&2 - echo "Remove the .dep 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\"" > .dep - echo "NAME=\"$projectname\"" >> .dep - echo "DEPS=()" >> .dep - - # 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 .dep ] || { - 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 .dep - - # Verify the fiven package name - [ -n "$2" ] || { - echo "No package name given." >&2 - exit 1 - } - - # Check if the given package is known - [ -d ~/.dep/packages/$2 ] || { - echo "Package not found" >&2 - exit 1 - } - - # No further checks yet, add it to the list - echo "DEPS+=(\"$2\")" >> .dep - ;; - install) - - # Verify the project is initialized - [ -f .dep ] || { - 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 .dep - - # If no arguments were given, install all - [ -n "$2" ] || { - - # Clear file-building steps - rm -rf lib/.dep - mkdir -p lib/.dep - - # Load config - source .dep - - # Prepare build files - if [ -d build ]; then - for file in $(find build -type f -regex '.*/[0-9][0-9]*-.*' | sort); do - outname=$(basename $file) - echo "Adding $file to $outname" - cat $file >> lib/.dep/$outname - done - fi - - # Install dependencies - for dependency in "${DEPS[@]}"; do - $0 $1 $dependency || { - echo "Installing dependencies failed" >&2 - echo "Error thrown during '$dependency' or one of it's dependencies" >&2 - exit 1 - } - done - - # Delete directed buildfiles - for file in $(find lib/.dep -type f -regex '.*/[0-9][0-9]*-.*' | sort); do - outname=$(basename $file | cut -c 4-) - rm -f $outname - done - - # Write directed buildfiles - for file in $(find lib/.dep -type f -regex '.*/[0-9][0-9]*-.*' | sort); do - outname=$(basename $file | cut -c 4-) - echo "Writing $file to $outname" - cat $file >> $outname - done - - exit 0 - } - - # Notify we're working on this dependency - echo "Installing: $2" - echo " Verifying package" - - # Make sure we know the dependency - [ -d ~/.dep/packages/$2 ] || { - echo " Package not found" >&2 - exit 1 - } - - # Check the config exists - [ -f ~/.dep/packages/$2/config ] || { - echo " Package does not contain a config" >&2 - exit 1 - } - - # Load the package config - clean_conf ~/.dep/packages/$2/config - source ~/.dep/packages/$2/config - - # Verify tarball is set - [ -n "$tarball" ] || { - echo " Tarball is not configured for this package" >&2 - exit 1 - } - - # Verify the sha256 is set - [ -n "$sha256" ] || { - echo " Sha256 checksum for this package is not configured" >&2 - exit 1 - } - - # Don't DDoS github, check the cache first - cachefile=$(echo ~/.dep/cache/$2) - if [ -f $cachefile ]; then - echo " Cache detected" - SUM=$(sha256sum -b $cachefile | cut -d " " -f 1) - [[ "$sha256" == "$SUM" ]] || { - echo " Checksum did not match, updating cache" - curl -fL# "$tarball" > $cachefile - [ $? -eq 0 ] || { - echo " Could not fetch tarball" >&2 - exit 1 - } - } - else - echo " Cache not available, downloading" - mkdir -p $(dirname $cachefile) - curl -fL# "$tarball" > $cachefile - [ $? -eq 0 ] || { - echo " Could not fetch tarball" >&2 - exit 1 - } - fi - - # Verify checksum - SUM=$(sha256sum -b $cachefile | cut -d " " -f 1) - [[ "$sha256" == "$SUM" ]] || { - echo " Checksum did not match" >&2 - exit 1 - } - - # Extract to the lib folder - orgdir=$(pwd) - mkdir -p lib/$2 - cd lib/$2 - tar --strip-components=1 -xzf $cachefile - cd $orgdir - - # Process the library's dependencies if needed - if [ -f lib/$2/.dep ]; then - clean_conf lib/$2/.dep - source lib/$2/.dep - for dependency in "${DEPS[@]}"; do - $0 $1 $dependency exit 1 - done - fi - - # Process included build-files - for file in $(find ~/.dep/packages/$2 -type f -regex '.*/[0-9][0-9]*-.*' | sort); do - outname=$(basename $file) - echo " Adding $file to $outname" - cat $file >> lib/.dep/$outname - done - ;; - license) - cat <<EOF -#include "../LICENSE" -EOF - ;; - - help) - echo "Usage: $0 command" - echo "" - echo "Commands:" - echo " help Show this help info" - echo " repo [help] Repository management" - echo " init Initialize the current directory as a dep project" - echo " add <package> Add a dependency" - echo " install [package] Install a package or all project dependencies" - echo "" - ;; - - *) - # Check for user-defined - if command -v $0-$1 &>/dev/null; then - $0-$1 "${@:2}" - else - $0 help - exit 1 - fi - ;; -esac diff --git a/src/dep-repo b/src/dep-repo @@ -1,90 +0,0 @@ -#!/usr/bin/env bash - -# Make sure the required stuff exists -[ -d ~/.dep ] || mkdir -p ~/.dep -[ -f ~/.dep/repositories ] || { - echo "https://github.com/cdeps/dep-repository/archive/master.tar.gz" > ~/.dep/repositories -} - -# Regex for validating URLs -# https://stackoverflow.com/a/3184819 -urlcheck='^(https?|ftp|file)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]$' - -case "$1" in - help) - echo "Usage: $0 command" - echo "" - echo "Commands:" - echo " help Show this help info" - echo " list List all repositories in use" - echo " add <url> Add a repository" - echo " clean Remove dependency cache" - echo " update Update dependency cache" - echo "" - ;; - - list) - cat ~/.dep/repositories - ;; - - add) - - # The user must give a url we're using - if [[ -z "$2" ]]; then - echo "No repository url given" >&2 - exit 1 - fi - - # The url must be valid - [[ "$2" =~ $urlcheck ]] || { - echo "Given url is not valid" >&2 - exit 1 - } - - # Save, further checks haven't been written - echo "$2" >> ~/.dep/repositories - echo "The following URL was added: $2" - ;; - - clean) - - # Remove all packages - rm -rf ~/.dep/packages && { - echo "All packages have been removed" - echo "Please run '$0 update' to fetch up-to-date versions" - } || { - echo "Unable to remove all packages" >&2 - echo "Please check the permissions for ~/.dep/packages" >&2 - exit 1 - } - - ;; - - update) - - # Make sure the extraction folder exists - [ -d ~/.dep/packages ] || { - mkdir -p ~/.dep/packages - } - - # Simply download all package references - cd ~/.dep/packages - for i in $(cat ~/.dep/repositories); do - curl -fL# "$i" | tar --strip-components=1 -xzf - - done - - ;; - remove) - - # Notify this is a todo - echo "This call is not implemented yet" >&2 - echo "To remove a repository, please manually edit the following file:" >&2 - echo " ~/.dep/repositories" >&2 - exit 1 - - ;; - *) - echo "Usage: $0 (list|add|clean|update|remove)" - exit 1 - ;; -esac diff --git a/src/ini.sh b/src/ini.sh @@ -0,0 +1,76 @@ +#include "shopt.sh" + +# Arguments: +# $0 <fn_keyHandler> <str_filename> [section[.key]] +function ini_foreach { + + # No file = no data + inifile="${2}" + if [[ ! -f "$inifile" ]]; then + exit 1 + fi + + # Process the file line-by-line + SECTION= + while read line; do + + # Remove surrounding whitespace + line=${line##*( )} # From the beginning + line=${line%%*( )} # From the end + + # Remove comments and empty lines + if [[ "${line:0:1}" == '#' ]] || [[ "${line:0:1}" == ';' ]] || [[ "${#line}" == 0 ]]; then + continue + fi + + # Handle section markers + if [[ "${line:0:1}" == "[" ]]; then + SECTION=$(echo $line | sed -e 's/\[\(.*\)\]/\1/') + SECTION=${SECTION##*( )} + SECTION=${SECTION%%*( )} + SECTION="${SECTION}." + continue + fi + + # Output found variable + NAME=${line%%=*} + NAME=${NAME%%*( )} + VALUE=${line#*=} + VALUE=${VALUE##*( )} + + # Output searched or all + if [[ -z "${3}" ]]; then + $1 "$SECTION" "$NAME" "${VALUE}" + elif [[ "${SECTION}" == "${3}." ]] || [[ "${SECTION}${NAME}" == "${3}" ]]; then + $1 "$SECTION" "$NAME" "${VALUE}" + fi + + done < "${inifile}" + +} + +function ini_output_full { + echo "$1$2=$3" +} +function ini_output_section { + echo "$2=$3" +} +function ini_output_value { + echo "$3" +} + +# Allow this file to be called stand-alone +# ini.sh <filename> [section[.key]] [sectionmode] +if [ $(basename $0) == "ini.sh" ]; then + fullMode=full + sectionMode=value + if [[ ! -z "${3}" ]]; then + fullMode=${3} + sectionMode=${3} + fi + if [[ -z "${2}" ]]; then + ini_foreach ini_output_${fullMode} "$@" + else + ini_foreach ini_output_${sectionMode} "$@" + fi +fi diff --git a/src/logo.txt b/src/logo.txt @@ -1,4 +0,0 @@ - ,_, - )v( - \_/ - =="== diff --git a/src/main.sh b/src/main.sh @@ -0,0 +1,17 @@ +#include "ini.sh" + +# Filled by bashpp +NAME=__NAME + +function main { + + # Commands: + # install + + + echo "Hello World" +} + +if [ $(basename $0) == "${NAME}" ]; then + main +fi diff --git a/src/shopt.sh b/src/shopt.sh @@ -0,0 +1,7 @@ +#ifndef __SHOPT_SH__ +#define __SHOPT_SH__ + +# Required for the whitespace trimming +shopt -s extglob + +#endif __SHOPT_SH__