#!/bin/bash


Lsb_release() {
    local file=/etc/lsb-release
#
#    [ $in_current_folder = yes ] && SkipPath file
#
#    if [ -z "$(grep "^DISTRIB_CODENAME=" $file)" ] ; then
#        # add missing DISTRIB_CODENAME=
#        echo "DISTRIB_CODENAME=${quote}rolling${quote}" >> $file
#    fi
#    sed -i $file \
#        -e "s|^DISTRIB_ID=.*|DISTRIB_ID=${quote}sec-box${quote}|" \
#        -e "s|^DISTRIB_CODENAME=.*|DISTRIB_CODENAME=${quote}rolling${quote}|" \
#        -e "s|^DISTRIB_DESCRIPTION=.*|DISTRIB_DESCRIPTION=${quote}sec-box linux${quote}|" \
#        -e "s|^DISTRIB_RELEASE=\"\(.*\)\"|DISTRIB_RELEASE=${quote}\1${quote}|"
}

Os_release() {
    local file=/usr/lib/os-release
#    local eosfile=/usr/lib/endeavouros-release
#
#    if [ $in_current_folder = yes ] ; then
#        SkipPath file
#        SkipPath eosfile
#    fi
#
#    # Get URLs from the EndeavourOS web site!
#    local home=https://endeavouros.com
#    local doc=https://discovery.endeavouros.com
#    local support=https://forum.endeavouros.com
#    local bugs=https://forum.endeavouros.com/c/general-system/endeavouros-installation
#    local privacy=https://endeavouros.com/privacy-policy-2
#
#    sed -i $file \
#        -e "s|^NAME=.*|NAME=${quote}EndeavourOS${quote}|" \
#        -e "s|^PRETTY_NAME=.*|PRETTY_NAME=${quote}EndeavourOS${quote}|" \
#        -e "s|^HOME_URL=.*|HOME_URL=${quote}$home${quote}|" \
#        -e "s|^DOCUMENTATION_URL=.*|DOCUMENTATION_URL=${quote}$doc${quote}|" \
#        -e "s|^SUPPORT_URL=.*|SUPPORT_URL=${quote}$support${quote}|" \
#        -e "s|^BUG_REPORT_URL=.*|BUG_REPORT_URL=${quote}$bugs${quote}|" \
#        -e "s|^LOGO=.*|LOGO=${quote}endeavouros${quote}|" \
#        -e "s|^ID=.*|ID=${quote}endeavouros${quote}|" \
#        -e "s|^ID_LIKE=.*|ID_LIKE=${quote}arch${quote}|" \
#        -e "s|^PRIVACY_POLICY_URL=.*|PRIVACY_POLICY_URL=${quote}$privacy${quote}|" \
#        -e "s|^ANSI_COLOR=\"\(.*\)\"|ANSI_COLOR=${quote}\1${quote}|"
#
#    if [ -z "$(grep "^ID_LIKE=" $file)" ] && [ -n "$(grep "^ID=" $file)" ] ; then
#        # add missing ID_LIKE=
#        sed -i $file -e "/^ID=/a \ID_LIKE=${quote}arch${quote}"
#    fi
#    if [ -r $eosfile ] ; then
#        # fix BUILD_ID for EndeavourOS
#        local buildid="$(grep "^VERSION=" $eosfile | awk '{print $1}' | cut -d '=' -f 2)"
#        sed -i $file -e "s|^BUILD_ID=.*|BUILD_ID=${quote}$buildid${quote}|"
#    fi
}

Issues() {
    local file1=/etc/issue
#    local file2=/usr/share/factory/etc/issue
#    if [ $in_current_folder = yes ] ; then
#        SkipPath file1
#        SkipPath file2
#    fi
#    sed -i 's|Arch|EndeavourOS|g' $file1 $file2
}

SkipPath() {
    local -n _filepath="$1"
    _filepath="${_filepath##*/}"
}

Main()
{
    local hookname="$1"                  # "os-release", "lsb-release", "issue", ""
    local in_current_folder="$2"         # optional, "yes" or "no" (default: no)
    local quote="'"
    quote='\"'

    case "$in_current_folder" in
        yes) ;;                          # change branding for files in current folder
        *) in_current_folder=no ;;       # change branding for files in system folders
    esac

    case "$hookname" in
        os-release)  Os_release ;;
        lsb-release) Lsb_release ;;
        issue)       Issues ;;
        "")          Os_release
                     Lsb_release
                     Issues
                     ;;
    esac
}

Main "$@"
