Improved file organization

This commit is contained in:
root
2025-05-25 09:49:43 +00:00
parent 4d692b51b5
commit 58f0fe6adc
16 changed files with 286 additions and 228 deletions

View File

@@ -1,28 +1,40 @@
#!/bin/bash
TMP_FILE=$(mktemp)
TMP_OUT=$(mktemp)
TMP_USERS=$(mktemp)
# Ask for username
dialog --backtitle "Create SMB share" --inputbox "Enter share name:" 10 40 2>"$TMP_FILE"
# 1) Ask for share name
dialog --backtitle "Create SMB share" --inputbox "Enter share name (folder path):" 10 50 2>"$TMP_FILE"
SHARE_NAME=$(<"$TMP_FILE")
# Ask for password (input will be hidden)
dialog --backtitle "Create SMB share" --inputbox "Enter associated username:" 10 40 2>"$TMP_FILE"
# 2) 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 found by get_users_list.sh" 10 40
rm -f "$TMP_FILE" "$TMP_USERS" "$TMP_OUT"
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"
# 3) 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")
# 4) Call the external script to create the share
bash $SMB_TOOLS_PATH/functions/create_user_share.sh "$SHARE_NAME" "$USERNAME" >"$TMP_OUT" 2>&1
# 3) Call the external script and capture output
# adjust the path (“../add_smb_user.sh”) as needed
TMP_OUT=$(mktemp)
bash ./../create_user_share.sh "$SHARE_NAME" "$USERNAME" >"$TMP_OUT" 2>&1
# 4) Display the result (use --msgbox for short, --textbox for multiline)
# 5) Display the result
dialog --backtitle "Create SMB share" \
--title "Result" \
--textbox "$TMP_OUT" 20 60
rm -f "$TMP_OUT"
rm -f "$TMP_FILE"
# 6) Cleanup
rm -f "$TMP_FILE" "$TMP_USERS" "$TMP_OUT"

76
gui/dialog_share_remove.sh Executable file
View File

@@ -0,0 +1,76 @@
#!/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" >"$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"

View File

@@ -15,7 +15,7 @@ PASSWORD=$(<"$TMP_FILE")
# 3) Call the external script and capture output
# adjust the path (“../add_smb_user.sh”) as needed
TMP_OUT=$(mktemp)
bash ./../add_smb_user.sh "$USERNAME" "$PASSWORD" >"$TMP_OUT" 2>&1
bash $SMB_TOOLS_PATH/functions/add_smb_user.sh "$USERNAME" "$PASSWORD" >"$TMP_OUT" 2>&1
# 4) Display the result (use --msgbox for short, --textbox for multiline)
dialog --backtitle "Add SMB User" \

View File

@@ -1,20 +0,0 @@
#!/bin/bash
TMP_FILE=$(mktemp)
# 3) Call the external script and capture output
# adjust the path (“../add_smb_user.sh”) as needed
TMP_OUT=$(mktemp)
bash ./../list_smb_users.sh >"$TMP_OUT" 2>&1
# 4) Display the result (use --msgbox for short, --textbox for multiline)
dialog --backtitle "SMB Users" \
--title "SMB Users" \
--textbox "$TMP_OUT" 20 60
rm -f "$TMP_OUT"
# dialog --msgbox "User '$USERNAME' with given password would be created." 8 50
rm -f "$TMP_FILE"

View File

@@ -1,26 +1,36 @@
#!/bin/bash
TMP_FILE=$(mktemp)
TMP_USERS=$(mktemp)
TMP_OUT=$(mktemp)
# Ask for username
dialog --backtitle "Remove SMB User" --inputbox "Enter username to be removed:" 10 40 2>"$TMP_FILE"
# 1) Get the list of users
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"
exit 1
fi
# 2) Prepare user list for dialog --menu (username + empty description)
MENU_ITEMS=()
while read -r user; do
MENU_ITEMS+=("$user" "")
done < "$TMP_USERS"
# 3) Ask the user to select one from the list
dialog --backtitle "Remove SMB User" \
--menu "Select a user to remove:" 15 50 8 \
"${MENU_ITEMS[@]}" 2>"$TMP_FILE"
USERNAME=$(<"$TMP_FILE")
# 4) Run the removal script
bash $SMB_TOOLS_PATH/functions/remove_smb_user.sh "$USERNAME" >"$TMP_OUT" 2>&1
# 3) Call the external script and capture output
# adjust the path (“../add_smb_user.sh”) as needed
TMP_OUT=$(mktemp)
bash ./../remove_smb_user.sh "$USERNAME" >"$TMP_OUT" 2>&1
# 4) Display the result (use --msgbox for short, --textbox for multiline)
# 5) Show output
dialog --backtitle "Remove SMB User" \
--title "Result" \
--textbox "$TMP_OUT" 20 60
rm -f "$TMP_OUT"
# dialog --msgbox "User '$USERNAME' with given password would be created." 8 50
rm -f "$TMP_FILE"
# 6) Cleanup
rm -f "$TMP_FILE" "$TMP_USERS" "$TMP_OUT"

View File

@@ -10,10 +10,9 @@ while true; do
--menu "Choose an action:" 15 50 6 \
1 "Add User" \
2 "Remove User" \
3 "List Users" \
4 "Create Share" \
5 "Remove Share" \
6 "Exit" 2>"$TMP_FILE"
3 "Create Share" \
4 "Remove Share" \
5 "Exit" 2>"$TMP_FILE"
CHOICE=$(<"$TMP_FILE")
@@ -25,17 +24,12 @@ while true; do
./dialog_user_remove.sh
;;
3)
./dialog_user_list.sh
;;
4)
./dialog_share_create.sh
;;
5)
dialog --inputbox "Enter share name to remove:" 10 40 2>"$TMP_FILE"
SHARE=$(<"$TMP_FILE")
dialog --msgbox "Share '$SHARE' would be removed." 8 40
4)
./dialog_share_remove.sh
;;
6)
5)
break
;;
*)