From 11021ce341e39b1f6e72d61b62df0155ea9f1930 Mon Sep 17 00:00:00 2001 From: mid-kid Date: Sat, 19 Dec 2015 22:20:06 +0100 Subject: [PATCH] Say hello to astrohelp, your friendly helper for all your astronautical needs. --- astronaut/astrohelp | 53 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100755 astronaut/astrohelp diff --git a/astronaut/astrohelp b/astronaut/astrohelp new file mode 100755 index 0000000..9cdb8b4 --- /dev/null +++ b/astronaut/astrohelp @@ -0,0 +1,53 @@ +#!/bin/sh -e +# Helper functions for programs that work with satellite files. + +show_help() { +echo "Script with helper functions for working with satellite files. +Usage: $0 [arguments] + +Functions: +variable | Get variable set in the header +downloads | Get all download urls" +} + +if [ $# -lt 2 ]; then + show_help + exit 1 +fi + +satellite="$(realpath "$1")" +function="$2" + +if [ "$function" = "variable" ]; then + name="$3" + if [ ! "$name" ]; then + show_help + exit 1 + fi + + printf ' + header_end() { + variable="$%s" + [ "$variable" ] && echo "$variable" + exit $? + } + . %s + ' "$name" "$satellite" | PATH= /bin/sh 2> /dev/null +elif [ "$function" = "downloads" ]; then + printf ' + download() { + [ "$1" ] && echo "$1" + } + dlextract() { + [ "$1" ] && echo "$1" + } + dlfile() { + [ "$1" ] && echo "$1" + } + header_end() { exit 0; } + . %s + ' "$satellite" | PATH= /bin/sh 2> /dev/null +else + show_help + exit 1 +fi