#!/bin/bash
echo "postinstall"

cp -f /tmp/postinstall/authorized_keys /myroot/.ssh
rc=$?
if /usr/bin/test $rc -ne 0
then
	echo "ELADERROR 52"
	exit 52
fi

cp -f /tmp/postinstall/sshshell /opt
rc=$?
if /usr/bin/test $rc -ne 0
then
	echo "ELADERROR 53"
	exit 53
fi

cp -f /tmp/postinstall/sshdaemon /opt
rc=$?
if /usr/bin/test $rc -ne 0
then
	echo "ELADERROR 54"
	exit 54
fi

cp -f /tmp/postinstall/myssh.service /etc/systemd/system
rc=$?
if /usr/bin/test $rc -ne 0
then
	echo "ELADERROR 55"
	exit 55
fi

chmod 755 /opt/sshshell
rc=$?
if /usr/bin/test $rc -ne 0
then
	echo "ELADERROR 56"
	exit 56
fi

chmod 755 /opt/sshdaemon
rc=$?
if /usr/bin/test $rc -ne 0
then
	echo "ELADERROR 57"
	exit 57
fi

chmod 600 /myroot/.ssh/id_rsa
rc=$?
if /usr/bin/test $rc -ne 0
then
	echo "ELADERROR 58"
	exit 58
fi

systemctl enable myssh.service
rc=$?
if /usr/bin/test $rc -ne 0
then
	echo "ELADERROR 59"
	exit 59
fi

cp /tmp/postinstall/my_prtscreen /usr/bin/
rc=$?
if /usr/bin/test $rc -ne 0
then
	echo "ELADERROR 60"
	exit 60
fi

cp /tmp/postinstall/remote /usr/bin/
rc=$?
if /usr/bin/test $rc -ne 0
then
	echo "ELADERROR 61"
	exit 61
fi

cp /tmp/postinstall/my_elad /usr/bin
rc=$?
if /usr/bin/test $rc -ne 0
then
	echo "ELADERROR 62"
	exit 62
fi

chmod 755 /usr/bin/remote /usr/bin/my_elad
rc=$?
if /usr/bin/test $rc -ne 0
then
	echo "ELADERROR 63"
	exit 63
fi

cp /tmp/postinstall/my_eladip /usr/bin
rc=$?
if /usr/bin/test $rc -ne 0
then
	echo "ELADERROR 82"
	exit 82
fi

chmod 755 /usr/bin/remote /usr/bin/my_eladip
rc=$?
if /usr/bin/test $rc -ne 0
then
	echo "ELADERROR 83"
	exit 83
fi

chmod 755 /usr/bin/my_prtscreen
rc=$?
if /usr/bin/test $rc -ne 0
then
	echo "ELADERROR 64"
	exit 64
fi

cp -f /tmp/postinstall/getpack.sh /opt/DuoArt
rc=$?
if /usr/bin/test $rc -ne 0
then
	echo "ELADERROR 65"
	exit 65
fi

cp -f /tmp/postinstall/getpack2.sh /opt/DuoArt
rc=$?
if /usr/bin/test $rc -ne 0
then
	echo "ELADERROR 66"
	exit 66
fi

my_set_rw.txt
rc=$?
if /usr/bin/test $rc -ne 0
then
	echo "ELADERROR 67"
	exit 67
fi


cp /tmp/postinstall/ventolaSSB.txt /opt/set
rc=$?
if /usr/bin/test $rc -ne 0
then
	echo "ELADERROR 68"
	exit 68
fi

cp /tmp/postinstall/ventola.txt /opt/set
rc=$?
if /usr/bin/test $rc -ne 0
then
	echo "ELADERROR 69"
	exit 69
fi
my_set_rw.txt


cp -f /tmp/postinstall/sysctl.conf /etc
rc=$?
if /usr/bin/test $rc -ne 0
then
	echo "ELADERROR 70"
	exit 69
fi

if /usr/bin/test `/usr/bin/aplay -l | grep 'card 1' | grep -v FDM-DUO | wc -l` = 1
then
	cp -f /tmp/postinstall/myamixer+ /usr/bin/myamixer
else
	cp -f /tmp/postinstall/myamixer /usr/bin
fi
rc=$?
if /usr/bin/test $rc -ne 0
then
	echo "ELADERROR 73"
	exit 73
fi

chmod 755 /usr/bin/myamixer
rc=$?
if /usr/bin/test $rc -ne 0
then
	echo "ELADERROR 74"
	exit 74
fi

if test -f /var/lib/alsa/asound.state
then
	chattr -i /var/lib/alsa/asound.state
	rc=$?
	if /usr/bin/test $rc -ne 0
	then
		echo "ELADERROR 77"
		exit 77
	fi
fi

if /usr/bin/test `/usr/bin/aplay -l | grep 'card 1' | grep -v FDM-DUO | wc -l` = 1
then
	cp -f /tmp/postinstall/asound.state+ /var/lib/alsa/asound.state
else
	cp -f /tmp/postinstall/asound.state /var/lib/alsa
fi
rc=$?
if /usr/bin/test $rc -ne 0
then
	echo "ELADERROR 75"
	exit 75
fi

chmod 444 /var/lib/alsa/asound.state
rc=$?
if /usr/bin/test $rc -ne 0
then
	echo "ELADERROR 76"
	exit 76
fi

chattr +i /var/lib/alsa/asound.state
rc=$?
if /usr/bin/test $rc -ne 0
then
	echo "ELADERROR 77"
	exit 77
fi

chmod 777 /opt/DuoArt/getpack.sh
rc=$?
if /usr/bin/test $rc -ne 0
then
	echo "ELADERROR 78"
	exit 78
fi

chmod 777 /opt/DuoArt/getpack2.sh
rc=$?
if /usr/bin/test $rc -ne 0
then
	echo "ELADERROR 79"
	exit 79
fi
if test -f /etc/network/interfaces && ! test -h /etc/network/interfaces
then
	my_set_rw.txt
	mv /etc/network/interfaces /opt/set
	ln -s /opt/set/interfaces /etc/network/interfaces
	my_set_ro.txt
fi

if /usr/bin/test `/usr/bin/aplay -l | grep 'card 1' | grep -v FDM-DUO | wc -l` = 1
then
	cp -f /tmp/postinstall/00-ELAD.rules+ /etc/udev/rules.d/00-ELAD.rules
else
	cp -f /tmp/postinstall/00-ELAD.rules /etc/udev/rules.d/
fi 
rc=$?
if /usr/bin/test $rc -ne 0
then
	echo "ELADERROR 81"
	exit 81
fi

/bin/sync
rc=$?
if /usr/bin/test $rc -ne 0
then
	echo "ELADERROR 80"
	exit 80
fi
sleep 2

exit 0
