#!/bin/bash

# Pearl APTus Update updates package list and displays
# information that some updates are available
# Created by Paweł "pavroo" Pijanowski 2017/06/15
# Copyright 2017-2019 under the GNU GPL2 License
# Last update 2019/09/08

if [ "$1" = "simulate" ]; then
	# check out connection to debian server
	PINGTEST0=$(ping -c 1 debian.org | grep [0-9])
	if [ -f /tmp/pearl-ping ]; then
		rm -f /tmp/pearl-ping
	fi
	if [ "$PINGTEST0" = "" ]; then
		echo "failed" >> /tmp/pearl-ping
		exit 1	
	else
		echo "ok" >> /tmp/pearl-ping
	fi

	# preper working dir
	if [ -d /tmp/aptus-update ]; then
		rm -rf /tmp/aptus-update
	fi
	mkdir -p /tmp/aptus-update

	# do the job
	apt-get update
	apt-get -u dist-upgrade --assume-no >> /tmp/aptus-update/checkout
	sed -i '1,4d' /tmp/aptus-update/checkout
	sed -i '$ d' /tmp/aptus-update/checkout
	sed -i '$ d' /tmp/aptus-update/checkout
fi

if [ "$1" = "clean" ]; then
	if [ -d /tmp/aptus-update ]; then
		rm -rf /tmp/aptus-update
	fi
fi

exit 0
