#!/bin/bash

case $1 in
    model)
        echo $(grep -oP 'Revision\s*:\s*\K[^ ]*' /proc/cpuinfo)
        ;;
    serial)
        echo $(grep -oP 'Serial\s*:\s*\K[^ ]*' /proc/cpuinfo)
        ;;
    config_txt)
        if [ -f /boot/firmware/config.txt ]; then
            echo "/boot/firmware/config.txt"
            exit 0
        fi
        if [ -f /boot/config.txt ]; then
            echo "/boot/config.txt"
            exit 0
        fi
        exit 1
        ;;
    password)
        PWSALT=`sudo grep pi /etc/shadow | awk -F\$ '{print $3}'`
        PWPI=`sudo grep pi /etc/shadow | awk -F: '{print $2}'`
        PWDFT=`mkpasswd -m sha-512 raspberry $PWSALT`
        if [ "$PWPI" = "$PWDFT" ]; then
            echo "default"
            exit 0
        else
            echo "user"
            exit 0
        fi
        ;;
    hostname)
        if [ -f /etc/hostname ]; then
            echo $(cat /etc/hostname)
            exit 0
        fi
        if [[ $(type -t hostname) == "file" ]]; then
            echo $(hostname)
            exit 0
        fi
        if [[ $(type -t hostnamectl) == "file" ]]; then
            echo $(hostnamectl hostname)
            exit 0
        fi
	;;
    *)
        echo "Usage: $0 {model|serial|config_txt|password|hostname}"
        exit 1
esac
