#!/bin/sh
# (c) Jason W 2013 

. /etc/init.d/tc-functions
useBusybox
HERE=`pwd`
TCEDIR=/etc/sysconfig/tcedir
DEBINXDIR="$TCEDIR"/import/debinx
read DEBINX_SECURITY < /etc/sysconfig/tcedir/import/debinx/debinx_security
DEBINX_SECURITY="/etc/sysconfig/tcedir/import/debinx/$DEBINX_SECURITY"
read DEBINX < /etc/sysconfig/tcedir/import/debinx/debinx
DEBINX="/etc/sysconfig/tcedir/import/debinx/$DEBINX"
SCE="$1"
SCEDIR="$TCEDIR"/sce
BUILD=`getBuild`
if [ "$BUILD" == "x86" ]; then
	DEBBUILD="i386"
elif [ "$BUILD" == "armv7" ]; then
	DEBBUILD="armhf"
elif [ "$BUILD" == "x86_64" ]; then
	DEBBUILD="amd64"
fi
read SSMIRROR < /opt/tcemirror                                                                             
SSMIRROR="${SSMIRROR%/}/dCore/import"   

#if ! ps a | grep "/usr/bin/sce-update" | grep -v grep > /dev/null 2>&1; then
#	exit 1
#fi

if busybox mount | grep "/tmp/sceupdatetest" > /dev/null 2>&1; then
     busybox umount /tmp/sceupdatetest
fi
[ -f /tmp/sce.md5new ] && rm /tmp/sce.md5new
[ -f /tmp/.updatechanged ] && rm /tmp/.updatechanged
[ -f /tmp/.lstchanged ] && rm /tmp/.lstchanged
[ -f /tmp/file.lst ] && rm /tmp/file.lst
[ -f /tmp/ssupdates ] && rm /tmp/ssupdates
ls /tmp/*.deb2sce > /dev/null 2>&1 && rm /tmp/*.deb2sce
[ -f /tmp/.pkgprebuilt ] && rm /tmp/.pkgprebuilt
[ -f /tmp/.importmissing ] && rm /tmp/.importmissing
[ -f /tmp/.importnotneeded ] && rm /tmp/.importnotneeded
[ -f /tmp/.updateavailable ] && rm /tmp/.updateavailable
[ -f/tmp/.importupdates ] && rm /tmp/.importupdates
[ -d /tmp/work ] && rm -r /tmp/work
[ -f /tmp/sce.recommends ] && rm /tmp/sce.recommends
[ -f /tmp/sce.suggests ] && rm /tmp/sce.suggests
#[ -f /tmp/.updatemd5failed ] && rm /tmp/.updatemd5failed

exit_tcnet() {
	echo " "
	echo "${YELLOW}Warning:${NORMAL} Issue connecting to `cat /opt/tcemirror`, exiting.."
	exit 1
}


if [ ! -f "$SCEDIR"/"$SCE".sce ] && [ ! -f "$SCEDIR"/update/"$SCE".sce ]; then
  echo " "
  echo "${YELLOW}Warning:${NORMAL} "$SCE".sce does not exist, exiting.."
  exit 1
fi

echo "====  "$SCE" updates  ====" >> /tmp/updateavailable

if busybox mount | grep "/tmp/sceupdatetest " > /dev/null 2>&1; then
 busybox umount /tmp/sceupdatetest
fi
## Determine if SCE exists in SCE dir, SCE/update dir, or is mounted and then mount.
if [ -f "$SCEDIR"/update/"$SCE".sce ]; then
   [ -d /tmp/sceupdatetest ] || mkdir /tmp/sceupdatetest
   busybox mount "$SCEDIR"/update/"$SCE".sce /tmp/sceupdatetest
   DATADIR=/tmp/sceupdatetest/usr/local/sce/"$SCE"
   FILE=/tmp/sceupdatetest/usr/local/sce/"$SCE"/"$SCE".md5sum
   FILEDATA=/tmp/sceupdatetest/usr/local/sce/"$SCE"/"$SCE"-data.md5sum
   RECOMMENDS=/tmp/sceupdatetest/usr/local/sce/"$SCE"/recommends
   SUGGESTS=/tmp/sceupdatetest/usr/local/sce/"$SCE"/suggests
elif busybox mount | grep "/tmp/tcloop/$SCE " > /dev/null 2>&1; then
   DATADIR=/tmp/tcloop/"$SCE"/usr/local/sce/"$SCE"
   FILE=/tmp/tcloop/"$SCE"/usr/local/sce/"$SCE"/"$SCE".md5sum
   FILEDATA=/tmp/tcloop/"$SCE"/usr/local/sce/"$SCE"/"$SCE"-data.md5sum
   RECOMMENDS=/tmp/sceupdatetest/usr/local/sce/"$SCE"/recommends
   SUGGESTS=/tmp/sceupdatetest/usr/local/sce/"$SCE"/suggests
elif [ -f "$SCEDIR"/"$SCE".sce ]; then
   DATADIR=/tmp/sceupdatetest/usr/local/sce/"$SCE"
   [ -d /tmp/sceupdatetest ] || mkdir /tmp/sceupdatetest
   busybox mount "$SCEDIR"/"$SCE".sce /tmp/sceupdatetest
   FILE=/tmp/sceupdatetest/usr/local/sce/"$SCE"/"$SCE".md5sum
   FILEDATA=/tmp/sceupdatetest/usr/local/sce/"$SCE"/"$SCE"-data.md5sum
   RECOMMENDS=/tmp/sceupdatetest/usr/local/sce/"$SCE"/recommends
   SUGGESTS=/tmp/sceupdatetest/usr/local/sce/"$SCE"/suggests
fi
##
echo "$FILE" > /tmp/FILE

## Find if needed md5sum file inside SCE exists.
if [ ! -f "$FILE" ]; then
	echo ""$1" has no built in md5sum list, not updating." >> /tmp/updateavailable
	echo " " >> /tmp/updateavailable
	echo " " >> /tmp/updateavailable
	echo " "
	if busybox mount | grep "/tmp/sceupdatetest" > /dev/null 2>&1; then
		busybox umount /tmp/sceupdatetest
	fi
	[ -d /tmp/sceupdatetest ] && rmdir /tmp/sceupdatetest
	exit 0
fi
##

## Check to see if package is available for dCore port.
checkextrarepoexists() {
	awk -v package="Package: $1" -v build="$DEBBUILD" -v FIELD="$1: "  '
	BEGIN {
		RS=""
		FS="\n"
	}
	{
		if ($1 == package) {
			for (i=2; i <= NF; i++) {
				split($i,f,": ")

				if ( f[1] == "Architecture" ) {
					if ( f[2] == "all" )
						{}
					else if ( f[2] == build )
						{}
					else
						break
					}
				
				if ( f[1] == "Filename" )
					{ print f[2]; exit; }
					
			}
		} 

	} ' < "$DEBINX"
}
##

## Determine which repo the package will come from.
if [ -f "$SCEDIR"/"$SCE".sce.lst ]; then
	:
elif grep "^$SCE:" "$DEBINXDIR"/PKGPREBUILTDEP > /dev/null 2>&1; then
	:
elif grep "^Package: $SCE$" "$TCEDIR"/import/debinx/debinx.* > /dev/null 2>&1; then
	DEBINX=`grep "^Package: $SCE$" "$TCEDIR"/import/debinx/debinx* /dev/null | head -n 1 | cut -f1 -d:`
	if [ -z `checkextrarepoexists "$SCE"` ]; then
		echo "$SCE is an extra repo package not available for `version | cut -f1 -d:` "$BUILD", not updating.." >> /tmp/updateavailable
		echo " " >> /tmp/updateavailable
		echo " " >> /tmp/updateavailable
		exit 0
	fi
	read DEBINX < /etc/sysconfig/tcedir/import/debinx/debinx
	DEBINX="/etc/sysconfig/tcedir/import/debinx/$DEBINX"
elif grep -q "^Package: $SCE$" "$DEBINX_SECURITY" > /dev/null 2>&1; then
	:
elif grep -q "^Package: $SCE$" "$DEBINX" > /dev/null 2>&1; then
	:
elif grep -q "^$SCE:" "$DEBINXDIR"/PKGADDDEP; then
	:
else
	echo "$SCE can't be imported from any repo or existing list file, not updating.." >> /tmp/updateavailable
	echo " " >> /tmp/updateavailable
	echo " " >> /tmp/updateavailable
	exit 0
fi
##

## Make sure md5.txt exists and passes check
if [ -f "$SCEDIR"/"$SCE".sce.md5.txt ]; then
	cd "$SCEDIR"
	if md5sum -c "$SCE".sce.md5.txt > /dev/null 2>&1; then
		cd "$HERE"
	else
		echo "$SCE" >> /tmp/.sceupdatelist
		echo "$SCE" >>/tmp/.updatemd5failed
		echo "$SCE did not pass the md5sum check, needs re-importing." >> /tmp/updateavailable
		echo " " >> /tmp/updateavailable
		echo " " >> /tmp/updateavailable
		echo "$SCE" >> /tmp/.updatechecked
		cd "$HERE"
		exit 0
	fi
else
	echo "$SCE" >> /tmp/.sceupdatelist
	echo "$SCE" >>/tmp/.updatemd5failed
	echo "$SCE has no $SCE.md5.txt file, needs re-importing." >> /tmp/updateavailable
	echo " " >> /tmp/updateavailable
	echo " " >> /tmp/updateavailable
	echo "$SCE" >> /tmp/.updatechecked
	exit 0
fi
##

unset DEPLIST
		
[ -d /tmp/work ] && rm -r /tmp/work


if [ -f "$DATADIR"/"$SCE".dep ]; then
	DEP1=`md5sum "$DATADIR"/"$SCE".dep | cut -f1 -d" "`
	if [ -f /etc/sysconfig/tcedir/sce/"$SCE".sce.dep ]; then
		DEP2=`md5sum /etc/sysconfig/tcedir/sce/"$SCE".sce.dep | cut -f1 -d" "`
	else
		DEP2="0"
	fi
	if [ "$DEP1" != "$DEP2" ]; then
		echo ""$SCE".sce.dep changed and needs to be re-imported." >> /tmp/updateavailable
		#echo " " >> /tmp/updateavailable
		echo "Dep file when imported:" >> /tmp/updateavailable
		awk '{print "        " $0 }' "$DATADIR"/"$SCE".dep >> /tmp/updateavailable
		#echo " " >> /tmp/updateavailable	
		if [ -f /etc/sysconfig/tcedir/sce/"$SCE".sce.dep ]; then
			echo "Dep file now existing /etc/sysconfig/tcedir/sce/"$SCE".sce.dep:" >> /tmp/updateavailable
			awk '{print "        " $0 }' /etc/sysconfig/tcedir/sce/"$SCE".sce.dep >> /tmp/updateavailable 
		else
			echo "Dep file does not exist: /etc/sysconfig/tcedir/sce/"$SCE".sce.dep." >> /tmp/updateavailable
		fi
		echo " " >> /tmp/updateavailable
		echo " " >> /tmp/updateavailable
		echo "$1" >> /tmp/.sceupdatelist
		exit 0
	fi
fi

if [ -f "$DATADIR"/"$SCE".lst ]; then
	LST1=`md5sum "$DATADIR"/"$SCE".lst | cut -f1 -d" "`
	if [ -f /etc/sysconfig/tcedir/sce/"$SCE".sce.lst ]; then
		LST2=`md5sum /etc/sysconfig/tcedir/sce/"$SCE".sce.lst | cut -f1 -d" "`
	else
		LST2="0"
	fi
	if [ "$LST1" != "$LST2" ]; then
		echo ""$SCE".sce.lst changed and needs to be re-imported." >> /tmp/updateavailable
		#echo " " >> /tmp/updateavailable
		echo "List file when imported:" >> /tmp/updateavailable
		awk '{print "        " $0 }' "$DATADIR"/"$SCE".lst >> /tmp/updateavailable
		#echo " " >> /tmp/updateavailable	
		if [ -f /etc/sysconfig/tcedir/sce/"$SCE".sce.lst ]; then
			echo "List file now existing /etc/sysconfig/tcedir/sce/"$SCE".sce.lst:" >> /tmp/updateavailable
			awk '{print "        " $0 }' /etc/sysconfig/tcedir/sce/"$SCE".sce.lst >> /tmp/updateavailable
		else
			echo "List file does not exist: /etc/sysconfig/tcedir/sce/"$SCE".sce.lst." >> /tmp/updateavailable
		fi
		echo " " >> /tmp/updateavailable
		echo " " >> /tmp/updateavailable
		echo "$1" >> /tmp/.sceupdatelist
		exit 0
	fi
fi

## Use list file in SCE dir and get deps of those packages.
if [ -f "$TCEDIR"/sce/"$SCE".sce.lst ]; then
	for I in `cat "$TCEDIR"/sce/"$SCE".sce.lst`; do 
		pgrep sce-update > /dev/null 2>&1 || exit 0
		debGetDeps "$I" > /dev/null 2>&1
	done
	#for I in `cat "$FILE" | cut -f1 -d:`; do
	#	pgrep sce-update > /dev/null 2>&1 || exit 0
	#	debGetDeps "$I" > /dev/null 2>&1
	#done
		
else
	debGetDeps "$SCE" > /dev/null 2>&1
		#for I in `cat "$FILE" | cut -f1 -d:`; do
		#	pgrep sce-update > /dev/null 2>&1 || exit 0
		#	debGetDeps "$I" > /dev/null 2>&1
		#done
fi
##

## Get md5sum data and list of package dependencies.
for I in `ls /tmp/work/`; do
	debGetUpdateList "$I"
done 
##

if [ -f "$DATADIR"/recommends ]; then
	touch /tmp/"$1".recommended
fi

if [ -f "$DATADIR"/suggests ]; then
	touch /tmp/"$1".suggested
fi

## No longer useful with recommends and suggests options, but maybe in the future.
## Update if pacakges are no longer required that are in the main SCE or it's deps.
for I in `cat "$FILE" | cut -f1 -d:`; do
	if ! ls /tmp/work/"$I" > /dev/null 2>&1 && [ ! -f /tmp/.updatechanged ]; then
		echo "$I" >> /tmp/.importnotneeded
	fi
done
##

if [ -s /tmp/.importnotneeded ]; then
	for I in `cat /tmp/.importnotneeded | sort | uniq`; do 
		A=`grep "^$I;" /tmp/.importpkgtype | cut -f1 -d";"`
		echo ""$I"   "$A"   has been removed as a dependency by "$SCE".sce or it's SCE deps." >> /tmp/updateavailable
	done
	echo " " >> /tmp/updateavailable
	echo " " >> /tmp/updateavailable
	echo "$1" >> /tmp/.sceupdatelist
	exit 0
fi 

## No longer useful with recommends and suggests options, but maybe in the future.
for I in `ls /tmp/work/`; do
	if [ ! -s /tmp/work/"$I" ] && ! grep "^$I:" "$DEBINXDIR"/PREBUILTMD5SUMLIST > /dev/null 2>&1; then
		continue
	fi
	if ls "$DATADIR"/*.debs > /dev/null 2>&1; then
		if ! grep "^$I:" "$FILE" > /dev/null 2>&1; then
			if ! grep "^$I$" "$DATADIR"/*.debs > /dev/null 2>&1; then
				echo "$I" >> /tmp/.importmissing
			fi
		fi
	else
		if ! grep "^$I:" "$FILE" > /dev/null 2>&1; then
			echo "$I" >> /tmp/.importmissing
		fi
	fi
done

if [ -s /tmp/.importmissing ]; then
	for I in `cat /tmp/.importmissing | sort | uniq`; do 
		A=`grep "^$I;" /tmp/.importpkgtype | cut -f2 -d";"`
		echo ""$I"   "$A"   is a new dependency in "$SCE".sce or it's SCE deps." >> /tmp/updateavailable
	done  
	echo " " >> /tmp/updateavailable
	echo " " >> /tmp/updateavailable
	echo "$1" >> /tmp/.sceupdatelist
	exit 
fi



while read line; do 
	pgrep sce-update > /dev/null 2>&1 || exit 0
	E=`echo $line | cut -f1 -d:`
        if grep "^$E$" "$DATADIR"/*.debs > /dev/null 2>&1; then
			continue
	fi
	F=`echo $line | awk '{print $2}' | awk '{ if (a[$1]++ == 0) print $0; }'`
    	G=`grep "^$E:" "$FILE" | awk '{print $2}' | awk '{ if (a[$1]++ == 0) print $0; }'`
	if [ -z "$F" ]; then
		continue
	fi 
	#echo "$E: ""$F" >> /tmp/updateavailable
	#echo "$E: ""$G" >> /tmp/updateavailable
	## Update if md5sum of existing package and one on the server differ.
     	if [[ "$F" != "$G" ]] && ! grep "^$E$" "$DEBINXDIR"/PKGEXCLUDELIST > /dev/null 2>&1; then
     		echo "$E" >> /tmp/.importupdates
		[ ! -f /tmp/sceupdatefull ] && break
        fi
	##
	NAME="$E"
		## Get updated or deleted startup script or data files info.
		if grep "^$E-deb2sce:" "$DEBINXDIR"/PKGDATAFILEMD5SUMLIST > /dev/null 2>&1 && ! grep "^$E-deb2sce:" "$FILEDATA"; then
			echo ""$E"  New "$E".deb2sce startup script available." >>  /tmp/updateavailable
			echo " " >> /tmp/updateavailable
			echo "$E" >> /tmp/ssupdates
			[ ! -f /tmp/sceupdatefull ] && break
		elif grep "^$E-deb2sce:" "$DEBINXDIR"/PKGDATAFILEMD5SUMLIST > /dev/null 2>&1; then
			MD5SSNEW=`grep "^$E-deb2sce:" "$DEBINXDIR"/PKGDATAFILEMD5SUMLIST | awk '{print $2}' | awk '{ if (a[$1]++ == 0) print $0; }'`
			MD5SSOLD=`grep "^$E-deb2sce:" "$FILEDATA" | awk '{print $2}' | awk '{ if (a[$1]++ == 0) print $0; }'`
			if [ "$MD5SSNEW" != "$MD5SSOLD" ]; then
				if ! grep "^$E$" /tmp/ssupdates; then
					echo "$E" >> /tmp/ssupdates	
					echo ""$E"  Updated "$E".deb2sce startup script available." >>  /tmp/updateavailable 
					[ ! -f /tmp/sceupdatefull ] && break
				fi
			fi
		elif grep "^$E-deb2sce:" "$FILEDATA" && ! grep "^$E-deb2sce:" "$DEBINXDIR"/PKGDATAFILEMD5SUMLIST > /dev/null 2>&1; then
			MD5SSNEW=`grep "^$E-deb2sce:" "$DEBINXDIR"/PKGDATAFILEMD5SUMLIST | awk '{print $2}' | awk '{ if (a[$1]++ == 0) print $0; }'`
			MD5SSOLD=`grep "^$E-deb2sce:" "$FILEDATA" | awk '{print $2}' | awk '{ if (a[$1]++ == 0) print $0; }'`
			if ! grep "^$E-deb2sce:" "$DEBINXDIR"/PKGDATAFILEMD5SUMLIST > /dev/null 2>&1; then
				MD5SSNEW="0"
				echo "$E" >> /tmp/ssupdates	
				echo ""$E"  "$E".deb2sce startup script was removed in the repo." >>  /tmp/updateavailable
				[ ! -f /tmp/sceupdatefull ] && break
			elif [ "$MD5SSNEW" != "$MD5SSOLD" ]; then
				if ! grep "^$E$" /tmp/ssupdates; then
					echo "$E" >> /tmp/ssupdates 
					echo ""$E"  Updated "$E".deb2sce startup script available." >>  /tmp/updateavailable
				fi
				[ ! -f /tmp/sceupdatefull ] && break
			fi
		
		fi
		
		if ! grep "^$E-data:" "$DEBINXDIR"/PKGDATAFILEMD5SUMLIST > /dev/null 2>&1 && ! grep "^$E-data:" "$FILEDATA"; then
			continue
		fi
		
		if grep "^$E-data:" "$DEBINXDIR"/PKGDATAFILEMD5SUMLIST > /dev/null 2>&1; then
	        	MD5DATANEW=`grep "^$E-data:" "$DEBINXDIR"/PKGDATAFILEMD5SUMLIST | awk '{print $2}' | awk '{ if (a[$1]++ == 0) print $0; }'`
			MD5DATAOLD=`grep "^$E-data:" "$FILEDATA" | awk '{print $2}' | awk '{ if (a[$1]++ == 0) print $0; }'`
			if ! grep "^$E-data:" "$FILEDATA" > /dev/null 2>&1; then
				MD5DATAOLD="0"
			fi
	        	if [ "$MD5DATANEW" != "$MD5DATAOLD" ]; then
			 	if ! grep "^$E$" /tmp/ssupdates; then
					echo "$E" >> /tmp/ssupdates
			   		echo ""$E"  New "$E"-data.tar.gz extra files available." >>  /tmp/updateavailable 	
	        			[ ! -f /tmp/sceupdatefull ] && break
				fi	
			fi
		
		elif grep "^$E-data:" "$FILEDATA" > /dev/null 2>&1; then
	        	MD5DATANEW=`grep "^$E-data:" "$DEBINXDIR"/PKGDATAFILEMD5SUMLIST | awk '{print $2}' | awk '{ if (a[$1]++ == 0) print $0; }'`
			MD5DATAOLD=`grep "^$E-data:" "$FILEDATA" | awk '{print $2}' | awk '{ if (a[$1]++ == 0) print $0; }'`
			if ! grep "^$E-data:" "$DEBINXDIR"/PKGDATAFILEMD5SUMLIST > /dev/null 2>&1; then
				MD5DATANEW="0"
			fi
	        	if [ "$MD5DATANEW" != "$MD5DATAOLD" ]; then
			 	#if ! grep "^$E$" /tmp/ssupdates; then
					echo "$E" >> /tmp/ssupdates
			   		echo ""$E"  "$E"-data.tar.gz was removed on the server." >>  /tmp/updateavailable 
	        			[ ! -f /tmp/sceupdatefull ] && break
				#fi	
			fi
		fi	
		##
done < /tmp/sce.md5new


if [ -s /tmp/.importupdates ]; then
	for I in `cat /tmp/.importupdates | sort | uniq`; do
		if ! grep "^$I$" /tmp/.importmissing > /dev/null 2>&1; then
			if grep "^$I;" /tmp/.importpkgtype > /dev/null 2>&1; then
				A=`grep "^$I;" /tmp/.importpkgtype | cut -f2 -d";"`
				echo ""$I"   "$A" " >> /tmp/updateavailable
			fi
		fi
 	done  
	echo "$1" >> /tmp/.sceupdatelist
fi

if [ -s /tmp/ssupdates ]; then 
	echo "$1" >> /tmp/.sceupdatelist
fi

if [ ! -s /tmp/.importupdates ] && [ ! -s /tmp/ssupdates ] && [ ! -s /tmp/.importmissing ] && [ ! -s /tmp/.importnotneeded ]; then
	echo "None" >> /tmp/updateavailable
	MD5SUMDEBINX=`md5sum "$TCEDIR"/import/debinx/NEWDEBINX | cut -f1 -d" "`
	if [ -f "$SCEDIR"/update/"$SCE".sce ]; then
		echo "$MD5SUMDEBINX" | tee "$SCEDIR"/update/"$SCE".sce.debinx > /dev/null 2>&1
	elif [ -f "$SCEDIR"/"$SCE".sce ]; then
		echo "$MD5SUMDEBINX" | tee "$SCEDIR"/"$SCE".sce.debinx > /dev/null 2>&1
	fi
fi

echo " " >> /tmp/updateavailable
echo " " >> /tmp/updateavailable
echo "$SCE" >> /tmp/.updatechecked

busybox mount | grep /tmp/sceupdatetest > /dev/null 2>&1 && busybox umount /tmp/sceupdatetest
[ -f /tmp/sce.md5new ] &&   rm /tmp/sce.md5new
[ -f /tmp/.updatechanged ] && rm /tmp/.updatechanged
[ -f /tmp/.lstchanged ] && rm /tmp/.lstchanged
[ -f /tmp/ssupdates ] && rm /tmp/ssupdates
[ -f "/tmp/.*deb2sce" ] && rm /tmp/.*deb2sce
[ -f "/tmp/*.md5sum" ] && rm /tmp/*.md5sum
[ -f "/tmp/*.pkglist" ] && rm /tmp/*.pkglist
[ -f /tmp/.prebuiltmd5sumlist ] && rm /tmp/.prebuiltmd5sumlist
[ -f /tmp/.pkgextrafilemd5sumlist ] && rm /tmp/.pkgextrafilemd5sumlist
[ -f /tmp/.pkgprebuilt ] && rm /tmp/.pkgprebuilt
[ -f /tmp/.importmissing ] && rm /tmp/.importmissing
[ -f /tmp/.importnotneeded ] && rm /tmp/.importnotneeded
[ -f /tmp/.updateavailable ] && rm /tmp/.updateavailable
[ -f/tmp/.importupdates ] && rm /tmp/.importupdates
[ -f /tmp/sce.recommends ] && rm /tmp/sce.recommends
[ -f /tmp/sce.suggests ] && rm /tmp/sce.suggests

chmod 1777 /tmp
cd "$SCEDIR" || exit 0
