├── .editorconfig ├── .gitattributes ├── .gitignore ├── Dockerfile ├── config.sh ├── dotfiles ├── .bash_profile ├── .bashrc ├── .shell_aliases ├── .shell_functions └── .shell_variables ├── lib ├── core │ ├── args.sh │ ├── color.sh │ ├── debug.sh │ ├── deps.sh │ ├── error.sh │ ├── examples.sh │ ├── io.sh │ ├── logo.sh │ ├── msg.sh │ └── welcome.sh ├── plugins │ ├── backup.sh │ ├── docker.sh │ └── gui.sh └── templates │ └── _skeleton.sh ├── licence.txt ├── readme.md └── run.sh /.editorconfig: -------------------------------------------------------------------------------- 1 | # Developer: Maik Ellerbrock 2 | # 3 | # GitHub: https://github.com/ellerbrock 4 | # Twitter: https://twitter.com/frapsoft 5 | 6 | root = true 7 | 8 | [*] 9 | charset = utf-8 10 | indent_style = space 11 | indent_size = 2 12 | end_of_line = lf 13 | insert_final_newline = true 14 | trim_trailing_whitespace = true 15 | 16 | [*.{json,yml}] 17 | indent_style = space 18 | indent_size = 2 19 | 20 | [*.md] 21 | insert_final_newline = false 22 | trim_trailing_whitespace = false 23 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Developer: Maik Ellerbrock 2 | # 3 | # GitHub: https://github.com/ellerbrock 4 | # Twitter: https://twitter.com/frapsoft 5 | 6 | * text=auto 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Developer: Maik Ellerbrock 2 | # 3 | # GitHub: https://github.com/ellerbrock 4 | # Twitter: https://twitter.com/frapsoft 5 | 6 | # most settings done via global gitignore settings 7 | 8 | # files 9 | .dockerignore 10 | docs.md 11 | todo.md 12 | 13 | # folders 14 | local 15 | tmp 16 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # Developer: Maik Ellerbrock 2 | # 3 | # GitHub: https://github.com/ellerbrock 4 | # Twitter: https://twitter.com/frapsoft 5 | 6 | FROM alpine:edge 7 | 8 | MAINTAINER Maik Ellerbrock (https://github.com/ellerbrock) 9 | 10 | RUN \ 11 | adduser -h /app -s /bin/bash -u 1000 -D app && \ 12 | apk add --no-cache \ 13 | bash \ 14 | bash-completion \ 15 | bash-doc \ 16 | dialog \ 17 | git && \ 18 | git clone https://github.com/ellerbrock/bash-framework.git /app/bash-framework && \ 19 | sed -i -e "s/bin\/ash/bin\/bash/" /etc/passwd && \ 20 | rm -rf /var/cache/apkc/* 21 | 22 | COPY ./dotfiles /app 23 | COPY ./dotfiles /root 24 | 25 | RUN chown -R app:app /app 26 | 27 | USER app 28 | 29 | WORKDIR /app/bash-framework 30 | 31 | CMD [ "/app/bash-framework/run.sh" ] 32 | -------------------------------------------------------------------------------- /config.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Developer: Maik Ellerbrock 4 | # 5 | # GitHub: https://github.com/ellerbrock 6 | # Twitter: https://twitter.com/frapsoft 7 | 8 | # 9 | # SHELL SETTINGS 10 | # 11 | 12 | declare -r SRC_DIR # defined in run.sh 13 | declare -r SRC_FILE # defined in run.sh 14 | 15 | declare -r CONFIG_LOADED=true 16 | declare -r CONFIG_VERSION="0.0.9" 17 | declare -r CONFIG_DEBUG=false 18 | 19 | # 20 | # FONTS SETTINGS 21 | # 22 | declare -r FONT_ERR="\033[1;40;91m" 23 | declare -r FONT_WARN="\033[1;40;93m" 24 | declare -r FONT_OK="\033[1;40;92m" 25 | declare -r FONT_BOLD="\033[1m" 26 | declare -r FONT_UNDERLINED="\033[4m" 27 | declare -r FONT_DIM="\033[2m" 28 | declare -r FONT_INVERT="\033[7m" 29 | declare -r FONT_BLINK="\033[5m" 30 | declare -r FONT_PINK="\033[95m" 31 | declare -r FONT_CYAN="\033[36m" 32 | declare -r FONT_RESET="\033[0m" 33 | 34 | # 35 | # MESSAGE SETTINGS 36 | # 37 | declare -r PREFIX_ERR="${FONT_ERR} [ ✘ ] " 38 | declare -r PREFIX_WARN="${FONT_WARN} [ ⚡ ] " 39 | declare -r PREFIX_OK="${FONT_OK} [ ✓ ] " 40 | 41 | declare -r PREFIX_HAPPY="${FONT_OK} [ ☺ ]" 42 | declare -r PREFIX_SAD="${FONT_ERR} [ ☹ ]" 43 | 44 | # 45 | # ERROR SETTINGS 46 | # 47 | declare -r ERROR_COLOR_TITLE="\033[1;41;97m" 48 | declare -r ERROR_COLOR_MSG="\033[0;40;93m" 49 | declare -r ERROR_MSG_DEFAULT="GOD DAMN IT - SOMETHING WENT WRONG" 50 | 51 | # 52 | # DIALOG SETTINGS 53 | # 54 | # Auto-size with height and width = 0. Maximize with height and width = -1. 55 | # Global-auto-size if also menu_height/list_height = 0. 56 | declare -r GUI_MSGBOX_HEIGHT=6 57 | declare -r GUI_MSGBOX_WIDTH=50 58 | 59 | # 60 | # BACKUP SETTINGS 61 | # 62 | declare -r BACKUP_ROOT="/Users/${USER}/devops" 63 | declare -r BACKUP_SRC="bash-framework" 64 | declare -r BACKUP_FILE="${BACKUP_SRC}_$(date +%s).tar.bz2" 65 | declare -r BACKUP_TARGET="/Users/${USER}/backup/code/shell/bash-framework" 66 | declare -r BACKUP_EXCLUDE=("./local ./tmp") 67 | -------------------------------------------------------------------------------- /dotfiles/.bash_profile: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Developer: Maik Ellerbrock 4 | # 5 | # GitHub: https://github.com/ellerbrock 6 | # Twitter: https://twitter.com/frapsoft 7 | 8 | source ~/.bashrc 9 | -------------------------------------------------------------------------------- /dotfiles/.bashrc: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Developer: Maik Ellerbrock 4 | # 5 | # GitHub: https://github.com/ellerbrock 6 | # Twitter: https://twitter.com/frapsoft 7 | 8 | source ~/.shell_variables 9 | source ~/.shell_aliases 10 | source ~/.shell_functions 11 | -------------------------------------------------------------------------------- /dotfiles/.shell_aliases: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Developer: Maik Ellerbrock 4 | # 5 | # GitHub: https://github.com/ellerbrock 6 | # Twitter: https://twitter.com/frapsoft 7 | 8 | # overwrite protection 9 | alias mv="mv -i" 10 | alias cp="cp -i" 11 | 12 | # file listing 13 | alias l="ls -alF" 14 | 15 | # folder navigation 16 | alias ..="cd .." 17 | alias ...="cd ../.." 18 | alias ....="cd ../../.." 19 | alias .....="cd ../../../.." 20 | alias ......="cd ../../../../.." 21 | 22 | # directory back 23 | alias 1="cd -" 24 | alias 2="cd -2" 25 | alias 3="cd -3" 26 | alias 4="cd -4" 27 | alias 5="cd -5" 28 | alias 6="cd -6" 29 | alias 7="cd -7" 30 | alias 8="cd -8" 31 | alias 9="cd -9" 32 | 33 | # docker 34 | alias doc="docker" 35 | alias doci="docker images" 36 | alias docc="docker-compose" 37 | alias docm="docker-machine" 38 | 39 | # yarn 40 | alias ya='yarn' 41 | alias yai='yarn init' 42 | alias yaa='yarn add' 43 | alias yaad='yarn add --dev' 44 | alias yau='yarn upgrade' 45 | alias yarm='yarn remove' 46 | alias yaod='yarn outdated' 47 | alias yapa='yarn pack' 48 | alias yap='yarn publish' 49 | alias yasu='yarn self-update' 50 | alias yaru='yarn run' 51 | alias yat='yarn test' 52 | alias yacc='yarn cache clean' 53 | alias yack='yarn check' 54 | alias yals='yarn ls' 55 | alias yai='yarn info' 56 | alias yali='yarn licenses ls' 57 | alias yaloi='yarn login' 58 | alias yaloo='yarn logout' 59 | 60 | # fun 61 | alias sayit="Software is like sex: it's better when it's free - Linus Torvalds" 62 | -------------------------------------------------------------------------------- /dotfiles/.shell_functions: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Developer: Maik Ellerbrock 4 | # 5 | # GitHub: https://github.com/ellerbrock 6 | # Twitter: https://twitter.com/frapsoft 7 | -------------------------------------------------------------------------------- /dotfiles/.shell_variables: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Developer: Maik Ellerbrock 4 | # 5 | # GitHub: https://github.com/ellerbrock 6 | # Twitter: https://twitter.com/frapsoft 7 | 8 | export TERM=xterm-256color 9 | export PS1="\[\033[1;104;33m\] \u \[\033[1;104;91m\]★\[\033[1;104;39m\] \W ➤ \[\033[0m\] " 10 | export CLICOLOR=1 11 | export LSCOLORS=ExFxBxDxCxegedabagacad 12 | -------------------------------------------------------------------------------- /lib/core/args.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Developer: Maik Ellerbrock 4 | # 5 | # GitHub: https://github.com/ellerbrock 6 | # Twitter: https://twitter.com/frapsoft 7 | 8 | [[ ! ${CONFIG_LOADED} ]] && echo "ERROR: PLEASE DON'T RUN DIRETLY (CONFIGURATION REQUIRED)" >&2 && exit 1 9 | 10 | # usage: check_args_len REQUIRED parameter 11 | # 12 | # example: check_args_len 2 ${#} - check inside a function if at least 2 parameter are given 13 | 14 | function check_args_len() { 15 | if [[ ${#} -lt 2 ]]; then 16 | err "missing parameter: usage ${0}" 17 | exit 1 18 | fi 19 | 20 | if [[ ${2} -lt ${1} ]]; then 21 | err "missing parameter(s) (required: ${1} | given: ${2})" 22 | exit 1 23 | fi 24 | 25 | if [[ ${CONFIG_DEBUG} == true ]]; then 26 | echo -e "${PREFIX_OK}${FONT_RESET} PARAMETER: (required: ${1} | given: ${2})" 27 | fi 28 | } 29 | -------------------------------------------------------------------------------- /lib/core/color.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Developer: Maik Ellerbrock 4 | # 5 | # GitHub: https://github.com/ellerbrock 6 | # Twitter: https://twitter.com/frapsoft 7 | 8 | [[ ! ${CONFIG_LOADED} ]] && echo "ERROR: PLEASE DON'T RUN DIRETLY (CONFIGURATION REQUIRED)" >&2 && exit 1 9 | 10 | # optional parameter: [ nice ] 11 | function print_colors() { 12 | for bg in {40..47} {100..107} 49; do 13 | for fg in {30..37} {90..97} 39; do 14 | for x in 0 1 2 4 5 7; do 15 | if [ "${1}" == "nice" ]; then 16 | local val="❤" 17 | else 18 | local val='\\033['"${x};${bg};${fg}m" 19 | fi 20 | echo -en "\033[${x};${bg};${fg}m " ${val} "\033[0m" 21 | done 22 | echo 23 | done 24 | done 25 | 26 | unset fg bg 27 | } 28 | -------------------------------------------------------------------------------- /lib/core/debug.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Developer: Maik Ellerbrock 4 | # 5 | # GitHub: https://github.com/ellerbrock 6 | # Twitter: https://twitter.com/frapsoft 7 | 8 | [[ ! ${CONFIG_LOADED} ]] && echo "ERROR: PLEASE DON'T RUN DIRETLY (CONFIGURATION REQUIRED)" >&2 && exit 1 9 | 10 | # print the shell running this process 11 | function print_shell() { 12 | local DEBUG_SHELL=$(ps -hp $$ | grep -v PID | awk '{ print $4 }') 13 | echo "SHELL: ${DEBUG_SHELL}" 14 | } 15 | 16 | # print arguments (useful for testing / debugging) 17 | function print_args() { 18 | echo -e "\n${FONT_OK}ARGUMENTS OVERVIEW${FONT_RESET}\n" 19 | 20 | echo -e "\t${FONT_OK}\${*}${FONT_RESET}:\t${*}\n" 21 | echo -e "\t${FONT_OK}\${#}${FONT_RESET}:\t${#}\n" 22 | echo -e "\t${FONT_OK}\${$}${FONT_RESET}:\t${$}\n" 23 | echo -e "\t${FONT_OK}\${?}${FONT_RESET}:\t${?}\n" 24 | echo -e "\t${FONT_OK}\${-}${FONT_RESET}:\t${-}\n" 25 | echo -e "\t${FONT_OK}\${$}${FONT_RESET}:\t${$}\n" 26 | echo -e "\t${FONT_OK}\${!}${FONT_RESET}:\t${!}\n" 27 | echo -e "\t${FONT_OK}\${0}${FONT_RESET}:\t${0}\n" 28 | echo -e "\t${FONT_OK}\${_}${FONT_RESET}:\t${_}\n" 29 | 30 | echo -e "${FONT_RESET}\nexecuted as: \"${0} ${*}\" with PID: ${$} as $(whoami)\n" 31 | } 32 | -------------------------------------------------------------------------------- /lib/core/deps.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Developer: Maik Ellerbrock 4 | # 5 | # GitHub: https://github.com/ellerbrock 6 | # Twitter: https://twitter.com/frapsoft 7 | 8 | [[ ! ${CONFIG_LOADED} ]] && echo "ERROR: PLEASE DON'T RUN DIRETLY (CONFIGURATION REQUIRED)" >&2 && exit 1 9 | 10 | function check_deps() { 11 | 12 | check_args_len 2 ${#} 13 | 14 | if [[ "${1}" != "vars" ]] && [[ "${1}" != "apps" ]]; then 15 | err "usage: ${0} type deps" "UNKNOWN PARAMETER \"${1}\"" 16 | exit 1 17 | fi 18 | 19 | for val in "${@:2}"; do 20 | # variables 21 | if [[ "${1}" == "vars" ]]; then 22 | if [[ -z "${!val}" ]]; then 23 | err "variable \"${val}\" is required but not defined" "MISSING REQUIRED VARIABLE \"${val}\"" 24 | exit 1 25 | fi 26 | 27 | if [[ ${CONFIG_DEBUG} == true ]]; then 28 | print_ok "VAR: ${val} is defined" 29 | fi 30 | # applications 31 | else 32 | if ! which "${val}" > /dev/null ; then 33 | err "application \"${val}\" is required but not installed or not in PATH" "MISSING REQUIRED APPLICATION \"${val}\"" 34 | exit 1 35 | fi 36 | 37 | if [[ ${CONFIG_DEBUG} == true ]]; then 38 | print_ok "APP: ${val} found" 39 | fi 40 | fi 41 | done 42 | 43 | 44 | unset val 45 | } 46 | -------------------------------------------------------------------------------- /lib/core/error.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Developer: Maik Ellerbrock 4 | # 5 | # GitHub: https://github.com/ellerbrock 6 | # Twitter: https://twitter.com/frapsoft 7 | 8 | [[ ! ${CONFIG_LOADED} ]] && echo "ERROR: PLEASE DON'T RUN DIRETLY (CONFIGURATION REQUIRED)" >&2 && exit 1 9 | 10 | # Usage: 11 | # 12 | # err "my error message without title" 13 | # err "my error message with a title" "ERROR TITLE" 14 | 15 | function err_title() { 16 | echo -e "${ERROR_COLOR_TITLE} ${1} ${FONT_RESET}" >&2 17 | } 18 | 19 | function err_msg() { 20 | echo -e "${FONT_ERR} ✘ ${1} ${FONT_RESET}" >&2 21 | } 22 | 23 | # error [ message ] [ title ] 24 | function err() { 25 | case ${#} in 26 | 2) 27 | err_title "${2}" 28 | err_msg "${1}" 29 | ;; 30 | 1) 31 | err_msg "${1}" 32 | ;; 33 | *) 34 | err_title "${ERROR_MSG_DEFAULT}" 35 | ;; 36 | esac 37 | } 38 | -------------------------------------------------------------------------------- /lib/core/examples.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Developer: Maik Ellerbrock 4 | # 5 | # GitHub: https://github.com/ellerbrock 6 | # Twitter: https://twitter.com/frapsoft 7 | # Docker: https://hub.docker.com/frapsoft 8 | 9 | [[ ! ${CONFIG_LOADED} ]] && echo "ERROR: PLEASE DON'T RUN DIRETLY (CONFIGURATION REQUIRED)" >&2 && exit 1 10 | 11 | # 12 | # Status Messages 13 | # 14 | function status_message_examples() { 15 | clear 16 | echo -e "${FONT_UNDERLINED}${FONT_BOLD}STATUS MESSAGES${FONT_RESET}:\n" 17 | 18 | print_err "error message" 19 | print_warn "warn message" 20 | print_ok "ok message" 21 | # 22 | # Check Argument Length 23 | # 24 | function i_need_2_args() { 25 | check_args_len 2 ${#} 26 | } 27 | 28 | i_need_2_args arg1 arg2 # all good 29 | # i_need_2_args arg1 # this would exit with error code 1 30 | } 31 | 32 | 33 | # 34 | # Error Messages 35 | # 36 | function error_message_examples() { 37 | echo -e "${FONT_UNDERLINED}${FONT_BOLD}ERROR MESSAGES${FONT_RESET}:\n" 38 | err 39 | echo 40 | err "my error message without title" 41 | echo 42 | err "my error message with a title" "ERROR TITLE" 43 | echo 44 | } 45 | 46 | 47 | # 48 | # GUI Examples 49 | # 50 | function gui_examples() 51 | { 52 | # Message Boxes 53 | gui_msgbox "I am a Message Box with default size" 54 | gui_msgbox "Cool i got an Title" "Awesome Title" 55 | gui_msgbox "Box with custom size settings" "My Title" 10 30 56 | gui_msgbox "Auto-size is possible as well" "My Title" 0 0 57 | 58 | 59 | # yes / no Dialog 60 | function callback() { 61 | check_args_len 1 ${#} 62 | 63 | case ${1} in 64 | 0) gui_msgbox "yes of course you do!" "RESULT: YES";; 65 | 1) gui_msgbox "what the hell? sudo rm -rf / you!" "RESULT: NO";; 66 | 255) gui_msgbox "you canceled with ESC" "RESULT: ESC";; 67 | esac 68 | } 69 | gui_yesno "callback" "Do you like the Bash Framework?" 70 | } 71 | 72 | 73 | # 74 | # Print Color Examples 75 | # 76 | function color_example() { 77 | print_colors nice 78 | } 79 | -------------------------------------------------------------------------------- /lib/core/io.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Developer: Maik Ellerbrock 4 | # 5 | # GitHub: https://github.com/ellerbrock 6 | # Twitter: https://twitter.com/frapsoft 7 | # Docker: https://hub.docker.com/frapsoft 8 | 9 | [[ ! ${CONFIG_LOADED} ]] && echo "ERROR: PLEASE DON'T RUN DIRETLY (CONFIGURATION REQUIRED)" >&2 && exit 1 10 | 11 | # usage: file_exists filename 12 | function file_exists() { 13 | check_args_len 1 ${#} 14 | if [[ -e ${1} ]]; then 15 | if [[ ${CONFIG_DEBUG} == true ]]; then 16 | print_ok "File: \"${1}\" exists" 17 | fi 18 | else 19 | err "File \"${1}\" does not exist!" 20 | exit 1 21 | fi 22 | } 23 | 24 | # usage: file_not_empty filename 25 | function file_not_empty() { 26 | check_args_len 1 ${#} 27 | if [[ -s ${1} ]]; then 28 | if [[ ${CONFIG_DEBUG} == true ]]; then 29 | print_ok "File: \"${1}\" is not empty" 30 | fi 31 | else 32 | err "File \"${1}\" is empty!" 33 | exit 1 34 | fi 35 | } 36 | 37 | # usage: file_is_readable filename 38 | function file_is_readable() { 39 | check_args_len 1 ${#} 40 | if [[ -r ${1} ]]; then 41 | if [[ ${CONFIG_DEBUG} == true ]]; then 42 | print_ok "File: \"${1}\" is readable" 43 | fi 44 | else 45 | err "File \"${1}\" is not readable!" 46 | exit 1 47 | fi 48 | } 49 | 50 | # usage: file_is_writeable filename 51 | function file_is_writeable() { 52 | check_args_len 1 ${#} 53 | if [[ -w ${1} ]]; then 54 | if [[ ${CONFIG_DEBUG} == true ]]; then 55 | print_ok "File: \"${1}\" is writeable" 56 | fi 57 | else 58 | err "File \"${1}\" is not writeable!" 59 | exit 1 60 | fi 61 | } 62 | 63 | # usage: file_is_executeable filename 64 | function file_is_executeable() { 65 | check_args_len 1 ${#} 66 | if [[ -x ${1} ]]; then 67 | if [[ ${CONFIG_DEBUG} == true ]]; then 68 | print_ok "File: \"${1}\" is executeable" 69 | fi 70 | else 71 | err "File \"${1}\" is not executeable!" 72 | exit 1 73 | fi 74 | } 75 | 76 | # usage: file_is_link filename 77 | function file_is_link() { 78 | check_args_len 1 ${#} 79 | if [[ -L ${1} ]]; then 80 | if [[ ${CONFIG_DEBUG} == true ]]; then 81 | print_ok "File: \"${1}\" is a link" 82 | fi 83 | else 84 | err "File \"${1}\" is not a link!" 85 | exit 1 86 | fi 87 | } 88 | 89 | # usage: file_is_newer file1 file2 90 | function file_is_newer() { 91 | check_args_len 2 ${#} 92 | if [[ ${1} -nt ${2} ]]; then 93 | if [[ ${CONFIG_DEBUG} == true ]]; then 94 | print_ok "File: \"${1}\" is newer then \"${2}\"" 95 | fi 96 | else 97 | err "File: \"${1}\" is not newer then \"${2}\"" 98 | exit 1 99 | fi 100 | } 101 | 102 | # usage: file_is_older file1 file2 103 | function file_is_older() { 104 | check_args_len 2 ${#} 105 | if [[ ${1} -ot ${2} ]]; then 106 | if [[ ${CONFIG_DEBUG} == true ]]; then 107 | print_ok "File: \"${1}\" is older then \"${2}\"" 108 | fi 109 | else 110 | err "File: \"${1}\" is not older then \"${2}\"" 111 | exit 1 112 | fi 113 | } 114 | 115 | # usage: dir_exists dirname 116 | function dir_exists() { 117 | check_args_len 1 ${#} 118 | if [[ -d ${1} ]]; then 119 | if [[ ${CONFIG_DEBUG} == true ]]; then 120 | print_ok "Directory: \"${1}\" exists" 121 | fi 122 | else 123 | err "Directory \"${1}\" does not exist!" 124 | exit 1 125 | fi 126 | } 127 | 128 | # usage: get_files callback search 129 | function get_files() { 130 | check_args_len 2 ${#} 131 | 132 | local list 133 | 134 | for f in ${2}; do 135 | if [[ -f ${f} ]]; then 136 | list="${list} ${f}" 137 | fi 138 | done 139 | 140 | if [[ ${CONFIG_DEBUG} == true ]]; then 141 | print_ok "Seach: \"${2}\"" 142 | print_ok "Result: \"${list}\"" 143 | fi 144 | 145 | eval "${1} ${list}" 146 | } 147 | 148 | 149 | #### TODO #### 150 | # 151 | # - replace text replace 152 | # - file rename 153 | # - search and do something with it 154 | # - crypt 155 | # - pack 156 | 157 | 158 | 159 | 160 | 161 | # 162 | # IO Examples 163 | # 164 | 165 | # file_exists tmp/exist.txt 166 | # file_exists tmp/nosuchfile.txt 167 | 168 | # file_not_empty tmp/exist.txt 169 | # file_not_empty tmp/exec.sh 170 | 171 | # file_is_readable tmp/exist.txt 172 | # file_is_readable tmp/nosuchfile.txt 173 | 174 | # file_is_writeable tmp/exist.txt 175 | # file_is_writeable tmp/nosuchfile.txt 176 | 177 | # file_is_executeable tmp/exec.sh 178 | # file_is_executeable tmp/exist.txt 179 | 180 | # file_is_link tmp/link 181 | # file_is_link tmp/exist.txt 182 | 183 | # file_is_newer tmp/exec.sh tmp/exist.txt 184 | # file_is_newer tmp/exist.txt tmp/exec.sh 185 | 186 | # file_is_older tmp/exist.txt tmp/exec.sh 187 | # file_is_older tmp/exec.sh tmp/exist.txt 188 | 189 | # dir_exists tmp 190 | # dir_exists tmpxxx 191 | 192 | # example callback for 193 | # function file_handle() { 194 | # # check_args_len 1 ${#} 195 | # if [[ ${#} -ge 1 ]]; then 196 | # for f in "${@}"; do 197 | # # do here the file handling ... 198 | # # file_is_writeable ${f} 199 | # if [[ ${CONFIG_DEBUG} == true ]]; then 200 | # print_ok "found file: \"${f}\"" 201 | # fi 202 | # done 203 | # else 204 | # if [[ ${CONFIG_DEBUG} == true ]]; then 205 | # print_warn "WARN: no files found for search" 206 | # fi 207 | # fi 208 | # } 209 | # 210 | # # get_files "file_handle" "tmp/*" # return all files from tmp 211 | # get_files "file_handle" "tmp/*" # return all files from tmp 212 | -------------------------------------------------------------------------------- /lib/core/logo.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Developer: Maik Ellerbrock 4 | # 5 | # GitHub: https://github.com/ellerbrock 6 | # Twitter: https://twitter.com/frapsoft 7 | # Docker: https://hub.docker.com/frapsoft 8 | 9 | [[ ! ${CONFIG_LOADED} ]] && echo "ERROR: PLEASE DON'T RUN DIRETLY (CONFIGURATION REQUIRED)" && exit 1 10 | 11 | function print_logo() { 12 | clear 13 | echo -e "\n\n${FONT_ERR} ❤ ❤ ❤ ❤ ❤ ❤ ❤ ❤ ❤ ❤ ❤ ❤ ❤ ❤ ❤ ❤ ❤ ❤${FONT_RESET}\n" 14 | echo ' /$$$$$$$ /$$ /$$ /$$ /$$' 15 | echo ' | $$__ $$ | $$ / $$/ $$ | $$' 16 | echo ' | $$ \ $$ /$$$$$$ /$$$$$$$| $$$$$$$ /$$$$$$$$$$ | $$' 17 | echo ' | $$$$$$$ |____ $$ /$$_____/| $$__ $$ | $$ $$_/ | $$' 18 | echo ' | $$__ $$ /$$$$$$$| $$$$$$ | $$ \ $$ /$$$$$$$$$$ |__/' 19 | echo ' | $$ \ $$ /$$__ $$ \____ $$| $$ | $$ |_ $$ $$_/ ' 20 | echo ' | $$$$$$$/| $$$$$$$ /$$$$$$$/| $$ | $$ | $$| $$ /$$' 21 | echo ' |_______/ \_______/|_______/ |__/ |__/ |__/|__/ |__/' 22 | echo -e "\033[31m" 23 | echo -e "${FONT_ERR} ❤ ❤ ❤ ❤ ❤ ❤ ❤ ❤ ❤ ❤ ❤ ❤ ❤ ❤ ❤ ❤ ❤ ❤" 24 | echo -e "${FONT_RESET}" 25 | echo -e "\t\t\t${FONT_PINK}Welcome ${FONT_CYAN}to the ${FONT_OK}Bash Framework!${FONT_RESET}\n" 26 | echo -e "\t\tA Libary to speed up your Shell Scripting Workflow.\n" 27 | } 28 | -------------------------------------------------------------------------------- /lib/core/msg.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Developer: Maik Ellerbrock 4 | # 5 | # GitHub: https://github.com/ellerbrock 6 | # Twitter: https://twitter.com/frapsoft 7 | 8 | [[ ! ${CONFIG_LOADED} ]] && echo "ERROR: PLEASE DON'T RUN DIRETLY (CONFIGURATION REQUIRED)" && exit 1 9 | 10 | # Usage: 11 | # 12 | # print_err "error message" 13 | # print_warn "warn message" 14 | # print_ok "ok message" 15 | 16 | function print_err() { 17 | check_args_len 1 ${#} 18 | echo -e "${PREFIX_ERR}${FONT_RESET} ${1}" >&2 19 | } 20 | 21 | function print_warn() { 22 | check_args_len 1 ${#} 23 | echo -e "${PREFIX_WARN}${FONT_RESET} ${1}" 24 | } 25 | 26 | function print_ok() { 27 | check_args_len 1 ${#} 28 | echo -e "${PREFIX_OK}${FONT_RESET} ${1}" 29 | } 30 | 31 | function press_a_key() { 32 | echo -e "\n${FONT_WARN}press a key to continue ...${FONT_RESET}" 33 | read -n1 34 | clear 35 | } 36 | -------------------------------------------------------------------------------- /lib/core/welcome.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Developer: Maik Ellerbrock 4 | # 5 | # GitHub: https://github.com/ellerbrock 6 | # Twitter: https://twitter.com/frapsoft 7 | # Docker: https://hub.docker.com/frapsoft 8 | 9 | [[ ! ${CONFIG_LOADED} ]] && echo "ERROR: PLEASE DON'T RUN DIRETLY (CONFIGURATION REQUIRED)" && exit 1 10 | 11 | # 12 | # Examples 13 | # 14 | 15 | print_logo 16 | press_a_key 17 | 18 | status_message_examples 19 | press_a_key 20 | 21 | error_message_examples 22 | press_a_key 23 | 24 | gui_examples 25 | press_a_key 26 | 27 | color_example 28 | echo "... this was the color example :)" 29 | press_a_key 30 | 31 | echo "Thats it for now." 32 | echo "Check on GitHub for new releases!" 33 | echo "https://bash-framework.com" 34 | press_a_key 35 | -------------------------------------------------------------------------------- /lib/plugins/backup.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Developer: Maik Ellerbrock 4 | # 5 | # GitHub: https://github.com/ellerbrock 6 | # Twitter: https://twitter.com/frapsoft 7 | 8 | [[ ! ${CONFIG_LOADED} ]] && echo "ERROR: PLEASE DON'T RUN DIRETLY (CONFIGURATION REQUIRED)" >&2 && exit 1 9 | 10 | DEP_VARS=("BACKUP_ROOT BACKUP_SRC BACKUP_TARGET") 11 | DEP_APPS=("tar bzip2") 12 | 13 | check_deps vars ${DEP_VARS} 14 | check_deps apps ${DEP_APPS} 15 | 16 | unset DEP_VARS DEP_APPS 17 | 18 | function backup() { 19 | local exdirs="" 20 | if [[ -n ${BACKUP_EXCLUDE} ]]; then 21 | for ex in ${BACKUP_EXCLUDE}; do 22 | exdirs+=" --exclude=${ex}" 23 | done 24 | fi 25 | 26 | cd ${BACKUP_ROOT} && \ 27 | tar ${exdirs} -cjf ${BACKUP_TARGET}/${BACKUP_FILE} ${BACKUP_SRC} && \ 28 | print_ok "Backup finished!" 29 | } 30 | -------------------------------------------------------------------------------- /lib/plugins/docker.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Developer: Maik Ellerbrock 4 | # 5 | # GitHub: https://github.com/ellerbrock 6 | # Twitter: https://twitter.com/frapsoft 7 | 8 | [[ ! ${CONFIG_LOADED} ]] && echo "ERROR: PLEASE DON'T RUN DIRETLY (CONFIGURATION REQUIRED)" >&2 && exit 1 9 | 10 | # DEP_VARS=("BACKUP_ROOT BACKUP_SRC BACKUP_TARGET") 11 | DEP_APPS=("docker") 12 | 13 | # check_deps vars ${DEP_VARS} 14 | check_deps apps ${DEP_APPS} 15 | 16 | # nothing here yet :( 17 | -------------------------------------------------------------------------------- /lib/plugins/gui.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Developer: Maik Ellerbrock 4 | # 5 | # GitHub: https://github.com/ellerbrock 6 | # Twitter: https://twitter.com/frapsoft 7 | # Docker: https://hub.docker.com/frapsoft 8 | 9 | [[ ! ${CONFIG_LOADED} ]] && echo "ERROR: PLEASE DON'T RUN DIRETLY (CONFIGURATION REQUIRED)" >&2 && exit 1 10 | 11 | DEP_VARS=("GUI_MSGBOX_HEIGHT GUI_MSGBOX_WIDTH") 12 | DEP_APPS=("dialog") 13 | 14 | check_deps vars ${DEP_VARS} 15 | check_deps apps ${DEP_APPS} 16 | 17 | # usage: gui_msgbox message [title] [height] [width] 18 | function gui_msgbox() { 19 | check_args_len 1 ${#} 20 | 21 | local t="" 22 | local h=${GUI_MSGBOX_HEIGHT} 23 | local w=${GUI_MSGBOX_WIDTH} 24 | 25 | [[ -n ${2} ]] && t="${2}" 26 | [[ -n ${3} ]] && h="${3}" 27 | [[ -n ${4} ]] && w="${4}" 28 | 29 | dialog --title "${t}" --msgbox "${1}" "${h}" "${w}" 30 | } 31 | 32 | 33 | # usage: gui_yesno callback message [title] [height] [width] 34 | function gui_yesno() { 35 | check_args_len 2 ${#} 36 | 37 | local h=${GUI_MSGBOX_HEIGHT} 38 | local w=${GUI_MSGBOX_WIDTH} 39 | 40 | [[ -n ${3} ]] && h="${3}" 41 | [[ -n ${4} ]] && w="${4}" 42 | 43 | dialog --yesno "${2}" "${h}" "${w}" 44 | eval "${1} ${?}" 45 | } 46 | 47 | # 48 | # from here under development ... (coming in the next release) 49 | # 50 | 51 | # # usage: gui_input message [title] [height] [width] 52 | # function gui_input() { 53 | # 54 | # check_args_len 1 ${#} 55 | # 56 | # local t="" 57 | # local h=${GUI_MSGBOX_HEIGHT} 58 | # local w=${GUI_MSGBOX_WIDTH} 59 | # 60 | # [[ -n ${2} ]] && t="${2}" 61 | # [[ -n ${3} ]] && h="${3}" 62 | # [[ -n ${4} ]] && w="${4}" 63 | # 64 | # local res=$(dialog --title ${t} --inputbox "${1}" "${h}" "${w}" 3>&1 1>&2 2>&3 3>&-) 65 | # echo "res:${res}" 66 | # } 67 | # 68 | # # usage: gui_input message [title] [height] [width] 69 | # function gui_menue() { 70 | # # check_args_len 1 ${#} 71 | # # 72 | # # local t="" 73 | # # local h=${GUI_MSGBOX_HEIGHT} 74 | # # local w=${GUI_MSGBOX_WIDTH} 75 | # # 76 | # # [[ -n ${2} ]] && t="${2}" 77 | # # [[ -n ${3} ]] && h="${3}" 78 | # # [[ -n ${4} ]] && w="${4}" 79 | # # 80 | # # local res=$(dialog --title ${t} --inputbox "${1}" "${h}" "${w}" 3>&1 1>&2 2>&3 3>&-) 81 | # # echo "res:${res}" 82 | # 83 | # local res=$(dialog --title "Please select the image" --menu "my menue" 10 45 3 sel1 "selection1" sel2 "selection2" sel3 "selection3" 3>&1 1>&2 2>&3 3>&-) 84 | # echo "res:${res}" 85 | # 86 | # case ${res} in 87 | # sel1) echo "selection1";; 88 | # sel2) echo "selection2";; 89 | # sel3) echo "selection3";; 90 | # esac 91 | # } 92 | -------------------------------------------------------------------------------- /lib/templates/_skeleton.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Developer: Maik Ellerbrock 4 | # 5 | # GitHub: https://github.com/ellerbrock 6 | # Twitter: https://twitter.com/frapsoft 7 | 8 | [[ ! ${CONFIG_LOADED} ]] && echo "ERROR: PLEASE DON'T RUN DIRETLY (CONFIGURATION REQUIRED)" >&2 && exit 1 9 | -------------------------------------------------------------------------------- /licence.txt: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2016 Maik Ellerbrock 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | ![Bash Script Framework](https://github.frapsoft.com/top/bash-framework.png) 2 | 3 | # Bash Script Framework 4 | 5 | _Write faster Shell Scripts with a modern look and feel._ 6 | 7 | [![Bash Shell](https://badges.frapsoft.com/bash/v1/bash.png?v=103)](https://github.com/ellerbrock/open-source-badges/) [![Open Source Love](https://badges.frapsoft.com/os/v1/open-source.svg?v=102)](https://github.com/ellerbrock/open-source-badges/) [![Gitter Chat](https://badges.gitter.im/frapsoft/frapsoft.svg)](https://gitter.im/frapsoft/frapsoft/) 8 | 9 | ![](https://github.frapsoft.com/screenshots/bash-framework-v2.jpg) 10 | 11 | ## Introduction 12 | 13 | **Info:** This is an alpha version under heavy development. 14 | 15 | I wrote the `Bash Script Framework` to get quicker started with Shell Scripting. 16 | 17 | Main Target: `Don't repeat yourself` and stop copy and pasting parts from other scripts to get the job done. 18 | 19 | ## Whats inside? 20 | 21 | - Colorful Messaging with UTF-8 Icons 22 | - Dialogs (Messages, Prompts, Inputs, Menus ...) 23 | - Error Handling 24 | - Dependency Checks for required variables (like configuration settings) 25 | - Run Test if required programs are installed and in PATH 26 | - Test if required argument length is given 27 | 28 | 29 | ### Plugins 30 | 31 | - Backup Plugin 32 | 33 | ## Wanna try it? 34 | 35 | Yeah why don't give it a quick shot even its not really very useful yet. 36 | 37 | `docker pull frapsoft/bash-framework` 38 | 39 | and play with it via: 40 | 41 | `docker run -it frapsoft/bash-framework` 42 | 43 | - 44 | - 45 | 46 | ## Contact / Social Media 47 | 48 | _Get the latest News about Web Development, Open Source, Tooling, Server & Security_ 49 | 50 | [![Github](https://github.frapsoft.com/social/github.png)](https://github.com/ellerbrock/)[![Docker](https://github.frapsoft.com/social/docker.png)](https://hub.docker.com/u/frapsoft/)[![npm](https://github.frapsoft.com/social/npm.png)](https://www.npmjs.com/~ellerbrock)[![Twitter](https://github.frapsoft.com/social/twitter.png)](https://twitter.com/frapsoft/)[![Facebook](https://github.frapsoft.com/social/facebook.png)](https://www.facebook.com/frapsoft/)[![Google+](https://github.frapsoft.com/social/google-plus.png)](https://plus.google.com/116540931335841862774)[![Gitter](https://github.frapsoft.com/social/gitter.png)](https://gitter.im/frapsoft/frapsoft/) 51 | 52 | ### License 53 | 54 | Copyright (c) 2016 [Maik Ellerbrock](https://github.com/ellerbrock/) 55 | 56 | [![MIT Licence](https://badges.frapsoft.com/os/mit/mit-125x28.png?v=102)](https://opensource.org/licenses/mit-license.php) 57 | -------------------------------------------------------------------------------- /run.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Developer: Maik Ellerbrock 4 | # 5 | # GitHub: https://github.com/ellerbrock 6 | # Twitter: https://twitter.com/frapsoft 7 | 8 | # set -u # stop when undeclared variables get consumed 9 | # set -e # stop when exitcode != 0 10 | # set -x # trace (useful for debuggging) 11 | 12 | SRC_DIR=$(dirname "${0}") 13 | SRC_FILE=$(basename "${0}") 14 | 15 | source ${SRC_DIR}/config.sh 16 | 17 | if [[ ! $CONFIG_LOADED ]]; then 18 | echo "ERROR: CAN'T LOAD CONFIGURATION" 19 | exit 1 20 | fi 21 | 22 | source ${SRC_DIR}/lib/core/color.sh 23 | source ${SRC_DIR}/lib/core/error.sh 24 | source ${SRC_DIR}/lib/core/args.sh 25 | source ${SRC_DIR}/lib/core/debug.sh 26 | source ${SRC_DIR}/lib/core/deps.sh 27 | source ${SRC_DIR}/lib/core/msg.sh 28 | source ${SRC_DIR}/lib/core/io.sh 29 | 30 | # 31 | # Plugins 32 | # 33 | # source ${SRC_DIR}/lib/plugins/backup.sh 34 | source ${SRC_DIR}/lib/plugins/gui.sh 35 | 36 | # 37 | # Welcome / show examples 38 | # 39 | source lib/core/examples.sh 40 | source lib/core/logo.sh 41 | source lib/core/welcome.sh 42 | --------------------------------------------------------------------------------