#!/bin/sh

unpkg(){
    local pkg=$1
    if [ -f $pkg ]; then
        tar -xf $pkg -C /
        /usr/sbin/syscontrol > /dev/null &
        /etc/init.d/dbus start
        /etc/init.d/avahi-daemon start
		killall -9 nginx > /dev/null
		/etc/init.d/nginx start
		killall -9 php-fpm > /dev/null
        /etc/init.d/php7-fpm start
        tosconf
    fi
}
sleep 2
local core=`uname -r`
try=0
while [ $try -lt 120 ]; do
    if [ -f /tmp/wget ]; then
        failed=`awk '/failed/' /tmp/wget`
        error=`awk '/ERROR/' /tmp/wget`
        [ -z "$failed" -a -z "$error" ] && break
        rm -f /tmp/wget
    fi
    wget -c http://app.tnas.online/patch.php?k=${core} -O /mnt/php7-all.tar -T 30 -t 3 -a /tmp/wget
    let try=try+1
    sleep 1
done

unpkg /mnt/php7-all.tar


