From 33cc4ff3a0b460b40b88f3ea707032fc50448f8a Mon Sep 17 00:00:00 2001 From: Karl G Date: Mon, 28 Aug 2017 12:11:09 +0200 Subject: [PATCH] fixing various issues with dbench - Added missing shebang - Fixed malformed multi line variables - Removed unnecessary su (which is not working in this way anyway) - Added missing error handling (unsupported options as well as missing argument) - Simplified the whole script (without the removal of features, hopefully?) --- dbench | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/dbench b/dbench index d85e1728..74ee8784 100755 --- a/dbench +++ b/dbench @@ -1,27 +1,33 @@ -usage="$(basename "$0") [-h] [-c ""] +#!/usr/bin/env bash -where: - -h show this help text - -c execute a command inside docker using docker exec" +display_usage() { + echo "$(basename "$0") [-h] [-c \"\"]" + echo '' + echo 'where:' + echo ' -h show this help text' + echo ' -c execute a command inside docker using docker exec' +} if [[ $# -eq 0 ]]; then - temp="docker exec -it frappe bash" - $temp + docker exec -it frappe bash else while getopts ':hc:' option; do - echo $option case "$option" in - h) echo "$usage" + h) + display_usage exit ;; - c) seed=$OPTARG - temp="docker exec frappe bash -c 'su frappe -c \"bench $OPTARG\"; exec \"${SHELL:-sh}\"'" - exec="true" + c) + docker exec frappe bash -c "bench $OPTARG" ;; + \?) + echo "Invalid option: -$OPTARG" >&2 + exit 1 + ;; + :) + echo "Option -$OPTARG requires an argument." >&2 + exit 1 + ;; esac done - if [[ "$exec" == "true" ]]; then - $temp - fi - shift $((OPTIND - 1)) fi