1cdf0e10cSrcweir#!/bin/sh 2*9f22d7c2SAndrew Rist# ************************************************************* 3*9f22d7c2SAndrew Rist# 4*9f22d7c2SAndrew Rist# Licensed to the Apache Software Foundation (ASF) under one 5*9f22d7c2SAndrew Rist# or more contributor license agreements. See the NOTICE file 6*9f22d7c2SAndrew Rist# distributed with this work for additional information 7*9f22d7c2SAndrew Rist# regarding copyright ownership. The ASF licenses this file 8*9f22d7c2SAndrew Rist# to you under the Apache License, Version 2.0 (the 9*9f22d7c2SAndrew Rist# "License"); you may not use this file except in compliance 10*9f22d7c2SAndrew Rist# with the License. You may obtain a copy of the License at 11*9f22d7c2SAndrew Rist# 12*9f22d7c2SAndrew Rist# http://www.apache.org/licenses/LICENSE-2.0 13*9f22d7c2SAndrew Rist# 14*9f22d7c2SAndrew Rist# Unless required by applicable law or agreed to in writing, 15*9f22d7c2SAndrew Rist# software distributed under the License is distributed on an 16*9f22d7c2SAndrew Rist# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17*9f22d7c2SAndrew Rist# KIND, either express or implied. See the License for the 18*9f22d7c2SAndrew Rist# specific language governing permissions and limitations 19*9f22d7c2SAndrew Rist# under the License. 20*9f22d7c2SAndrew Rist# 21*9f22d7c2SAndrew Rist# ************************************************************* 22cdf0e10cSrcweir 23cdf0e10cSrcweirlinenum=LINENUMBERPLACEHOLDER 24cdf0e10cSrcweir 25cdf0e10cSrcweirUNPACKDIR=/var/tmp/unpack_PRODUCTNAMEPLACEHOLDER 26cdf0e10cSrcweirdiskSpaceRequired=DISCSPACEPLACEHOLDER 27cdf0e10cSrcweirchecksum=CHECKSUMPLACEHOLDER 28cdf0e10cSrcweir 29cdf0e10cSrcweirEXTRACTONLY="no" 30cdf0e10cSrcweirif [ "$1" = "-x" ] 31cdf0e10cSrcweirthen 32cdf0e10cSrcweir EXTRACTONLY=yes 33cdf0e10cSrcweirfi 34cdf0e10cSrcweir 35cdf0e10cSrcweir# Determining current platform 36cdf0e10cSrcweir 37cdf0e10cSrcweirplatform=`uname -s` 38cdf0e10cSrcweir 39cdf0e10cSrcweircase $platform in 40cdf0e10cSrcweirSunOS) 41cdf0e10cSrcweir tail_prog="tail" 42cdf0e10cSrcweir ;; 43cdf0e10cSrcweirLinux) 44cdf0e10cSrcweir tail_prog="tail -n" 45cdf0e10cSrcweir ;; 46cdf0e10cSrcweir*) 47cdf0e10cSrcweir tail_prog="tail" 48cdf0e10cSrcweir ;; 49cdf0e10cSrcweiresac 50cdf0e10cSrcweir 51cdf0e10cSrcweir# Asking for the unpack directory 52cdf0e10cSrcweir 53cdf0e10cSrcweirecho 54cdf0e10cSrcweirecho "Select the directory in which to save the unpacked files. [$UNPACKDIR] " 55cdf0e10cSrcweirread reply leftover 56cdf0e10cSrcweirif [ "x$reply" != "x" ] 57cdf0e10cSrcweirthen 58cdf0e10cSrcweir UNPACKDIR="$reply" 59cdf0e10cSrcweirfi 60cdf0e10cSrcweir 61cdf0e10cSrcweirif [ -d $UNPACKDIR ]; then 62cdf0e10cSrcweir printf "Directory $UNPACKDIR already exists.\n" 63cdf0e10cSrcweir printf "Please select a new directory name.\n" 64cdf0e10cSrcweir exit 1 65cdf0e10cSrcweirfi 66cdf0e10cSrcweir 67cdf0e10cSrcweir# Unpacking 68cdf0e10cSrcweir 69cdf0e10cSrcweirmkdir -m 700 $UNPACKDIR 70cdf0e10cSrcweir 71cdf0e10cSrcweirdiskSpace=`df -k $UNPACKDIR | $tail_prog -1 | awk '{if ( $4 ~ /%/) { print $3 } else { print $4 } }'` 72cdf0e10cSrcweirif [ $diskSpace -lt $diskSpaceRequired ]; then 73cdf0e10cSrcweir printf "The selected drive does not have enough disk space available.\n" 74cdf0e10cSrcweir printf "PRODUCTNAMEPLACEHOLDER requires at least %s kByte.\n" $diskSpaceRequired 75cdf0e10cSrcweir exit 1 76cdf0e10cSrcweirfi 77cdf0e10cSrcweir 78cdf0e10cSrcweirtrap 'rm -rf $UNPACKDIR; exit 1' HUP INT QUIT TERM 79cdf0e10cSrcweir 80cdf0e10cSrcweirif [ -x /usr/bin/sum ] ; then 81cdf0e10cSrcweir echo "File is being checked for errors ..." 82cdf0e10cSrcweir 83cdf0e10cSrcweir sum=`$tail_prog +$linenum $0 | /usr/bin/sum` 84cdf0e10cSrcweir sum=`echo $sum | awk '{ print $1 }'` 85cdf0e10cSrcweir 86cdf0e10cSrcweir if [ $sum != $checksum ]; then 87cdf0e10cSrcweir echo "The download file appears to be corrupted. Please download PRODUCTNAMEPLACEHOLDER again." 88cdf0e10cSrcweir exit 1 89cdf0e10cSrcweir fi 90cdf0e10cSrcweirfi 91cdf0e10cSrcweir 92cdf0e10cSrcweirecho "Unpacking ..." 93cdf0e10cSrcweir 94cdf0e10cSrcweir$tail_prog +$linenum $0 | (cd $UNPACKDIR; tar xf -) 95cdf0e10cSrcweir 96cdf0e10cSrcweirecho "All files have been successfully unpacked." 97cdf0e10cSrcweir 98cdf0e10cSrcweirif [ "$EXTRACTONLY" != "yes" ] 99cdf0e10cSrcweirthen 100cdf0e10cSrcweir if [ -f $UNPACKDIR/setup ] 101cdf0e10cSrcweir then 102cdf0e10cSrcweir chmod 775 $UNPACKDIR/setup 103cdf0e10cSrcweir $UNPACKDIR/setup 104cdf0e10cSrcweir fi 105cdf0e10cSrcweirfi 106cdf0e10cSrcweir 107cdf0e10cSrcweirexit 0 108