forked from Tauop/sshGate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·126 lines (103 loc) · 3.64 KB
/
build.sh
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
#
# Copyright (c) 2010 Linagora
# Patrick Guiran <pguiran@linagora.com>
# http://github.com/Tauop/sshGate
#
# sshGate is free software, you can redistribute it and/or modify
# it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of
# the License, or (at your option) any later version.
#
# sshGate is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
INTERACTIVE_MODE='N'
if [ "$1" = '-i' ]; then
INTERACTIVE_MODE='Y'
fi
# load dependencies
load() {
local var= value= file=
var="$1"; file="$2"
value=$( eval "echo \"\${${var}:-}\"" )
[ -n "${value}" ] && return 1;
if [ -f "${file}" ]; then
. "${file}"
else
echo "ERROR: Unable to load ${file}"
exit 2
fi
return 0;
}
# Load configuration file
if [ -r /etc/ScriptHelper.conf ]; then
. /etc/ScriptHelper.conf
SCRIPT_HELPER_DIRECTORY="${SCRIPT_HELPER_DIRECTORY:-}"
SCRIPT_HELPER_DIRECTORY="${SCRIPT_HELPER_DIRECTORY%%/}"
else
SCRIPT_HELPER_DIRECTORY='./lib'
fi
if [ ! -d "${SCRIPT_HELPER_DIRECTORY}/" ]; then
echo "[ERROR] sshGate depends on ScriptHelper which doesn't seem to be installed"
exit 2
fi
load __LIB_MESSAGE__ "${SCRIPT_HELPER_DIRECTORY}/message.lib.sh"
load __LIB_ASK__ "${SCRIPT_HELPER_DIRECTORY}/ask.lib.sh"
# ----------------------------------------------------------------------------
version=
if [ "${INTERACTIVE_MODE}" = 'Y' ]; then
ASK version "sshgate version ?"
# build are used for testing :-) (can be empty)
build=
ASK --allow-empty build "sshGate build number ?"
[ -n "${build}" ] && version="${version}-${build}"
include_script_helper='N'
ASK --yesno include_script_helper 'Include ScriptHelper in package ?'
else
version=$( cat VERSION )
include_script_helper='Y'
fi
# ----------------------------------------------------------------------------
DOTHIS 'Build sshgate-server package'
softname=sshGate-server-${version}
dir="/tmp/${softname}"
[ -d "${dir}/" ] && rm -rf "${dir}/"
mkdir "${dir}/"
# for MacOS X and its fucking ._files
export COPYFILE_DISABLE=true
cp -r ./ "${dir}/"
if [ "${include_script_helper}" = 'N' ]; then
# cp -r ./lib ${dir}/
rm -rf "${dir}/lib/"
fi
# specific action for package built with build.sh script
find "${dir}/build-utils" -name "*.sh" -exec mv {} "${dir}/" ';'
mv "${dir}/build-utils/bin/sshgate-configure" "${dir}/bin/sshgate-configure"
mv "${dir}/build-utils/bin/core/setup.func" "${dir}/bin/core/setup.func"
rm -rf "${dir}/build-utils/"
# clean up
find "${dir}/" -name "sshGate-server-*.tar.gz" | xargs rm -f
find "${dir}/" -type f -iname '*swp' | xargs rm -f
find "${dir}/" -type f -iname '.*' | xargs rm -f
find "${dir}/" -iname '.git' | xargs rm -rf
# put version and build number
sed_repl=
sed_repl="${sed_repl} s|%% __SSHGATE_VERSION__ %%|${version}|;"
sed_repl="${sed_repl} s|%% __SSHGATE_BUILD__ %%|${build}|;"
sed -e "${sed_repl}" < "${dir}/install.sh" > "${dir}/install.sh.sed"
sed -e "${sed_repl}" < "${dir}/data/sshgate.conf" > "${dir}/sshgate.conf.sed"
mv "${dir}/install.sh.sed" "${dir}/install.sh"
mv "${dir}/sshgate.conf.sed" "${dir}/data/sshgate.conf"
chmod +x "${dir}/install.sh"
cd /tmp
tar -z -c -f "${softname}.tar.gz" "${softname}" 2>/dev/null >/dev/null
cd - >/dev/null
mv "${dir}.tar.gz" .
rm -rf "${dir}"
OK