#!/bin/sh
# -*- mode: sh; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# vim: et sts=4 sw=4

#  SPDX-License-Identifier: LGPL-2.1+
#
#  Copyright © 2020 Collabora Ltd.
#  Copyright © 2020 Valve Corporation.
#
#  This file is part of steamos-customizations.
#
#  steamos-customizations is free software; you can redistribute it and/or
#  modify it under the terms of the GNU Lesser General Public License as
#  published by the Free Software Foundation; either version 2.1 of the License,
#  or (at your option) any later version.

udev_rules() {
    local partset
    partset="${1##*/}"

    cat <<EOF
#
# Automatically generated file; DO NOT EDIT.
# ${0##*/} $partset
#
EOF

    # must be after 60-persistent-storage.rules
    while read -r name partuuid
    do
        cat <<EOF
ENV{ID_PART_ENTRY_SCHEME}=="gpt", ENV{ID_PART_ENTRY_UUID}=="$partuuid", SYMLINK+="disk/by-partsets/$partset/$name"
EOF
    done <"$1"
}

mkdir -p /run/udev/rules.d
for file in "$@"
do
    udev_rules "$file" >"/run/udev/rules.d/90-steamos-partsets-${file##*/}.rules"
done
