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

Merge branch 'support-windows' into 'master'

Support windows

See merge request !96
parents 39ae37c8 d145fc86
No related branches found
No related tags found
1 merge request!96Support windows
......@@ -2,6 +2,7 @@
# ignored configs
# ----------------------------------------------------------------------
jobs/*.job
jobs/env
keys/*
logs/auto-*
logs/full-*
......
......@@ -13,7 +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
# 2023-03-17 ah v1.5 ignore required user on MS windows; source jobs/env if it exists; use varaiable FQDN
# ================================================================================
......@@ -48,6 +48,8 @@ function j_init(){
. "${DIR_JOBS}/env"
fi
_getFqdn
if [ ! -d "${DIR_LOGS}" ]; then
mkdir -p "${DIR_LOGS}" && echo "INFO: dir created ${DIR_LOGS}"
fi
......@@ -150,7 +152,7 @@ function j_getFullTarget(){
sTmpSafeName=$(j_getSafename "$1")
sTmpHostname=$2
if [ -z "$sTmpHostname" ]; then
sTmpHostname=$(hostname -f)
sTmpHostname=$FQDN
fi
if [ -z "${STORAGE_BASEDIR}" ]; then
STORAGE_BASEDIR=$(_j_getvar "${STORAGEFILE}" "storage")
......@@ -386,6 +388,34 @@ function _isMswindows(){
uname | grep -iE "(CYGWIN_NT|MINGW|MSYS_NT|Windows_NT|WindowsNT)" >/dev/null
}
# get fqdn and put it into FQDN; called in j_init
# - with gnu core utils: hostname -f
# - on ms windows: grep from output of ipconfig and %COMPUTERNAME%
function _getFqdn(){
if [ -z "$FQDN" ]; then
if ! FQDN=$( hostname -f 2>/dev/null ); then
echo "INFO: hostname -f is not available"
if _isMswindows; then
if [ -n "$COMPUTERNAME" ]; then
local _domain
_domain=$( ipconfig -all | grep "Primary Dns" | cut -f 2 -d ':' | tr -d ' ' )
FQDN="${COMPUTERNAME}.${_domain}"
fi
fi
fi
if [ -z "$FQDN" ]; then
echo "ERROR: unable to detect fqdn. Aborting."
exit 1
fi
fi
if ! echo "$FQDN" | grep "\..*" >/dev/null; then
echo "ERROR: fqdn $FQDN does not contain a domain name. Aborting."
exit 1
fi
# echo "INFO: FQDN is [$FQDN]"
}
# ------------------------------------------------------------
# check if it was startet with a given user
# This is skipped if MS windows was detected with "mingw".
......
......@@ -3,6 +3,12 @@
# set custom variables eg. extend PATH
# ----------------------------------------------------------------------
# extend path
# PATH=/c/portable/restic/:$PATH
# if you get "ERROR: unable to detect fqdn.":
# the command "hostname -f" must return a fqdn (host incl. domain)
# if all tries fail set a hostname as fqdn here
# FQDN=mycomputer.example.com
# ----------------------------------------------------------------------
......@@ -38,8 +38,7 @@
local _target=$( j_getFullTarget )
echo ${_target} | grep "https.*@" >/dev/null
if [ $? -eq 0 ]; then
local _host=$( hostname -f )
_target=$( echo $_target | sed "s#${_host}/##" )
_target=$( echo $_target | sed "s#${FQDN}/##" )
fi
export RESTIC_REPOSITORY=$_target
......
......@@ -323,7 +323,7 @@ function setAction(){
else
iExit=1
until [ $iExit -eq 0 ]; do
registerBackupSlot "$(hostname -f)"
registerBackupSlot "$FQDN"
iExit=$?
if [ $iExit -ne 0 ]; then
statusBackupSlot
......@@ -482,7 +482,7 @@ function setAction(){
if [ -z "$STORAGE_REGISTER" ]; then
echo "SKIP"
else
unregisterBackupSlot "$(hostname -f)" $rc
unregisterBackupSlot "$FQDN" $rc
fi
h2 "$( date ) Backup finished"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment