Skip to content
Snippets Groups Projects
Commit 39ae37c8 authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

Merge branch 'support-windows' into 'master'

Draft: ignore required user on MS windows

See merge request !95
parents d46061c8 78a31080
No related branches found
No related tags found
1 merge request!95ignore required user on MS windows
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
```
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
# helper script to share functions for parsing and handlinmg backup jobs # 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> # ds - Daniel Schueler <daniel.schueler@iml.unibe.ch>
# #
# 2016-11-10 ah,ds v1.0 # 2016-11-10 ah,ds v1.0
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
# 2017-02-16 ah,ds v1.2 added storage helper function # 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 # 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" # 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" ...@@ -41,6 +42,11 @@ STORAGEFILE="${DIR_JOBS}/transfer.job"
function j_init(){ function j_init(){
j_banner 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 if [ ! -d "${DIR_LOGS}" ]; then
mkdir -p "${DIR_LOGS}" && echo "INFO: dir created ${DIR_LOGS}" mkdir -p "${DIR_LOGS}" && echo "INFO: dir created ${DIR_LOGS}"
...@@ -373,16 +379,28 @@ function j_requireProcess(){ ...@@ -373,16 +379,28 @@ function j_requireProcess(){
fi 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 # 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 # param string username, i.e. root
# ------------------------------------------------------------ # ------------------------------------------------------------
function j_requireUser(){ function j_requireUser(){
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 ")") sUser=$(id | cut -f 2 -d "(" | cut -f 1 -d ")")
if [[ "$sUser" != "$1" ]]; then if [[ "$sUser" != "$1" ]]; then
>&2 echo "ERROR: user $1 is reqired." >&2 echo "ERROR: user $1 is reqired."
exit 5 exit 5
fi fi
fi
} }
# ---------------------------------------------------------------------- # ----------------------------------------------------------------------
......
#!/bin/bash
# ----------------------------------------------------------------------
# set custom variables eg. extend PATH
# ----------------------------------------------------------------------
# PATH=/c/portable/restic/:$PATH
# ----------------------------------------------------------------------
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment