-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·126 lines (100 loc) · 2.92 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·126 lines (100 loc) · 2.92 KB
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
115
116
117
118
119
120
121
122
123
124
125
126
#!/bin/bash
YES=0 #no touchee
NO=1 #no touchee
# ###
# User might want to change these, though should use environment vars
# ###
INSTALL_DIR="${LDAPTOOLS_INSTALL_DIR:-$HOME/ldap-tools}"
DEBUG=$YES
VERBOSE=$YES
# ###
# END OF USER CONFIGURABLE SECTION
# ###
TS=$( date +%Y-%m-%d_%H%M%S )
BASE=$( readlink -e $( dirname "$0" ) )
log() {
[[ $VERBOSE -eq $YES ]] || return 0
echo "INFO $*" >&2
}
debug() {
[[ $DEBUG -eq $YES ]] || return 0
echo "DEBUG (${BASH_SOURCE[1]} [${BASH_LINENO[0]}] ${FUNCNAME[1]}) $*"
}
set_install_dir() {
[[ $DEBUG -eq $YES ]] && set -x
# Update any files that need INSTALL_DIR
local _pattern='___INSTALL_DIR___'
local _replacement="$INSTALL_DIR"
grep -r --files-with-matches -F "$_pattern" "${BASE}" \
| while read; do
sed -i -e "s?$_pattern?$_replacement?" "$REPLY"
done
}
install_subdirs() {
[[ $DEBUG -eq $YES ]] && set -x
declare -A _dir_modes=(
[bin]='0755'
[cron]='0755'
[conf]='0644'
[files]='0644'
[lib]='0644'
[lap]='0644'
)
local _base_len
let "_base_len = ${#BASE} + 1"
for dir in "${!_dir_modes[@]}"; do
# make target dirs
for tgt in $( find "${BASE}"/"${dir}" -type d ); do
local _subd="${tgt:${_base_len}}"
install -d "${INSTALL_DIR}"/"${_subd}"
done
# install each file
for file in $( find "${BASE}"/"${dir}" -type f ); do
local _file=$( basename "${file}" )
local _dir=$(dirname "${file}" )
local _subd="${_dir:${_base_len}}"
install \
-D \
--compare \
--verbose \
--suffix="${TS}" \
--mode="${_dir_modes[$dir]}" \
-t "${INSTALL_DIR}"/"${_subd}" \
"${file}"
done
done
}
mk_symlinks() {
[[ $debug -eq $yes ]] && set -x
local _conf_bkup_dir _conf_bkup_file
_conf_bkup_dir="${HOME}"/.config/ldap
declare -A _links=(
["${INSTALL_DIR}"/bin/stop]="${INSTALL_DIR}"/bin/serverctl
["${INSTALL_DIR}"/bin/start]="${INSTALL_DIR}"/bin/serverctl
["${INSTALL_DIR}"/bin/restart]="${INSTALL_DIR}"/bin/serverctl
["${INSTALL_DIR}"/bin/status]="${INSTALL_DIR}"/bin/serverctl
["${INSTALL_DIR}"/bin/dsconf]="${INSTALL_DIR}"/bin/dsc
["${INSTALL_DIR}"/bin/dsctl]="${INSTALL_DIR}"/bin/dsc
["${INSTALL_DIR}"/bin/ldapsearch]="${INSTALL_DIR}"/bin/dsc
["${INSTALL_DIR}"/bin/ldapmodify]="${INSTALL_DIR}"/bin/dsc
# ["${INSTALL_DIR}"/conf/config]="${INSTALL_DIR}"/conf/example
)
# Look for an existing config to restore
local _conf_bkup_dir="${HOME}"/.config/ldap
if [[ -d "${_conf_bkup_dir}" ]] ; then
_conf_bkup_file=$( find "${_conf_bkup_dir}" -type f -name config | head -1 )
if [[ -f "${_conf_bkup_file}" ]] ; then
_links["${INSTALL_DIR}"/conf/config]="${_conf_bkup_file}"
fi
fi
for k in "${!_links[@]}"; do
src="${_links[$k]}"
tgt="${k}"
[[ -e "${tgt}" ]] \
|| ln -sr "${src}" "${tgt}"
done
}
[[ $DEBUG -eq $YES ]] && set -x
set_install_dir
install_subdirs
mk_symlinks