1*cdf0e10cSrcweir#!/bin/sh
2*cdf0e10cSrcweir
3*cdf0e10cSrcweirlinenum=LINENUMBERPLACEHOLDER
4*cdf0e10cSrcweir
5*cdf0e10cSrcweirUNPACKDIR=/var/tmp/unpack_PRODUCTNAMEPLACEHOLDER
6*cdf0e10cSrcweirdiskSpaceRequired=DISCSPACEPLACEHOLDER
7*cdf0e10cSrcweirchecksum=CHECKSUMPLACEHOLDER
8*cdf0e10cSrcweir
9*cdf0e10cSrcweirEXTRACTONLY="no"
10*cdf0e10cSrcweirif [ "$1" = "-x" ]
11*cdf0e10cSrcweirthen
12*cdf0e10cSrcweir    EXTRACTONLY=yes
13*cdf0e10cSrcweirfi
14*cdf0e10cSrcweir
15*cdf0e10cSrcweir# Determining current platform
16*cdf0e10cSrcweir
17*cdf0e10cSrcweirplatform=`uname -s`
18*cdf0e10cSrcweir
19*cdf0e10cSrcweircase $platform in
20*cdf0e10cSrcweirSunOS)
21*cdf0e10cSrcweir  tail_prog="tail"
22*cdf0e10cSrcweir  ;;
23*cdf0e10cSrcweirLinux)
24*cdf0e10cSrcweir  tail_prog="tail -n"
25*cdf0e10cSrcweir  ;;
26*cdf0e10cSrcweir*)
27*cdf0e10cSrcweir  tail_prog="tail"
28*cdf0e10cSrcweir  ;;
29*cdf0e10cSrcweiresac
30*cdf0e10cSrcweir
31*cdf0e10cSrcweir# Asking for the unpack directory
32*cdf0e10cSrcweir
33*cdf0e10cSrcweirecho
34*cdf0e10cSrcweirecho "Select the directory in which to save the unpacked files. [$UNPACKDIR] "
35*cdf0e10cSrcweirread reply leftover
36*cdf0e10cSrcweirif [ "x$reply" != "x" ]
37*cdf0e10cSrcweirthen
38*cdf0e10cSrcweir  UNPACKDIR="$reply"
39*cdf0e10cSrcweirfi
40*cdf0e10cSrcweir
41*cdf0e10cSrcweirif [ -d $UNPACKDIR ]; then
42*cdf0e10cSrcweir    printf "Directory $UNPACKDIR already exists.\n"
43*cdf0e10cSrcweir    printf "Please select a new directory name.\n"
44*cdf0e10cSrcweir    exit 1
45*cdf0e10cSrcweirfi
46*cdf0e10cSrcweir
47*cdf0e10cSrcweir# Unpacking
48*cdf0e10cSrcweir
49*cdf0e10cSrcweirmkdir -m 700 $UNPACKDIR
50*cdf0e10cSrcweir
51*cdf0e10cSrcweirdiskSpace=`df -k $UNPACKDIR | $tail_prog -1 | awk '{if ( $4 ~ /%/) { print $3 } else { print $4 } }'`
52*cdf0e10cSrcweirif [ $diskSpace -lt $diskSpaceRequired ]; then
53*cdf0e10cSrcweir    printf "The selected drive does not have enough disk space available.\n"
54*cdf0e10cSrcweir    printf "PRODUCTNAMEPLACEHOLDER requires at least %s kByte.\n" $diskSpaceRequired
55*cdf0e10cSrcweir    exit 1
56*cdf0e10cSrcweirfi
57*cdf0e10cSrcweir
58*cdf0e10cSrcweirtrap 'rm -rf $UNPACKDIR; exit 1' HUP INT QUIT TERM
59*cdf0e10cSrcweir
60*cdf0e10cSrcweirif [ -x /usr/bin/sum ] ; then
61*cdf0e10cSrcweir    echo "File is being checked for errors ..."
62*cdf0e10cSrcweir
63*cdf0e10cSrcweir	sum=`$tail_prog +$linenum $0 | /usr/bin/sum`
64*cdf0e10cSrcweir    sum=`echo $sum | awk '{ print $1 }'`
65*cdf0e10cSrcweir
66*cdf0e10cSrcweir    if [ $sum != $checksum ]; then
67*cdf0e10cSrcweir		echo "The download file appears to be corrupted. Please download PRODUCTNAMEPLACEHOLDER again."
68*cdf0e10cSrcweir		exit 1
69*cdf0e10cSrcweir	fi
70*cdf0e10cSrcweirfi
71*cdf0e10cSrcweir
72*cdf0e10cSrcweirecho "Unpacking ..."
73*cdf0e10cSrcweir
74*cdf0e10cSrcweir$tail_prog +$linenum $0 | (cd $UNPACKDIR; tar xf -)
75*cdf0e10cSrcweir
76*cdf0e10cSrcweirecho "All files have been successfully unpacked."
77*cdf0e10cSrcweir
78*cdf0e10cSrcweirif [ "$EXTRACTONLY" != "yes" ]
79*cdf0e10cSrcweirthen
80*cdf0e10cSrcweir  if [ -f $UNPACKDIR/setup ]
81*cdf0e10cSrcweir  then
82*cdf0e10cSrcweir      chmod 775 $UNPACKDIR/setup
83*cdf0e10cSrcweir      $UNPACKDIR/setup
84*cdf0e10cSrcweir  fi
85*cdf0e10cSrcweirfi
86*cdf0e10cSrcweir
87*cdf0e10cSrcweirexit 0
88