-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdaps2docker-common
114 lines (94 loc) · 2.11 KB
/
daps2docker-common
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/env bash
#
# This file is part of the daps2docker scripts
# It contains common variables and
# --- Variables
#
SYSTEM_CONFIGDIR="/etc/daps2docker"
USER_CONFIGDIR="$HOME/.config/daps2docker"
DEFAULT_CONFIGNAME="config"
GIT_DEFAULT_CONFIGNAME=".daps2docker.conf"
META_PREFIX=".meta"
# Declare some global arrays
declare -A valid_formats
declare -A configfilelist
index=0
# --- Functions
#
is_bool() {
# Check if the value is a boolean
# $1 - value to check for boolness
[[ "$1" == 0 || "$1" == 1 ]] && echo "isbool"
}
load_config_file() {
# $1 the config file to be loaded
#
local config=$1
if [[ -e $config ]]; then
source "$config"
index=$((index + 1))
configfilelist[$index]=$config
echo "[INFO] Loading config file \"$config\"..."
fi
}
get_toplevel_gitdir() {
# $1 the directory to check if it's a local Git repo
local DIR=${1:-.}
# If we have a file, use the directory only
[ -f $DIR ] && DIR=$(dirname $DIR)
git -C ${DIR} rev-parse --show-toplevel
}
is_git_dir() {
local dir=${1:-.}
# $1 the directory to check if it's a local Git repo
get_toplevel_gitdir ${dir} 1>/dev/null 2>&1; return $?
}
get_user_id() {
# Get the user id
if [ -n "$UID" ]; then
echo "$UID"
else
id -u
fi
}
get_group_id() {
# Get the group id
if [ -n "$GID" ]; then
echo "$GID"
else
id -g
fi
}
get_user_group_id() {
# Get the user and group id
local USER_ID=$(get_user_id)
local GROUP_ID=$(get_group_id)
echo "${USER_ID}:${GROUP_ID}"
}
log_message() {
# $1 - the message to log
# $2 - the log level
local message=$1
local loglevel=${2:-"INFO"}
echo -e "[$loglevel] $message"
}
log_debug() {
# $1 - the message to log
log_message "$1" "DEBUG"
}
log_info() {
# $1 - the message to log
log_message "$1" "INFO"
}
log_warn() {
# $1 - the message to log
log_message "$1" "WARN"
}
log_error() {
# $1 - the message to log
log_message "$1" "ERROR"
}
log_critical() {
# $1 - the message to log
log_message "$1" "CRITICAL"
}