| 1 |
# Polypkg main
|
| 2 |
|
| 3 |
pp_version="1.0.0.$pp_revision"
|
| 4 |
pp_copyright="(c) 2008, Quest Software, Inc. All rights reserved."
|
| 5 |
|
| 6 |
pp_opt_debug=false
|
| 7 |
pp_opt_destdir="$DESTDIR"
|
| 8 |
pp_opt_install_script=
|
| 9 |
pp_opt_list=false
|
| 10 |
pp_opt_no_clean=false
|
| 11 |
pp_opt_no_package=false
|
| 12 |
pp_opt_only_front=false
|
| 13 |
pp_opt_platform=
|
| 14 |
pp_opt_probe=false
|
| 15 |
pp_opt_strip=false
|
| 16 |
pp_opt_save_unstripped=false
|
| 17 |
pp_opt_vas_platforms=false
|
| 18 |
pp_opt_wrkdir="`pwd`/pp.work.$$"
|
| 19 |
pp_opt_verbose=false
|
| 20 |
pp_opt_version=false
|
| 21 |
pp_opt_input="-"
|
| 22 |
pp_opt_init_vars=""
|
| 23 |
pp_opt_eval=
|
| 24 |
|
| 25 |
test -n "$PP_NO_CLEAN" && pp_opt_no_clean=true
|
| 26 |
test -n "$PP_DEBUG" && pp_opt_debug=true
|
| 27 |
test -n "$PP_VERBOSE" && pp_opt_verbose=true
|
| 28 |
|
| 29 |
#@ pp_main_cleanup(): calls backend cleanup and removes $pp_wrkdir
|
| 30 |
pp_main_cleanup () {
|
| 31 |
pp_debug "main_cleanup"
|
| 32 |
pp_remove_later_now
|
| 33 |
if $pp_opt_no_clean || test x"$pp_platform" = x"unknown"; then
|
| 34 |
: no cleanup
|
| 35 |
else
|
| 36 |
pp_backend_${pp_platform}_cleanup
|
| 37 |
$pp_errors && pp_die "Errors during cleanup"
|
| 38 |
if test -d "$pp_wrkdir"; then
|
| 39 |
if $pp_opt_debug; then
|
| 40 |
pp_debug "not removing $pp_wrkdir"
|
| 41 |
else
|
| 42 |
pp_verbose rm -rf "$pp_wrkdir"
|
| 43 |
fi
|
| 44 |
fi
|
| 45 |
fi
|
| 46 |
}
|
| 47 |
|
| 48 |
#@ pp_parseopts(args...): sets the $pp_opt_* variables from cmd line args
|
| 49 |
# exits on incorrect usage
|
| 50 |
pp_parseopts () {
|
| 51 |
typeset a n _var _val
|
| 52 |
while test $# -gt 0; do
|
| 53 |
|
| 54 |
# convert -[dilpv] to --long-options
|
| 55 |
case "$1" in
|
| 56 |
--?*=?*) n=`echo "$1" | sed -ne 's/^--\([^=]*\)=.*/\1/p'`
|
| 57 |
a=`echo "$1" | sed -ne 's/^--[^=]*=\(.*\)/\1/p'`
|
| 58 |
shift
|
| 59 |
set -- "--$n" "$a" "$@";;
|
| 60 |
--?*) : ;;
|
| 61 |
|
| 62 |
-d) shift; set -- "--debug" "$@";;
|
| 63 |
-d*) a=`echo "$1" | sed -ne 's/^-.//'`
|
| 64 |
shift; set -- "--debug" "$@";;
|
| 65 |
|
| 66 |
-i) shift; set -- "--install-script" "$@";;
|
| 67 |
-i*) a=`echo "$1" | sed -ne 's/^-.//'`
|
| 68 |
shift; set -- "--install-script" "$a" "$@";;
|
| 69 |
|
| 70 |
-l) shift; set -- "--list" "$@";;
|
| 71 |
-l*) a=`echo "$1" | sed -ne 's/^-.//'`
|
| 72 |
shift; set -- "--list" "$@";;
|
| 73 |
|
| 74 |
-p) shift; set -- "--platform" "$@";;
|
| 75 |
-p*) a=`echo "$1" | sed -ne 's/^-.//'`
|
| 76 |
shift; set -- "--platform" "$a" "$@";;
|
| 77 |
|
| 78 |
-v) shift; set -- "--verbose" "$@";;
|
| 79 |
-v*) a=`echo "$1" | sed -ne 's/^-.//'`
|
| 80 |
shift; set -- "--verbose" "$@";;
|
| 81 |
|
| 82 |
-\?) shift; set -- "--help" "$@";;
|
| 83 |
-\?*) a=`echo "$1" | sed -ne 's/^-.//'`
|
| 84 |
shift; set -- "--help" "$@";;
|
| 85 |
esac
|
| 86 |
|
| 87 |
case "$1" in
|
| 88 |
--destdir|--eval|--install-script|--platform|--wrkdir)
|
| 89 |
test $# -ge 2 || pp_error "missing argument to $1";;
|
| 90 |
esac
|
| 91 |
|
| 92 |
case "$1" in
|
| 93 |
--) shift;break;;
|
| 94 |
--debug) pp_opt_debug=true; shift;;
|
| 95 |
--destdir) pp_opt_destdir="$2"; shift;shift;;
|
| 96 |
--eval) pp_opt_eval="$2"; shift;shift;; # undoc
|
| 97 |
--install-script) pp_opt_install_script="$2"; shift;shift;;
|
| 98 |
--list) pp_opt_list=true; shift;;
|
| 99 |
--no-clean) pp_opt_no_clean=true; shift;;
|
| 100 |
--no-package) pp_opt_no_package=true; shift;;
|
| 101 |
--only-front) pp_opt_only_front=true; shift;;
|
| 102 |
--platform) pp_opt_platform="$2"; shift;shift;;
|
| 103 |
--probe) pp_opt_probe=true; shift;;
|
| 104 |
--strip) pp_opt_strip=true; shift;;
|
| 105 |
--save-unstripped) pp_opt_save_unstripped=true; shift;;
|
| 106 |
--wrkdir) pp_opt_wrkdir="$2"; shift;shift;;
|
| 107 |
--vas-platforms) pp_opt_vas_platforms=true; shift;;
|
| 108 |
--verbose) pp_opt_verbose=true; shift;;
|
| 109 |
--version) pp_opt_version=true; shift;;
|
| 110 |
--help) pp_errors=true; shift;;
|
| 111 |
-) break;;
|
| 112 |
-*) pp_error "unknown option $1"; shift;;
|
| 113 |
*) break;;
|
| 114 |
esac
|
| 115 |
|
| 116 |
done
|
| 117 |
|
| 118 |
pp_opt_input=-
|
| 119 |
if test $# -gt 0; then
|
| 120 |
pp_opt_input="$1"
|
| 121 |
shift
|
| 122 |
fi
|
| 123 |
|
| 124 |
#-- extra arguments of the form Foo=bar alter *global* vars
|
| 125 |
while test $# -gt 0; do
|
| 126 |
case "$1" in
|
| 127 |
-*) pp_error "unexpected option '$1'"
|
| 128 |
shift;;
|
| 129 |
*=*) _val="${1#*=}"
|
| 130 |
_var=${1%="$_val"}
|
| 131 |
_val=`echo "$_val"|sed -e 's/[$"\\]/\\&/g'`
|
| 132 |
pp_debug "setting $_var = \"$_val\""
|
| 133 |
pp_opt_init_vars="$pp_opt_init_vars$_var=\"$_val\";"
|
| 134 |
shift;;
|
| 135 |
*) pp_error "unexpected argument $1'"
|
| 136 |
shift;;
|
| 137 |
esac
|
| 138 |
done
|
| 139 |
|
| 140 |
test $# -gt 0 &&
|
| 141 |
pp_error "unknown argument $1"
|
| 142 |
|
| 143 |
if $pp_errors; then
|
| 144 |
cat <<. >&2
|
| 145 |
polypkg $pp_version $pp_copyright
|
| 146 |
usage: $0 [options] [input.pp] [var=value ...]
|
| 147 |
-d --debug -- write copious info to stderr
|
| 148 |
--destdir=path -- file root, defaults to \$DESTDIR
|
| 149 |
-? --help -- display this information
|
| 150 |
-i --install-script=path -- create an install helper script
|
| 151 |
-l --list -- write package filenames to stdout
|
| 152 |
--no-clean -- don't remove temporary files
|
| 153 |
--no-package -- do everything but create packages
|
| 154 |
--only-front -- only perform front-end actions
|
| 155 |
-p --platform=platform -- defaults to local platform
|
| 156 |
--probe -- print local system identifier, then exit
|
| 157 |
--strip -- strip debug symbols from binaries before
|
| 158 |
packaging (modifies files in destdir)
|
| 159 |
--save-unstripped -- save unstripped binaries to
|
| 160 |
\$name-\$version-unstripped.tar.gz
|
| 161 |
--wrkdir=path -- defaults to subdirectory of \$TMPDIR or /tmp
|
| 162 |
-v --verbose -- write info to stderr
|
| 163 |
--version -- display version and quit
|
| 164 |
.
|
| 165 |
exit 1
|
| 166 |
fi
|
| 167 |
}
|
| 168 |
|
| 169 |
#@ pp_drive(): drives the front-end, middle and backend
|
| 170 |
pp_drive () {
|
| 171 |
# initialise the front and back ends
|
| 172 |
pp_model_init
|
| 173 |
pp_frontend_init
|
| 174 |
$pp_opt_only_front || pp_backend_init
|
| 175 |
|
| 176 |
# run the front-end to generate the intermediate files
|
| 177 |
# set $pp_input_dir to be the 'include dir' if needed
|
| 178 |
pp_debug "calling frontend on $pp_opt_input"
|
| 179 |
case "$pp_opt_input" in
|
| 180 |
-) pp_input_dir=.
|
| 181 |
test -t 1<&0 &&
|
| 182 |
pp_warn "reading directives from standard input"
|
| 183 |
pp_frontend
|
| 184 |
;;
|
| 185 |
*/*) pp_input_dir=${pp_opt_input%/*}
|
| 186 |
pp_frontend <"$pp_opt_input"
|
| 187 |
;;
|
| 188 |
*) pp_input_dir=.
|
| 189 |
pp_frontend <"$pp_opt_input"
|
| 190 |
;;
|
| 191 |
esac
|
| 192 |
|
| 193 |
pp_files_ignore_others
|
| 194 |
pp_service_scan_groups
|
| 195 |
|
| 196 |
# some sanity checks after front-end processing
|
| 197 |
if test x"$pp_platform" != x"null"; then
|
| 198 |
pp_debug "sanity checks"
|
| 199 |
test -n "$pp_components" || pp_error "No components?"
|
| 200 |
pp_check_var_is_defined "name"
|
| 201 |
pp_check_var_is_defined "version"
|
| 202 |
pp_files_check_duplicates
|
| 203 |
pp_files_check_coverage
|
| 204 |
pp_die_if_errors "Errors during sanity checks"
|
| 205 |
fi
|
| 206 |
|
| 207 |
# stop now if we're only running the front
|
| 208 |
$pp_opt_only_front && return
|
| 209 |
|
| 210 |
if test x"$pp_opt_strip" = x"true"; then
|
| 211 |
pp_strip_binaries
|
| 212 |
fi
|
| 213 |
|
| 214 |
# run the back-end to generate the package
|
| 215 |
pp_debug "calling backend"
|
| 216 |
pp_backend
|
| 217 |
pp_die_if_errors "Errors during backend processing"
|
| 218 |
|
| 219 |
# copy the resulting package files to PP_PKGDESTDIR or .
|
| 220 |
for f in `pp_backend_names` -; do
|
| 221 |
test x"$f" = x"-" && continue
|
| 222 |
pp_debug "copying: $f to `pwd`"
|
| 223 |
if pp_verbose cp $pp_wrkdir/$f ${PP_PKGDESTDIR:-.}; then
|
| 224 |
echo "${PP_PKGDESTDIR:+$PP_PKGDESTDIR/}$f"
|
| 225 |
else
|
| 226 |
pp_error "$f: missing package"
|
| 227 |
fi
|
| 228 |
done
|
| 229 |
pp_die_if_errors "Errors during package copying"
|
| 230 |
}
|
| 231 |
|
| 232 |
#@ pp_install_script(): generate the install helper script
|
| 233 |
pp_install_script () {
|
| 234 |
pp_debug "writing install script to $pp_opt_install_script"
|
| 235 |
rm -f $pp_opt_install_script
|
| 236 |
pp_backend_install_script > $pp_opt_install_script
|
| 237 |
pp_die_if_errors "Errors during package install script"
|
| 238 |
chmod +x $pp_opt_install_script
|
| 239 |
}
|
| 240 |
|
| 241 |
#@ pp_main(): main driver function
|
| 242 |
pp_main () {
|
| 243 |
# If PP_DEV_PATH is set, then jump to that script.
|
| 244 |
# (Useful when working on polypkg source that isn't installed)
|
| 245 |
if test -n "$PP_DEV_PATH" -a x"$PP_DEV_PATH" != x"$0"; then
|
| 246 |
pp_warn "switching from $0 to $PP_DEV_PATH ..."
|
| 247 |
exec "$PP_DEV_PATH" "$@" || exit 1
|
| 248 |
fi
|
| 249 |
|
| 250 |
pp_set_expand_converter_or_reexec "$@"
|
| 251 |
pp_parseopts "$@"
|
| 252 |
|
| 253 |
if $pp_opt_version; then
|
| 254 |
#-- print version and exit
|
| 255 |
echo "polypkg $pp_version"
|
| 256 |
exit 0
|
| 257 |
fi
|
| 258 |
|
| 259 |
pp_set_platform
|
| 260 |
|
| 261 |
trap 'pp_main_cleanup' 0
|
| 262 |
|
| 263 |
pp_wrkdir="$pp_opt_wrkdir"
|
| 264 |
pp_debug "pp_wrkdir = $pp_wrkdir"
|
| 265 |
rm -rf "$pp_wrkdir"
|
| 266 |
mkdir -p "$pp_wrkdir"
|
| 267 |
|
| 268 |
pp_destdir="$pp_opt_destdir"
|
| 269 |
pp_debug "pp_destdir = $pp_destdir"
|
| 270 |
|
| 271 |
if $pp_opt_probe; then
|
| 272 |
pp_backend_init
|
| 273 |
pp_backend_probe
|
| 274 |
elif $pp_opt_vas_platforms; then
|
| 275 |
pp_backend_init
|
| 276 |
pp_backend_vas_platforms
|
| 277 |
elif test -n "$pp_opt_eval"; then
|
| 278 |
#-- execute a shell command
|
| 279 |
eval "$pp_opt_eval" || exit
|
| 280 |
else
|
| 281 |
pp_drive
|
| 282 |
if test -n "$pp_opt_install_script"; then
|
| 283 |
pp_install_script
|
| 284 |
fi
|
| 285 |
fi
|
| 286 |
|
| 287 |
exit 0
|
| 288 |
}
|
| 289 |
|