cfgfoo

git clone https://orangeshoelaces.net/git/cfgfoo.git

/cfgfoo

   1 #!/bin/sh
   2 
   3 # cfgfoo
   4 # Copyright 2018, 2019 Vasilii Kolobkov
   5 # 
   6 # This program is free software: you can redistribute it and/or modify
   7 # it under the terms of the GNU General Public License as published by
   8 # the Free Software Foundation, either version 3 of the License, or
   9 # (at your option) any later version. 
  10 #
  11 # This program is distributed in the hope that it will be useful,
  12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14 # GNU General Public License for more details.
  15 #
  16 # You should have received a copy of the GNU General Public License
  17 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
  18 
  19 if [ "$#" -eq 0 ]; then
  20         printf "cfgfoo: Can't do without step file.\n"
  21         exit 1
  22 fi
  23 __step="$1"
  24 shift
  25 if [ ! -f "$__step" ]; then
  26         printf "cfgfoo: Step file '%s' doesn't exist.\n" "$__step"
  27         exit 1
  28 fi
  29 
  30 if [ "$#" -gt 0 -a "$1" = -s ]; then
  31         __stayput=y
  32         shift
  33 fi
  34 
  35 file_exists() {
  36         if [ ! -f "$1" ]; then
  37                 printf "Can't find '%s'.\n" "$1"
  38                 return 1
  39         fi
  40 }
  41 
  42 (
  43         printf "cfgfoo: Step '%s" "${__step}"
  44         [ "$#" -gt 0 ] && printf " %s'.\n" "$*" || printf "'.\n"
  45 
  46         if [ -n "${__stayput+y}" ]; then
  47                 . "$__step"
  48         else
  49                 cd "$(dirname "$__step")"
  50                 . "./$(basename "$__step")"
  51         fi
  52 
  53         (set -e; step_taken "$@")
  54         if [ "$?" -eq 0 ]; then
  55                 printf 'cfgfoo: Has already been taken. Skipping.\n'
  56                 exit
  57         fi
  58 
  59         (set -e; take_step "$@")
  60         res="$?"
  61         if [ "$res" -ne 0 ]; then
  62                 printf "cfgfoo: Failed with exit status %d.\n" "$res"
  63                 exit 1
  64         fi
  65 )