#!/bin/ash

tweak_system() {
	if [ "$mediadetected" = "cd" ]; then
		echo -e "#!/bin/sh\neject $livedevice\nsleep 5" > /mnt/usr/lib/systemd/system-shutdown/live-system.shutdown
		chmod +x /mnt/usr/lib/systemd/system-shutdown/live-system.shutdown
	fi

}

enable_persistent_connections() {
	cat > /mnt/etc/systemd/system/live-nm-connections.service << EOF
[unit]
Description="Live-System NetworkManager connections"
Before=NetworkManager.service

[Service]
Type=oneshot
ExecStart=/etc/rc.d/rc.nm-connections restore
ExecStop=/etc/rc.d/rc.nm-connections save
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target
EOF
	ln -sf ../live-nm-connections.service /mnt/etc/systemd/system/multi-user.target.wants
}

setup_locale() {
	if [ ! -z "$locale" ]; then
		if [ -z "$quiet" ]; then echo "Setting up locale ($locale)"; fi
		echo "LANG=$locale" >> /mnt/etc/locale.conf
	fi
}

setup_time() {
	if [ ! -z "$tz" ]; then
		if [ -f /mnt/usr/share/zoneinfo/$tz ]; then
			if [ -z "$quiet" ]; then echo "Setting up timezone ($tz)"; fi
			ln -sf /usr/share/zoneinfo/$tz /mnt/etc/localtime
		fi
	fi
	if [ ! -z "$hwc" ]; then
		if [ "$hwc" = "UTC" ] || [ "$hwc" = "localtime" ]; then
			if [ -z "$quiet" ]; then echo "Setting up hardware clock ($hwc)"; fi
			if [ "$hwc" == "UTC" ]; then
				rm -f /mnt/etc/adjtime
			else
				echo -e "0.0 0 0\n0\nLOCAL" > /mnt/etc/adjtime
			fi
		fi
	fi
}

setup_console_keymap() {
	if [ ! -z "$keymap" ]; then
		if [ -z "$quiet" ]; then echo "Setting up keymap ($keymap)"; fi
		echo "KEYMAP=$keymap" > /mnt/etc/vconsole.conf
	fi
}
