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

# Hack...
# This hack allows us to not break with the expecation that the default/first user will be UID 1000.
# Since calamares doesn't allow forcing a uid we'll implcitly move the auto-ranges so the oem user is created at uid 60000.
# useradd adds a user uid even if we set the uid_min to a system uid (eg 900) as we are adding a user account.
# As oem user has the maximum uid & gid of 60000, the new installed on first boot will receive the reset min id and gid of 1000.
# This this hack is undone in a calamares-oem-uid-undo-and-configure after the user has been created.
# EndHack...

set -ex

ROOT=$1

cp $ROOT/etc/login.defs $ROOT/etc/login.defs.oem

sed -i 's%UID_MIN.*1000%UID_MIN 60000%g' $ROOT/etc/login.defs
sed -i 's%GID_MIN.*1000%GID_MIN 60000%g' $ROOT/etc/login.defs
