#!/bin/sh
# SPDX-FileCopyrightText: 2018 Harald Sitter <sitter@kde.org>
# SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL

# Hack...
# Undo calamares-oem-uid

set -ex

ROOT=$1

# reinstate login.defs and reset user uid & gid to 1000
mv $ROOT/etc/login.defs.oem $ROOT/etc/login.defs

# ... and also do some special modifications to configure the oem user
mkdir -p $ROOT/home/oem/Desktop
ln -s ../../../calamares/oem-prepare/oem-prepare.desktop $ROOT/home/oem/Desktop/oem-prepare.desktop
# Make sure the oem user (900) can clean up this file!
chown -Rv 60000 $ROOT/home/oem/Desktop/

kwriteconfig6 --file $ROOT/etc/sddm.conf --group Autologin --key Relogin --type bool true
kwriteconfig6 --file $ROOT/etc/sddm.conf --group Autologin --key User oem
kwriteconfig6 --file $ROOT/etc/sddm.conf --group Autologin --key Session plasma.desktop

# NB: Mind the check in calamares-oem-prepare2 when changing this!
cat << CONF >>$ROOT/etc/polkit-1/localauthority/50-local.d/99-oem-nopasswd.pkla
[oem User No Password]
Identity=unix-user:oem
Action=*
ResultAny=yes
ResultInactive=yes
ResultActive=yes
CONF
chmod 664 $ROOT/etc/polkit-1/localauthority/50-local.d/99-oem-nopasswd.pkla
