pack_in_onefile.sh 2.93 KB
Newer Older
1
#!/bin/sh
2 3 4
#
# Run for create one-file-scripts
#
5 6
# Copyright (C) 2012, 2016, 2017  Etersoft
# Copyright (C) 2012, 2016, 2017  Vitaly Lipatov <lav@etersoft.ru>
7
#
8 9 10
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
11 12 13 14 15
# (at your option) any later version.
#
# This program 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
16
# GNU Affero General Public License for more details.
17
#
18 19
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
20 21
#

22

23
incorporate_subfile()
24 25
{
cat <<EOF >>$OUTPUT
26

27 28
################# incorporate $1 #################
internal_$(basename $1)()
29 30 31
{
EOF

32
cat $1 | grep -v "^#!/bin/sh" | sed -e 's| exit$| return|g' -e 's|exit \$| return $|g' -e 's|^init_eget$||' >>$OUTPUT
33 34 35

cat <<EOF >>$OUTPUT
}
36 37
################# end of incorporated $1 #################

38 39 40
EOF
}

41 42 43 44 45
get_version()
{
	grep "^Version:" eepm.spec | head -n1 | sed "s|Version: *||g"
}

46 47
filter_out()
{
48
	grep -v "^[ 	]*load_helper " | \
49 50
		sed -e 's|^eget()|disabled_eget()|g' | \
		sed -e 's|^onefile_eget()|eget()|g' | \
51 52 53 54
		sed -e 's|^erc()|disabled_erc()|g' | \
		sed -e 's|^onefile_erc()|erc()|g' | \
		sed -e 's|^ercat()|disabled_ercat()|g' | \
		sed -e 's|^onefile_ercat()|ercat()|g' | \
Vitaly Lipatov's avatar
Vitaly Lipatov committed
55 56
		sed -e 's|^estrlist()|disabled_estrlist()|g' | \
		sed -e 's|^onefile_estrlist()|estrlist()|g' | \
57
		sed -e 's|$SHAREDIR/tools_json|internal_tools_json|g' | \
58
		sed -e 's|DISTRVENDOR=$PROGDIR/distr_info|DISTRVENDOR=internal_distr_info|g' | \
59 60
		sed -e "s|@VERSION@|$(get_version)|g"

61 62 63 64
}

incorporate_all()
{
65 66
mkdir -p packed
OUTPUT=packed/$PACKCOMMAND.sh
67
echo -n >$OUTPUT
68
awk 'BEGIN{desk=0}{if(/^load_helper epm-sh-functions/){desk++};if(desk==0) {print}}' <bin/$PACKCOMMAND | filter_out >>$OUTPUT
69 70 71 72 73 74 75

for i in bin/epm-sh-functions $(ls -1 bin/$PACKCOMMAND-* | grep -v epm-sh-functions | sort) ; do
	echo
	echo "# File $i:"
	cat $i | grep -v "^#"
done | filter_out >>$OUTPUT

76
incorporate_subfile bin/distr_info
77 78
if [ "$PACKCOMMAND" = "epm" ] ; then
    incorporate_subfile bin/tools_eget
79 80
    [ -f bin/tools_erc ] && incorporate_subfile bin/tools_erc
    [ -f bin/tools_ercat ] && incorporate_subfile bin/tools_ercat
81 82 83 84 85 86 87 88 89
    incorporate_subfile bin/tools_estrlist
    incorporate_subfile bin/tools_json
fi

cat <<EOF >>$OUTPUT

${PACKCOMMAND}_main()
{
EOF
90 91

awk 'BEGIN{desk=0}{if(desk>0) {print} ; if(/^load_helper epm-sh-functions/){desk++}}' <bin/$PACKCOMMAND | filter_out >>$OUTPUT
92 93 94 95 96 97

cat <<EOF >>$OUTPUT
}
${PACKCOMMAND}_main "\$@"
EOF

98
chmod 0755 $OUTPUT
99 100 101 102 103 104
}

###############
PACKCOMMAND=epm
incorporate_all

105 106 107
# test
packed/$PACKCOMMAND.sh --help >/dev/null || exit

108 109 110
###############
PACKCOMMAND=serv
incorporate_all
111 112 113

# test
packed/$PACKCOMMAND.sh --help >/dev/null || exit