Created
November 13, 2017 14:18
-
-
Save sebthemonster/1c0213335414dcb62c1fb74c59280f3d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#================================================================ | |
# HEADER | |
#================================================================ | |
#% SYNOPSIS | |
#+ ${SCRIPT_NAME} [-hv] [-o[file]] args ... | |
#% | |
#% DESCRIPTION | |
#% This is a script template | |
#% to start any good shell script. | |
#% | |
#% OPTIONS | |
#% -h, --help Print this help | |
#% -v, --version Print script information | |
#% | |
#% EXAMPLES | |
#% ${SCRIPT_NAME} -o DEFAULT arg1 arg2 | |
#% | |
#================================================================ | |
#- IMPLEMENTATION | |
#- version ${SCRIPT_NAME} x.y.z | |
#- author Author Name | |
#- copyright Copyright (c) | |
#- license WTFPL (http://www.wtfpl.net/about/) | |
#- script_id 1234 | |
#- | |
#================================================================ | |
# HISTORY | |
# 2015/03/01 : author : Script creation | |
# 2015/04/01 : author : Add long options and improvements | |
# | |
#================================================================ | |
# DEBUG OPTION | |
# set -n # Uncomment to check your syntax, without execution. | |
# set -x # Uncomment to debug this shell script | |
# | |
#================================================================ | |
# END_OF_HEADER | |
#================================================================ | |
#== usage functions ==# | |
usage() { printf "Usage: "; scriptinfo usg ; } | |
usagefull() { scriptinfo ful ; } | |
scriptinfo() { headFilter="^#-" | |
[ "$1" = "usg" ] && headFilter="^#+" | |
[ "$1" = "ful" ] && headFilter="^#[%+]" | |
[ "$1" = "ver" ] && headFilter="^#-" | |
head -${SCRIPT_HEADSIZE:-99} ${0} | grep -e "${headFilter}" | sed -e "s/${headFilter}//g" -e "s/\${SCRIPT_NAME}/${SCRIPT_NAME}/g" | |
} | |
# usage() { printf "Usage: "; head -${SCRIPT_HEADSIZE:-99} ${0} | grep -e "^#+" | sed -e "s/^#+[ ]*//g" -e "s/\${SCRIPT_NAME}/${SCRIPT_NAME}/g" ; } | |
# usagefull() { head -${SCRIPT_HEADSIZE:-99} ${0} | grep -e "^#[%+-]" | sed -e "s/^#[%+-]//g" -e "s/\${SCRIPT_NAME}/${SCRIPT_NAME}/g" ; } | |
# scriptinfo() { head -${SCRIPT_HEADSIZE:-99} ${0} | grep -e "^#-" | sed -e "s/^#-//g" -e "s/\${SCRIPT_NAME}/${SCRIPT_NAME}/g"; } | |
#== needed variables ==# | |
SCRIPT_HEADSIZE=$(head -200 ${0} |grep -n "^# END_OF_HEADER" | cut -f1 -d:) | |
SCRIPT_NAME="$(basename ${0})" | |
SCRIPT_ID="$(scriptinfo | grep script_id | tr -s ' ' | cut -d' ' -f3)" | |
SCRIPT_NAME="$(basename ${0})" # scriptname without path | |
SCRIPT_UNIQ="${SCRIPT_NAME%.*}.${SCRIPT_ID}.${HOSTNAME%%.*}" | |
SCRIPT_UNIQ_DATED="${SCRIPT_UNIQ}.$(date "+%y%m%d%H%M%S").${$}" | |
SCRIPT_DIR="$( cd $(dirname "$0") && pwd )" # script directory | |
SCRIPT_DIR_TEMP="/tmp" # Make sure temporary folder is RW | |
#== set options ==# | |
SCRIPT_OPTS='hv' | |
SCRIPT_LONG_OPTS='help,version' | |
#== Read the options ==# | |
TEMP=`getopt -o $SCRIPT_OPTS --long $SCRIPT_LONG_OPTS \ | |
-n $SCRIPT_NAME -- "$@"` | |
eval set -- "$TEMP" | |
# Process the options with getopt parsing | |
while true; do | |
case "$1" in | |
-h | --help) usagefull; exit 0;; | |
-v | --version) scriptinfo; exit 0;; | |
-- ) shift; break ;; | |
* ) break ;; | |
esac | |
done | |
#============================ | |
# MAIN SCRIPT | |
#============================ | |
echo 'your script is here' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment