#!/bin/bash

Lsb_release() {
    local file=/etc/lsb-release

    if [[ -z "`grep "^DISTRIB_RELEASE=" $file`" ]] ; then
        # add missing DISTRIB_RELEASE=
        echo "DISTRIB_RELEASE=rolling" >> "$file"
    fi
    sed -i "$file" \
        -e 's|^DISTRIB_ID=.*$|DISTRIB_ID=tuxOS|' \
        -e 's|^DISTRIB_RELEASE=.*$|DISTRIB_RELEASE=rolling|' \
        -e 's|^DISTRIB_DESCRIPTION=.*$|DISTRIB_DESCRIPTION=\"tuxOS\"|'
}

Os_release() {
    local file=/usr/lib/os-release

    sed -i "$file" \
        -e 's|^NAME=.*$|NAME=\"tuxOS\"|' \
        -e 's|^PRETTY_NAME=.*$|PRETTY_NAME=\"tuxOS\"|' \
        -e 's|^ID=.*$|ID=tuxOS|' \
        -e 's|^ID_LIKE=.*$|ID_LIKE=arch|' \
        -e 's|^BUILD_ID=.*$|BUILD_ID=rolling|' \
        -e 's|^HOME_URL=.*$|HOME_URL=\"https://github.com/0xtux/tuxOS\"|' \
        -e 's|^DOCUMENTATION_URL=.*$|DOCUMENTATION_URL=\"https://github.com/0xtux/tuxOS/wiki\"|' \
        -e 's|^SUPPORT_URL=.*$|SUPPORT_URL=\"https://github.com/0xtux/tuxOS\"|' \
        -e 's|^BUG_REPORT_URL=.*$|BUG_REPORT_URL=\"https://github.com/0xtux/tuxOS/issues\"|' \
        -e 's|^LOGO=.*$|LOGO=tuxOS|'

    if [ -z "$(grep "^ID_LIKE=" $file)" ] && [ -n "$(grep "^ID=" $file)" ] ; then
        # add missing ID_LIKE=
        sed -i $file -e '/^ID=/a \ID_LIKE=arch'
    fi

	# fix issue file
    sed -i 's|Arch Linux|tuxOS|g' /etc/issue /usr/share/factory/etc/issue
}

Main()
{
    local hookname="$1"

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

Main "$@"
