Joey Armstrong | 7c3a1e0 | 2023-07-01 16:21:24 -0400 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # ----------------------------------------------------------------------- |
Joey Armstrong | 6f63edf | 2024-01-12 11:30:08 -0500 | [diff] [blame] | 3 | # Copyright 2023-2024 Open Networking Foundation (ONF) and the ONF Contributors |
Joey Armstrong | 7c3a1e0 | 2023-07-01 16:21:24 -0400 | [diff] [blame] | 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | # ----------------------------------------------------------------------- |
| 17 | |
| 18 | ##-------------------## |
| 19 | ##---] GLOBALS [---## |
| 20 | ##-------------------## |
| 21 | set -euo pipefail |
| 22 | |
| 23 | umask 022 |
| 24 | |
| 25 | ## ----------------------------------------------------------------------- |
| 26 | ## Intent: Display an error mesage then exit with shell exit status |
| 27 | ## ----------------------------------------------------------------------- |
| 28 | function error() |
| 29 | { |
| 30 | local iam="${BASH_SOURCE[0]}::${FUNCNAME[1]}" |
| 31 | echo "$iam: ERROR: $*" |
| 32 | exit 1 |
| 33 | } |
| 34 | |
| 35 | ## ----------------------------------------------------------------------- |
| 36 | ## Intent: Display a message labeled for the running script |
| 37 | ## ----------------------------------------------------------------------- |
| 38 | function func_echo() |
| 39 | { |
| 40 | local iam="${BASH_SOURCE[0]}::${FUNCNAME[1]}" |
| 41 | echo "$iam: $*" |
| 42 | return |
| 43 | } |
| 44 | |
| 45 | ## ----------------------------------------------------------------------- |
| 46 | ## Intent: Display a message labeled for the running script |
| 47 | ## ----------------------------------------------------------------------- |
| 48 | function usage() |
| 49 | { |
| 50 | [[ $# -gt 0 ]] && echo "$*" |
| 51 | |
| 52 | func_echo "USAGE: $0 [args] dir[, .. dir]" |
| 53 | cat <<EOH |
| 54 | Create a directory structure required for Dockerfile use. |
| 55 | --debug Enable debug mode |
| 56 | --help This message |
| 57 | EOH |
| 58 | |
| 59 | return |
| 60 | } |
| 61 | |
| 62 | ##----------------## |
| 63 | ##---] MAIN [---## |
| 64 | ##----------------## |
| 65 | func_echo "HELLO" |
| 66 | |
| 67 | declare -a dirs=() |
| 68 | while [[ $# -gt 0 ]]; do |
| 69 | arg="$1"; shift |
| 70 | case "$arg" in |
| 71 | -*debug) set -x ;; |
| 72 | -*help) usage ;; |
| 73 | -*) error "Detected unknown switch [$arg]" ;; |
| 74 | *) dirs+=("$arg") ;; |
| 75 | esac |
| 76 | done |
| 77 | |
| 78 | [[ ${#dirs[@]} -eq 0 ]] && { |
| 79 | usage "At least one directory is required" |
| 80 | exit 1; |
| 81 | } |
| 82 | |
| 83 | for dir in "${dirs[@]}"; |
| 84 | do |
| 85 | active="$dir/active" |
| 86 | mkdir -p "$dir" |
| 87 | touch "$active" |
| 88 | done |
| 89 | |
| 90 | # find "${dirs[@]}" -ls |
| 91 | |
| 92 | # [EOF] |