#!/bin/bash

set -e

if [[ "${is_minimal}" = "true" ]]; then
    return 0
elif [[ "${is_ghost}" = "true" ]]; then
    return 0
elif [[ "${is_oem_mode}" = "false" ]]; then
    return 0
fi

#if [[ -f /usr/share/kylin-os-installer/data/oem-config.service ]]; then
#    cp -a /usr/share/kylin-os-installer/data/oem-config.service /lib/systemd/system
#    cp -a /usr/share/kylin-os-installer/data/oem-config.target /lib/systemd/system
#    /bin/systemctl enable oem-config.service
#    /bin/systemctl enable oem-config.target
#
#fi

oem_mode=
if grep -q 'test-mode' /proc/cmdline; then
    oem_mode="oem-automatic"
    # 拷贝自定义的配置
    if [[ -f /cdrom/kyple-installer.cfg ]]; then
        cp /cdrom/kyple-installer.cfg /usr/share/kylin-os-installer/ky-installer.cfg
        echo 'test-mode=true' >>/usr/share/kylin-os-installer/ky-installer.cfg
    fi
else
    oem_mode="oem"
fi

if [[ "${is_990_9a0}" = "true" ]]; then
    sed -i "s/kylin-os-installer/kylin-os-installer-${oem_mode}/" /usr/bin/start-installer
else
    cp -a /usr/share/applications/kylin-os-installer.desktop /etc/xdg/autostart
    sed -i "/Exec/d" /etc/xdg/autostart/kylin-os-installer.desktop
    echo "Exec=/usr/bin/kylin-os-installer-${oem_mode}" >>/etc/xdg/autostart/kylin-os-installer.desktop

    /bin/systemctl disable kylin-os-installer
fi

# 删除用户与重启 lightdm
if [[ -f /usr/share/kylin-os-installer/data/delete-oem-user.service ]]; then
    cp -a /usr/share/kylin-os-installer/data/delete-oem-user.service /lib/systemd/system
    /bin/systemctl disable delete-oem-user.service
fi
