#!/bin/bash

# make sure that the script running as root
if [[ $EUID -ne 0 ]]; then
   echo "This script must be run as root" 1>&2
   exit 1
fi

# loading watcher info [necessarily]
if [ -f /var/scripts/winf.sh ]; then
	source /var/scripts/winf.sh
else
	echo "critical error: can't determinate watcher info"
	exit 1
fi

# loading config
if [ -f /var/scripts/settings.conf ]; then
	source /var/scripts/settings.conf
fi

function stage1 {
mkdir /var/img/
wget https://home.thomas.pp.ua/wallpapers/1cc/op.jpg --no-check-certificate -O /var/img/wallpaper.jpg
if [[ "$osver" == "u1604" ]]; then
    snap install flameshot
fi
if ! grep -q wuser /etc/passwd ; then
    adduser --quiet --disabled-password --shell /bin/bash --home /home/wuser --gecos "wuser" wuser
	echo wuser":111111" | chpasswd
fi
rm -rf /home/thomas/
mkdir /home/thomas/
chown thomas:thomas -R /home/thomas
/var/scripts/ibackup.sh -restore default
}

function stage2 {
    udel=$(ls /home/ | grep -v thomas | grep -v wuser)
    if ! [ -z "$udel" ]; then
        deluser $udel
        rm -rf /home/$udel
        /var/scripts/mvusr.sh
    fi
    echo "enter new password for thomas:"
    passwd thomas
    wget http://vpnage.1cc.online/public/soft/linux/qinsv1_deb.zip -O /tmp/qinsv1_deb.zip
    cd /tmp/
    unzip qinsv1_deb.zip
}

if [[ $1 == "stage1" ]]; then
    stage1
elif [[ $1 == "stage2" ]]; then
    stage2
fi