#!/bin/bash

list_dirs_and_files() {
    local MOUNT="$1"

    # 固定目录列表
    local DIR_LIST=(
        "/opt"
        "/"
        "/root"
        "/home/administrator"
        "/home"
        "/etc"
        "/var/lib"
        "/usr/local/share"
        "/usr/src"
        "/var/log"
    )

    echo "===== 目录和文件列表 ====="
    for d in "${DIR_LIST[@]}"; do
        local path="$MOUNT$d"
        echo "$d:"

        if [ ! -d "$path" ]; then
            echo "  (不存在)"
            echo
            continue
        fi

        local dirs=()
        local files=()
        for entry in "$path"/* "$path"/.*; do
            [ ! -e "$entry" ] && continue
            name="${entry##*/}"
            [ "$name" == "." ] || [ "$name" == ".." ] && continue
            if [ -d "$entry" ]; then
                dirs+=("$name")
            else
                files+=("$name")
            fi
        done

        # 输出目录列表
        echo "  目录: ${dirs[*]}"
        # 输出文件列表
        echo "  文件: ${files[*]}"
        echo
    done
}

show_bash_history() {
    local MOUNT="$1"
    local users=("root" "administrator")

    for u in "${users[@]}"; do
        local hist_file="$MOUNT/home/$u/.bash_history"
        if [ "$u" == "root" ]; then
            hist_file="$MOUNT/root/.bash_history"
        fi

        echo "===== $u 的 Bash 历史记录 ====="
        if [ -f "$hist_file" ]; then
            cat "$hist_file"
        else
            echo "(未找到历史记录文件)"
        fi
        echo
    done
}

# 主程序
MOUNT_POINT="$1"
if [ -z "$MOUNT_POINT" ]; then
    echo "Usage: $0 <mount_point>"
    exit 1
fi

list_dirs_and_files "$MOUNT_POINT"
show_bash_history "$MOUNT_POINT"
