#!/bin/bash TMP_FILE=$(mktemp) TMP_OUT=$(mktemp) TMP_USERS=$(mktemp) TMP_SHARES=$(mktemp) ######################################################################################### # SHOW USERS LIST # Ask to select a user ######################################################################################### # Retrieve list of users from external script bash $SMB_TOOLS_PATH/functions/list_smb_users.sh > "$TMP_USERS" if [ ! -s "$TMP_USERS" ]; then dialog --msgbox "No users" 10 40 rm -f "$TMP_FILE" "$TMP_USERS" "$TMP_OUT" "$TMP_SHARES" exit 1 fi # Format list for dialog menu: convert each username into a pair (tag + description) MENU_ITEMS=() while read -r user; do MENU_ITEMS+=("$user" "") # empty description done < "$TMP_USERS" # Ask for username via a menu dialog --backtitle "Create SMB share" \ --menu "Select associated username:" 15 50 8 \ "${MENU_ITEMS[@]}" 2>"$TMP_FILE" USERNAME=$(<"$TMP_FILE") ######################################################################################### # SHOW SHARES LIST # Ask to select a share assigned to the selected user ######################################################################################### # Retrieve list of users from external script bash $SMB_TOOLS_PATH/functions/list_smb_shares.sh $USERNAME> "$TMP_SHARES" if [ ! -s "$TMP_SHARES" ]; then dialog --msgbox "No shares associated with the user" 10 40 rm -f "$TMP_FILE" "$TMP_USERS" "$TMP_OUT" "$TMP_SHARES" exit 1 fi # Format list for dialog menu: convert each username into a pair (tag + description) MENU_ITEMS=() while read -r share; do MENU_ITEMS+=("$share" "") # empty description done < "$TMP_SHARES" # Ask for username via a menu dialog --backtitle "Create SMB share" \ --menu "Select associated username:" 15 50 8 \ "${MENU_ITEMS[@]}" 2>"$TMP_FILE" SHARE=$(<"$TMP_FILE") ######################################################################################### # REMOVE SELECTED SHARE ######################################################################################### # Call the external script to create the share bash $SMB_TOOLS_PATH/functions/remove_share.sh "$SHARE" "$USERNAME" >"$TMP_OUT" 2>&1 # Display the result dialog --backtitle "Remove SMB share" \ --title "Result" \ --textbox "$TMP_OUT" 20 60 # Cleanup rm -f "$TMP_FILE" "$TMP_USERS" "$TMP_OUT" "$TMP_SHARES"