diff --git a/docs/30_Configuration/60_File_env.md b/docs/30_Configuration/60_File_env.md new file mode 100644 index 0000000000000000000000000000000000000000..715afa64d0c30f61eb232462a3d9fb4d46e4cfd5 --- /dev/null +++ b/docs/30_Configuration/60_File_env.md @@ -0,0 +1,12 @@ +If a file `env` exists in the folder `./jobs/` it will be sourced by the backup scripts. +Here you can set custom environment variables. + +A common usage is extending the variable PATH to execute binaries that are not located in any directory. + +Example: + +This might be helpful on MS Windows. If you put the restic binary "somewhere" eg. c:\portable\restic\restic.exe then you can add the path to the env file: + +```bash +PATH=/c/portable/restic/:$PATH +``` diff --git a/jobhelper.sh b/jobhelper.sh index 51062390c0b845217f10b75f2775d01d3465e85e..a05467c41ce184ecbda651a202ac9ac1dd527b6d 100755 --- a/jobhelper.sh +++ b/jobhelper.sh @@ -5,7 +5,7 @@ # helper script to share functions for parsing and handlinmg backup jobs # # -------------------------------------------------------------------------------- -# ah - Axel Hahn <axel.hahn@iml.unibe.ch> +# ah - Axel Hahn <axel.hahn@unibe.ch> # ds - Daniel Schueler <daniel.schueler@iml.unibe.ch> # # 2016-11-10 ah,ds v1.0 @@ -13,6 +13,7 @@ # 2017-02-16 ah,ds v1.2 added storage helper function # 2018-02-13 ah,ds v1.3 detect samba shares based on a flag # 2022-10-07 ah v1.4 unescape regex with space to prevent "grep: warning: stray \ before white space" +# 2023-03-16 ah v1.5 ignore required user on MS windows; source jobs/env if it exists # ================================================================================ @@ -41,6 +42,11 @@ STORAGEFILE="${DIR_JOBS}/transfer.job" function j_init(){ j_banner + if [ -r "${DIR_JOBS}/env" ]; + then + echo "INFO: loading custom environment ${DIR_JOBS}/env" + . "${DIR_JOBS}/env" + fi if [ ! -d "${DIR_LOGS}" ]; then mkdir -p "${DIR_LOGS}" && echo "INFO: dir created ${DIR_LOGS}" @@ -373,15 +379,27 @@ function j_requireProcess(){ fi } +# detect ms windows by cygwin, mingw, msys ... +# see https://en.wikipedia.org/wiki/Uname +# return code is 0 for YES +function _isMswindows(){ + uname | grep -iE "(CYGWIN_NT|MINGW|MSYS_NT|Windows_NT|WindowsNT)" >/dev/null +} + # ------------------------------------------------------------ # check if it was startet with a given user +# This is skipped if MS windows was detected with "mingw". # param string username, i.e. root # ------------------------------------------------------------ function j_requireUser(){ - sUser=$(id | cut -f 2 -d "(" | cut -f 1 -d ")") - if [[ "$sUser" != "$1" ]]; then - >&2 echo "ERROR: user $1 is reqired." - exit 5 + if _isMswindows; then + echo "SKIP: j_requireUser $1 is not handled on MS Windows." + else + sUser=$(id | cut -f 2 -d "(" | cut -f 1 -d ")") + if [[ "$sUser" != "$1" ]]; then + >&2 echo "ERROR: user $1 is reqired." + exit 5 + fi fi } diff --git a/jobs/env.dist b/jobs/env.dist new file mode 100644 index 0000000000000000000000000000000000000000..4537e778c77d3fd488dde9f419afc0c6e80ebc41 --- /dev/null +++ b/jobs/env.dist @@ -0,0 +1,8 @@ +#!/bin/bash +# ---------------------------------------------------------------------- +# set custom variables eg. extend PATH +# ---------------------------------------------------------------------- + +# PATH=/c/portable/restic/:$PATH + +# ----------------------------------------------------------------------