Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/proto/sear.sh
1808 views
1
########################################################################
2
# #
3
# This software is part of the ast package #
4
# Copyright (c) 1990-2011 AT&T Intellectual Property #
5
# and is licensed under the #
6
# Eclipse Public License, Version 1.0 #
7
# by AT&T Intellectual Property #
8
# #
9
# A copy of the License is available at #
10
# http://www.eclipse.org/org/documents/epl-v10.html #
11
# (with md5 checksum b35adb5213ca9657e911e9befb180842) #
12
# #
13
# Information and Software Systems Research #
14
# AT&T Research #
15
# Florham Park NJ #
16
# #
17
# Glenn Fowler <[email protected]> #
18
# #
19
########################################################################
20
: self extracting archive generator for ratz
21
22
COMMAND=sear
23
24
args=
25
cc="ncc -O -Y-Os"
26
cmd="dir"
27
dyn=-D_DLL
28
ico=
29
opt=
30
out=install.exe
31
src=
32
33
case `(getopts '[-][123:xyz]' opt --xyz; echo 0$opt) 2>/dev/null` in
34
0123) ARGV0="-a $COMMAND"
35
USAGE=$'
36
[-?
37
@(#)$Id: sear (AT&T Labs Research) 2011-03-04 $
38
]
39
'$USAGE_LICENSE$'
40
[+NAME?sear - generate a win32 ratz self extracting archive]
41
[+DESCRIPTION?\bsear\b generates a win32 self extracting archive that
42
can be used to install win32 files and applications. \bpax\b(1) is used
43
to generate a \btgz\b (\btar\b(1) \bgzip\b(1)) archive from the
44
\afile\a operands that is appended to the self extracting archive. If
45
no \afile\a operands are specified then the standard input is read.
46
\bpax\b(1) options (like \b--verbose\b) may be specified after a \b--\b
47
operand but before the first \afile\a operand.]
48
[+?When the self extracting archive is executed it creates a temporary
49
directory and unpacks each \afile\a. If \b--command\b=\acommand\a was
50
specified when the archive was generated then \acommand\a is executed
51
by \bCMD.EXE\b. The temporary directory is then removed.]
52
[+?\b.exe\b files generated by \bsear\b(1) are fully functional
53
\bratz\b(1) executables, so any \bratz\b option may be used on a
54
\bsear\b file. This allows \bsear\b file contents to be examined and
55
extracted without executing any embedded installation scripts.]
56
[a:args|arguments?The arguments appended to the \bCMD.EXE\b command
57
string after the runtime sear operands are appended.]:[args]
58
[b:bootstrap?Bootstrap-sepcific link.]
59
[c:cc?The C compiler command and flags are set to \acc\a.]:[cc:='$cc$']
60
[i:icon?The resource icon is set to \aicon\a. The default is a 32 or 64
61
bit icon.]:[icon:=$INSTALLROOT/lib/sear/sear??.ico]
62
[m:meter?Set the \bratz\b(1) \b--meter\b option when the archive is
63
extracted.]
64
[o:output?The self extracting file name is \afile\a.]:[file:='$out$']
65
[r:ratz?The \bratz\b(1) source file is set to
66
\apath\a.]:[path:=$INSTALLROOT/lib/sear/ratz.c]
67
[x:command?The \bCMD.EXE\b command string to run after the top level
68
files have been read into the temporary directory.]:[command:='$cmd$']
69
[v:verbose?Set the \bratz\b(1) \b--verbose\b option when the archive is
70
extracted.]
71
72
[ -- pax-options ] [ file ] ...
73
74
[+EXIT STATUS?]{
75
[+0?Success.]
76
[+>0?An error occurred.]
77
}
78
[+SEE ALSO?\bratz\b(1), \bgunzip\b(1), \bpax\b(1), \bCMD.EXE\b(m$)]
79
'
80
;;
81
*) ARGV0=""
82
USAGE="c:[command]i:[icon]o:[output]r:[ratz-src] [ file ] ..."
83
;;
84
esac
85
86
usage()
87
{
88
OPTIND=0
89
getopts $ARGV0 "$USAGE" OPT '-?'
90
exit 2
91
}
92
93
while getopts $ARGV0 "$USAGE" OPT
94
do case $OPT in
95
a) args=-D_SEAR_ARGS="\"$OPTARG\""
96
;;
97
b) dyn=
98
;;
99
c) cc=$OPTARG
100
;;
101
i) ico=$OPTARG
102
;;
103
m) opt=${opt}m
104
;;
105
o) out=$OPTARG
106
[[ ${out##*/} != *.?* ]] && out=${out%.}.exe
107
;;
108
r) src=$OPTARG
109
;;
110
x) cmd=$OPTARG
111
;;
112
v) opt=${opt}v
113
;;
114
*) usage
115
;;
116
esac
117
done
118
shift $((OPTIND-1))
119
120
if [[ ! $src ]]
121
then f=ratz.c
122
src=$(dirname -r lib/$COMMAND/$f)
123
if [[ ! $src ]]
124
then echo "$COMMAND: $f: cannot locate ratz source" >&2
125
exit 1
126
fi
127
elif [[ ! -f $src ]]
128
then echo "$COMMAND: $src: cannot read ratz source" >&2
129
exit 1
130
fi
131
if [[ ! $ico ]]
132
then w=$(uname -i 2>/dev/null)
133
w=${w%/*}
134
[[ $w == 32 || $w == 64 ]] || w=
135
f=sear$w.ico
136
ico=$(dirname -r lib/$COMMAND/$f)
137
if [[ ! $ico ]]
138
then echo "$COMMAND: $f: cannot locate icon source" >&2
139
exit 1
140
fi
141
elif [[ ! -f $ico ]]
142
then echo "$COMMAND: $ico: cannot read icon" >&2
143
exit 1
144
fi
145
[[ $opt ]] && cc="$cc -D_SEAR_OPTS=\"-$opt\""
146
cc="$cc $dyn"
147
148
tmp=/tmp/sear$$
149
obj=${src##*/}
150
obj=${obj%.*}.o
151
trap 'rm -f "$obj" $tmp.*' 0 1 2 3
152
res=$tmp.res
153
libs=-ladvapi32
154
typeset -H host_ico=$ico host_rc=$tmp.rc host_res=$tmp.res
155
print -r "sear ICON \"${host_ico//\\/\\\\}\"" > $tmp.rc
156
if ! rc -x -r -fo"$host_res" "$host_rc"
157
then exit 1
158
fi
159
if ! $cc -D_SEAR_SEEK=0 -D_SEAR_EXEC="\"$cmd\"" "$args" -c "$src" ||
160
! ${cc/-Bstatic/} --mt-output="$out.manifest" --mt-name="${out%.*}" --mt-administrator -o "$out" "$obj" "$res" $libs
161
then exit 1
162
fi
163
if [[ -f "$out.manifest" ]]
164
then mv "$out.manifest" "${out%.*}.manifest"
165
ed - "${out%.*}.manifest" <<-'!'
166
/<dependency>/,/<\/dependency>/d
167
w
168
q
169
!
170
if ! $cc --mt-input="${out%.*}.manifest" -o "$out" "$obj" "$res" $libs
171
then exit 1
172
fi
173
mt="--mt-input=${out%.*}.manifest --mt-delete"
174
else mt=
175
fi
176
size=$(wc -c < "$out")
177
if ! $cc -D_SEAR_SEEK=$(($size)) -D_SEAR_EXEC="\"$cmd\"" "$args" -c "$src" ||
178
! $cc $mt -o "$out" "$obj" "$res" $libs
179
then exit 1
180
fi
181
if [[ -f "$out.manifest" ]]
182
then rm -f "$out.manifest"
183
fi
184
files=0
185
pax -x tgz -w "$@" >> "$out"
186
187