#!/bin/bash

case $1 in
    model)
        grep -oP 'Revision\s*:\s*\K[^ ]*' /proc/cpuinfo
        ;;
    serial)
        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
            cat /etc/hostname
            exit 0
        fi
        if [[ $(type -t hostname) == "file" ]]; then
            hostname
            exit 0
        fi
        if [[ $(type -t hostnamectl) == "file" ]]; then
            hostnamectl hostname
            exit 0
        fi
        ;;
    default-gateway)
        ip route | grep default | awk '{print $3}'
        ;;
    *)
        echo "Usage: $0 {model|serial|config_txt|password|hostname|default-gateway}"
        exit 1
        ;;
esac
