#!/bin/bash

if [ -e /tmp/.kylin-postactions-runned ];then
  exit 0
fi

# grub-mkconfig -o /boot/efi/EFI/grub2/grub.cfg
# grub-mkconfig -o /boot/grub/grub.cfg-2
if [ ! -e /boot/efi/EFI/boot/bootaa64.efi ] && [ -e /boot/efi/EFI/kylin/grubaa64.efi ];then
  mkdir -p /boot/efi/EFI/boot
  cp /boot/efi/EFI/kylin/grubaa64.efi /boot/efi/EFI/boot/bootaa64.efi 
fi


# ssh-keygen -t rsa -P '' -f /etc/ssh/ssh_host_rsa_key
# ssh-keygen -t dsa -P '' -f /etc/ssh/ssh_host_dsa_key
# ssh-keygen -t ecdsa -P '' -f /etc/ssh/ssh_host_ecdsa_key
# ssh-keygen -t ed25519 -P '' -f /etc/ssh/ssh_host_ed25519_key
sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/g' /etc/ssh/sshd_config

DISABLE_SERVICE="dbus
	mountdebugfs
	mysql
	nfs-config
	nfs-idmapd
	nfs-mountd
	nfs-server
	nmbd
	open-iscsi
	polkitd
	rpcbind
	samba-ad-dc
	smartd
	smbd
	tftpd-hpa
	tomcat7
	vsftpd
	php7.0-fpm
	isc-dhcp-server
	mdadm
	wpa_supplicant
	multipath-tools
	multipath-tools-boot
	ufw
	apache2
	ntp
	bind9
	wpa_supplicant
"
echo Some service need not autostart on boot: $DISABLE_SERVICE
for service in $DISABLE_SERVICE ; do
	echo -n Disable service: $service "  "
	systemctl disable $service >/dev/null 2>&1
	if [ $? -eq 0 ] ; then
		echo Success
	else
		echo Failed
	fi
done

sed -i '/ib_iser/d' /lib/modules-load.d/open-iscsi.conf
sed -i 's/ntp.ubuntu.com/time.pool.aliyun.com/g' /etc/default/ntpdate
rm -rf /etc/network/if-up.d/ntpdate
rm -rf /etc/modules-load.d/cups-filters.conf

#huawei boot
# rm -rf /boot/*
# mkdir /tmp_kylin
# tar xf /opt/boot.tar.gz -C /tmp_kylin
# cp -r /tmp_kylin/boot/* /boot/
# sync
# rm -rf /opt/boot.tar.gz  /tmp_kylin
sync


depmod -a

touch /tmp/.kylin-postactions-runned
