Compare commits
No commits in common. "main" and "cli" have entirely different histories.
@ -12,10 +12,13 @@ fi
|
||||
USERNAME="$1"
|
||||
PASSWORD="$2"
|
||||
|
||||
# If no username or password provided, exit with error
|
||||
if [[ -z "$USERNAME" || -z "$PASSWORD" ]]; then
|
||||
echo "Usage: $0 <username> <password>"
|
||||
exit 1
|
||||
if [[ -z "$USERNAME" ]]; then
|
||||
read -p "Enter username: " USERNAME
|
||||
fi
|
||||
|
||||
if [[ -z "$PASSWORD" ]]; then
|
||||
read -s -p "Enter password: " PASSWORD
|
||||
echo
|
||||
fi
|
||||
|
||||
# Create system user without extra fields
|
||||
@ -35,12 +38,3 @@ if [[ $? -eq 0 ]]; then
|
||||
else
|
||||
echo "Failed to add Samba user."
|
||||
fi
|
||||
|
||||
log_file="$SMB_TOOLS_PATH/filebrowser/addusers.txt"
|
||||
|
||||
if [ -f "$log_file" ]; then
|
||||
echo "$USERNAME:$PASSWORD" >> "$log_file"
|
||||
fi
|
||||
|
||||
# Non-blocking docker restart
|
||||
docker restart filebrowser </dev/null &>/dev/null &
|
7
aliases.sh
Normal file
7
aliases.sh
Normal file
@ -0,0 +1,7 @@
|
||||
alias smbtools_user_add=$SMB_TOOLS_PATH/add_smb_user.sh
|
||||
alias smbtools_user_remove=$SMB_TOOLS_PATH/remove_smb_user.sh
|
||||
alias smbtools_user_list=$SMB_TOOLS_PATH/list_smb_users.sh
|
||||
|
||||
alias smbtools_share_create=$SMB_TOOLS_PATH/create_share.sh
|
||||
alias smbtools_share_remove=$SMB_TOOLS_PATH/remove_share.sh
|
||||
alias smbtools_share_list=$SMB_TOOLS_PATH/list_smb_shares.sh
|
@ -1 +0,0 @@
|
||||
alias smbtools="bash $SMB_TOOLS_PATH/gui/main.sh"
|
@ -2,11 +2,11 @@
|
||||
|
||||
# Usage check
|
||||
if [ "$#" -ne 2 ]; then
|
||||
echo "Usage: $0 <folder_name> <username>"
|
||||
echo "Usage: $0 <folder_path> <username>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
FOLDER_PATH="$SMB_DATA_FOLDER/$2/$1"
|
||||
FOLDER_PATH="$1"
|
||||
USERNAME="$2"
|
||||
SMBCONF="/etc/samba/smb.conf"
|
||||
SHARE_CONFIG_DIR="/etc/samba/shares.d"
|
||||
@ -31,20 +31,17 @@ fi
|
||||
SHARE_NAME=$(basename "$FOLDER_PATH")
|
||||
|
||||
# 4. Ensure shares.d directory exists
|
||||
if [ ! -d "$SHARE_CONFIG_DIR/$USERNAME" ]; then
|
||||
mkdir -p "$SHARE_CONFIG_DIR/$USERNAME"
|
||||
if [ ! -d "$SHARE_CONFIG_DIR" ]; then
|
||||
mkdir -p "$SHARE_CONFIG_DIR"
|
||||
fi
|
||||
|
||||
# Controllare che uerfolder esista
|
||||
|
||||
# 5. Create Samba share config file
|
||||
SHARE_CONFIG_FILE="$SHARE_CONFIG_DIR/$USERNAME/$SHARE_NAME.conf"
|
||||
echo $SHARE_CONFIG_FILE
|
||||
SHARE_CONFIG_FILE="$SHARE_CONFIG_DIR/$SHARE_NAME.conf"
|
||||
if [ -f "$SHARE_CONFIG_FILE" ]; then
|
||||
echo "Warning: Share config already exists: $SHARE_CONFIG_FILE"
|
||||
else
|
||||
cat <<EOF > "$SHARE_CONFIG_FILE"
|
||||
[$USERNAME-$SHARE_NAME]
|
||||
[$SHARE_NAME]
|
||||
path = $FOLDER_PATH
|
||||
valid users = $USERNAME
|
||||
read only = no
|
@ -1,19 +0,0 @@
|
||||
version: '3'
|
||||
services:
|
||||
filebrowser:
|
||||
image: filebrowser/filebrowser:latest
|
||||
container_name: filebrowser
|
||||
restart: always
|
||||
entrypoint: ./start.sh
|
||||
volumes:
|
||||
- $SMB_DATA_FOLDER:/srv #Change to match your directory
|
||||
- /selfhosting/apps/smb_utilities/filebrowser/filebrowser.db:/database/filebrowser.db #Change to match your directory
|
||||
- /selfhosting/apps/smb_utilities/filebrowser/settings.json:/config/settings.json #Change to match your directory
|
||||
- /selfhosting/apps/smb_utilities/filebrowser/start.sh:/start.sh
|
||||
- /selfhosting/apps/smb_utilities/filebrowser/addusers.txt:/addusers.txt
|
||||
- /selfhosting/apps/smb_utilities/filebrowser/removeusers.txt:/removeusers.txt
|
||||
environment:
|
||||
- PUID=$(id -u)
|
||||
- PGID=$(id -g)
|
||||
ports:
|
||||
- 8095:80 #Change the port if needed
|
@ -1,64 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Helper function to check a command
|
||||
command_exists() {
|
||||
command -v "$1" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
DOCKER_OK=true
|
||||
COMPOSE_OK=true
|
||||
|
||||
# Check for Docker
|
||||
if ! command_exists docker; then
|
||||
DOCKER_OK=false
|
||||
fi
|
||||
|
||||
# Check for Docker Compose (plugin or legacy)
|
||||
if ! docker compose version >/dev/null 2>&1 && ! command_exists docker-compose; then
|
||||
COMPOSE_OK=false
|
||||
fi
|
||||
|
||||
# If either is missing, run install script
|
||||
if [[ "$DOCKER_OK" = false || "$COMPOSE_OK" = false ]]; then
|
||||
echo "Missing required tools. Running installer..."
|
||||
git clone https://git.giovanesaggio.com/Selfhosting/docker_setup.git
|
||||
./docker_setup/docker_setup.sh
|
||||
rm -r docker_setup
|
||||
fi
|
||||
|
||||
# Parse and prompt for .env variables
|
||||
ENV_FILE=".env"
|
||||
|
||||
if [[ ! -f "$ENV_FILE" ]]; then
|
||||
echo "$ENV_FILE not found. Creating a new one."
|
||||
touch "$ENV_FILE"
|
||||
fi
|
||||
|
||||
declare -A ENV_VARS
|
||||
|
||||
# Load existing env vars
|
||||
while IFS='=' read -r key value; do
|
||||
[[ "$key" =~ ^[A-Z_][A-Z0-9_]*$ ]] || continue
|
||||
ENV_VARS["$key"]="$value"
|
||||
done < "$ENV_FILE"
|
||||
|
||||
echo "Configure environment variables (press ENTER to keep current value):"
|
||||
|
||||
# Prompt for each variable
|
||||
for key in "${!ENV_VARS[@]}"; do
|
||||
current="${ENV_VARS[$key]}"
|
||||
read -p "$key [$current]: " new_value
|
||||
if [[ -n "$new_value" ]]; then
|
||||
ENV_VARS["$key"]="$new_value"
|
||||
fi
|
||||
done
|
||||
|
||||
# Overwrite .env with updated values
|
||||
> "$ENV_FILE"
|
||||
for key in "${!ENV_VARS[@]}"; do
|
||||
echo "$key=${ENV_VARS[$key]}" >> "$ENV_FILE"
|
||||
done
|
||||
|
||||
# Launch Docker
|
||||
docker compose up -d
|
||||
|
@ -1,8 +0,0 @@
|
||||
{
|
||||
"port": 80,
|
||||
"baseURL": "",
|
||||
"address": "",
|
||||
"log": "stdout",
|
||||
"database": "/database/filebrowser.db",
|
||||
"root": "/srv"
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
./filebrowser config init
|
||||
./filebrowser users add admin admin
|
||||
./filebrowser users update admin --perm.admin
|
||||
|
||||
input_file="addusers.txt"
|
||||
while IFS=: read -r username password
|
||||
do
|
||||
./filebrowser users add $username $password
|
||||
./filebrowser users update $username --scope /$username
|
||||
done < "$input_file"
|
||||
echo -n > $input_file
|
||||
|
||||
input_file="removeusers.txt"
|
||||
while IFS=: read -r username
|
||||
do
|
||||
./filebrowser users rm $username
|
||||
done < "$input_file"
|
||||
echo -n > $input_file
|
||||
|
||||
./filebrowser
|
@ -1,28 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Usage check
|
||||
if [ "$#" -ne 1 ]; then
|
||||
echo "Usage: $0 <username>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
USERNAME="$1"
|
||||
SHARE_DIR="/etc/samba/shares.d/$USERNAME"
|
||||
|
||||
# Loop through share config files
|
||||
for file in "$SHARE_DIR"/*.conf; do
|
||||
[ -e "$file" ] || continue # Skip if no .conf files
|
||||
|
||||
SHARE_NAME=$(basename "$file" .conf)
|
||||
PATH_LINE=$(grep -i "^ *path *= *" "$file")
|
||||
USER_LINE=$(grep -i "^ *valid users *= *" "$file")
|
||||
|
||||
# Extract values
|
||||
SHARE_PATH=$(echo "$PATH_LINE" | cut -d'=' -f2- | xargs)
|
||||
VALID_USER=$(echo "$USER_LINE" | cut -d'=' -f2- | xargs)
|
||||
|
||||
# Check if this share belongs to the specified user
|
||||
if [[ "$VALID_USER" == *"$USERNAME"* ]]; then
|
||||
printf "%s\n" "$SHARE_NAME"
|
||||
fi
|
||||
done
|
@ -1,12 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Check if pdbedit is installed
|
||||
if ! command -v pdbedit &> /dev/null; then
|
||||
echo -e "${YELLOW}Error:${NC} pdbedit is not installed. Install Samba first."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# List users with color
|
||||
pdbedit -L | cut -d: -f1 | while read -r user; do
|
||||
echo -e "${user}"
|
||||
done
|
@ -1,66 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Script to remove a Samba share, archive its data, and clean up configs
|
||||
# Usage: ./remove_samba_share.sh <share_name>
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
if [ "$#" -ne 2 ]; then
|
||||
echo "Usage: $0 <share_name> <username>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
SHARE_NAME="$1"
|
||||
USERNAME="$2"
|
||||
SHARE_CONFIG_DIR="/etc/samba/shares.d"
|
||||
SMBCONF="/etc/samba/smb.conf"
|
||||
SHARE_CONFIG_FILE="$SHARE_CONFIG_DIR/$USERNAME/$SHARE_NAME.conf"
|
||||
TRASH_BASE="$SMB_DATA_FOLDER/trash"
|
||||
|
||||
# 1. Read the .conf file if it exists
|
||||
if [ ! -f "$SHARE_CONFIG_FILE" ]; then
|
||||
echo "Error: Share config file does not exist: $SHARE_CONFIG_FILE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Found share config: $SHARE_CONFIG_FILE"
|
||||
|
||||
# Extract path and username
|
||||
SHARE_PATH=$(grep -i '^[[:space:]]*path[[:space:]]*=' "$SHARE_CONFIG_FILE" | cut -d'=' -f2- | xargs)
|
||||
VALID_USER=$(grep -i '^[[:space:]]*valid users[[:space:]]*=' "$SHARE_CONFIG_FILE" | cut -d'=' -f2- | xargs)
|
||||
|
||||
# Validate extracted data
|
||||
if [ -z "$SHARE_PATH" ] || [ -z "$VALID_USER" ]; then
|
||||
echo "Error: Could not extract share path or user from config."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Move share folder if it exists
|
||||
if [ -d "$SHARE_PATH" ]; then
|
||||
USER_TRASH_DIR="$TRASH_BASE/$VALID_USER"
|
||||
DEST="$USER_TRASH_DIR/$(basename "$SHARE_PATH")"
|
||||
|
||||
echo "Moving share folder '$SHARE_PATH' to '$DEST'"
|
||||
mkdir -p "$USER_TRASH_DIR"
|
||||
mv "$SHARE_PATH" "$DEST"
|
||||
else
|
||||
echo "Note: Share path '$SHARE_PATH' does not exist or is not a directory — skipping move."
|
||||
fi
|
||||
|
||||
# Remove the config file
|
||||
echo "Removing share config file: $SHARE_CONFIG_FILE"
|
||||
rm -f "$SHARE_CONFIG_FILE"
|
||||
|
||||
# Remove include line and related comment from smb.conf
|
||||
INCLUDE_LINE="include = $SHARE_CONFIG_FILE"
|
||||
sed -i "/# Include share definition for $SHARE_NAME/d" "$SMBCONF"
|
||||
sed -i "\|$INCLUDE_LINE|d" "$SMBCONF"
|
||||
|
||||
# Restart Samba
|
||||
echo "Restarting Samba service..."
|
||||
if systemctl restart smbd; then
|
||||
echo "Samba restarted successfully."
|
||||
else
|
||||
echo "Error restarting Samba. Please check logs."
|
||||
exit 2
|
||||
fi
|
@ -1,67 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Usage: ./remove_samba_user.sh <username>
|
||||
|
||||
# Check for root
|
||||
if [[ $EUID -ne 0 ]]; then
|
||||
echo "This script must be run as root."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
####################################################################
|
||||
# Parse username
|
||||
####################################################################
|
||||
|
||||
USERNAME="$1"
|
||||
|
||||
if [[ -z "$USERNAME" ]]; then
|
||||
read -p "Enter username to remove: " USERNAME
|
||||
fi
|
||||
|
||||
####################################################################
|
||||
# Remove shares
|
||||
# All the shares associated to the user are removed
|
||||
####################################################################
|
||||
|
||||
bash $SMB_TOOLS_PATH/functions/list_smb_shares.sh $USERNAME | while IFS= read -r line; do
|
||||
# Skip empty lines
|
||||
[ -z "$line" ] && continue
|
||||
|
||||
bash $SMB_TOOLS_PATH/functions/remove_share.sh "$line" "$USERNAME"
|
||||
done
|
||||
|
||||
# ####################################################################
|
||||
# # Remove samba user
|
||||
# ####################################################################
|
||||
|
||||
if pdbedit -L | grep -q "^$USERNAME:"; then
|
||||
smbpasswd -x "$USERNAME"
|
||||
echo "Samba user $USERNAME removed."
|
||||
else
|
||||
echo "Samba user $USERNAME does not exist."
|
||||
fi
|
||||
|
||||
# ####################################################################
|
||||
# # Remove system user
|
||||
# ####################################################################
|
||||
|
||||
if id "$USERNAME" &>/dev/null; then
|
||||
userdel -r "$USERNAME"
|
||||
echo "System user $USERNAME removed (including home directory)."
|
||||
else
|
||||
echo "System user $USERNAME does not exist."
|
||||
fi
|
||||
|
||||
# ####################################################################
|
||||
# # Remove filebrowser
|
||||
# ####################################################################
|
||||
|
||||
log_file="$SMB_TOOLS_PATH/filebrowser/removeusers.txt"
|
||||
|
||||
if [ -f "$log_file" ]; then
|
||||
echo "$USERNAME" >> "$log_file"
|
||||
fi
|
||||
|
||||
# Non-blocking docker restart
|
||||
docker restart filebrowser </dev/null &>/dev/null &
|
@ -1,40 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
TMP_FILE=$(mktemp)
|
||||
TMP_OUT=$(mktemp)
|
||||
TMP_USERS=$(mktemp)
|
||||
|
||||
# 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")
|
||||
|
||||
# 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
|
||||
|
||||
# 5) Display the result
|
||||
dialog --backtitle "Create SMB share" \
|
||||
--title "Result" \
|
||||
--textbox "$TMP_OUT" 20 60
|
||||
|
||||
# 6) Cleanup
|
||||
rm -f "$TMP_FILE" "$TMP_USERS" "$TMP_OUT"
|
@ -1,76 +0,0 @@
|
||||
#!/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"
|
@ -1,30 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
TMP_FILE=$(mktemp)
|
||||
|
||||
# Ask for username
|
||||
dialog --backtitle "Add User" --inputbox "Enter new username:" 10 40 2>"$TMP_FILE"
|
||||
USERNAME=$(<"$TMP_FILE")
|
||||
|
||||
# Ask for password (input will be hidden)
|
||||
dialog --backtitle "Add User" --insecure --passwordbox "Enter password for $USERNAME:" 10 40 2>"$TMP_FILE"
|
||||
PASSWORD=$(<"$TMP_FILE")
|
||||
|
||||
|
||||
|
||||
# 3) Call the external script and capture output
|
||||
# adjust the path (“../add_smb_user.sh”) as needed
|
||||
TMP_OUT=$(mktemp)
|
||||
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" \
|
||||
--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"
|
@ -1,36 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
TMP_FILE=$(mktemp)
|
||||
TMP_USERS=$(mktemp)
|
||||
TMP_OUT=$(mktemp)
|
||||
|
||||
# 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
|
||||
|
||||
# 5) Show output
|
||||
dialog --backtitle "Remove SMB User" \
|
||||
--title "Result" \
|
||||
--textbox "$TMP_OUT" 20 60
|
||||
|
||||
# 6) Cleanup
|
||||
rm -f "$TMP_FILE" "$TMP_USERS" "$TMP_OUT"
|
43
gui/main.sh
43
gui/main.sh
@ -1,43 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
TMP_FILE=$(mktemp)
|
||||
TITLE="System Administration Tool"
|
||||
|
||||
while true; do
|
||||
dialog --clear \
|
||||
--backtitle "$TITLE" \
|
||||
--title "Main Menu" \
|
||||
--menu "Choose an action:" 15 50 6 \
|
||||
1 "Add User" \
|
||||
2 "Remove User" \
|
||||
3 "Create Share" \
|
||||
4 "Remove Share" \
|
||||
5 "Exit" 2>"$TMP_FILE"
|
||||
|
||||
CHOICE=$(<"$TMP_FILE")
|
||||
|
||||
case $CHOICE in
|
||||
1)
|
||||
bash $SMB_TOOLS_PATH/gui/dialog_user_add.sh
|
||||
;;
|
||||
2)
|
||||
bash $SMB_TOOLS_PATH/gui/dialog_user_remove.sh
|
||||
;;
|
||||
3)
|
||||
bash $SMB_TOOLS_PATH/gui/dialog_share_create.sh
|
||||
;;
|
||||
4)
|
||||
bash $SMB_TOOLS_PATH/gui/dialog_share_remove.sh
|
||||
;;
|
||||
5)
|
||||
break
|
||||
;;
|
||||
*)
|
||||
dialog --msgbox "Invalid option." 8 30
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
clear
|
||||
rm -f "$TMP_FILE"
|
||||
echo "Exited."
|
79
install.sh
79
install.sh
@ -1,79 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Define colors
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
|
||||
echo -e "${GREEN}------------------------${NC}"
|
||||
echo -e "${GREEN} SmbTools installer ${NC}"
|
||||
echo -e "${GREEN}------------------------${NC}"
|
||||
|
||||
apt install samba -y
|
||||
|
||||
rm /etc/samba/smb.conf
|
||||
cp config/smb.conf /etc/samba/smb.conf
|
||||
|
||||
mkdir -p /etc/samba/shares.d
|
||||
|
||||
systemctl enable smbd
|
||||
systemctl restart smbd
|
||||
|
||||
|
||||
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
|
||||
ENV_LINE="export SMB_TOOLS_PATH=\"$SCRIPT_DIR\""
|
||||
|
||||
export SMB_TOOLS_PATH=$SCRIPT_DIR\
|
||||
|
||||
# Check if it's already set in .bashrc
|
||||
if grep -Fxq "$ENV_LINE" "$HOME/.bashrc"; then
|
||||
echo "SMB_TOOLS_PATH already set in .bashrc"
|
||||
else
|
||||
echo "$ENV_LINE" >> "$HOME/.bashrc"
|
||||
echo "Added SMB_TOOLS_PATH to ~/.bashrc"
|
||||
fi
|
||||
|
||||
ALIASES_LINE="source $SMB_TOOLS_PATH/config/aliases.sh"
|
||||
|
||||
# Check if it's already set in .bashrc
|
||||
if grep -Fxq "$ALIASES_LINE" "$HOME/.bashrc"; then
|
||||
echo "SmbTools aliases already set"
|
||||
else
|
||||
echo "$ALIASES_LINE" >> "$HOME/.bashrc"
|
||||
echo "Set SmbTools aliases"
|
||||
fi
|
||||
|
||||
# Ask the user to input a data folder
|
||||
echo
|
||||
read -rp "Enter path to data folder (e.g., /data/smb): " DATA_FOLDER
|
||||
|
||||
# Validate and create it if it doesn't exist
|
||||
if [ ! -d "$DATA_FOLDER" ]; then
|
||||
echo "Directory doesn't exist. Creating: $DATA_FOLDER"
|
||||
mkdir -p "$DATA_FOLDER"
|
||||
fi
|
||||
|
||||
# Set environment variable
|
||||
ENV_LINE="export SMB_DATA_FOLDER=\"$DATA_FOLDER\""
|
||||
export SMB_DATA_FOLDER="$DATA_FOLDER"
|
||||
|
||||
# Check if it's already set in .bashrc
|
||||
if grep -Fxq "$ENV_LINE" "$HOME/.bashrc"; then
|
||||
echo "SMB_DATA_FOLDER already set in .bashrc"
|
||||
else
|
||||
echo "$ENV_LINE" >> "$HOME/.bashrc"
|
||||
echo "Added SMB_DATA_FOLDER to ~/.bashrc"
|
||||
fi
|
||||
|
||||
|
||||
source $HOME/.bashrc
|
||||
|
||||
cd filebrowser
|
||||
bash ./install.sh
|
||||
cd ..
|
||||
|
||||
echo -e "${YELLOW}------------------------------------------------------${NC}"
|
||||
echo -e "${YELLOW} !!! WARNING !!! ${NC}"
|
||||
echo -e "${YELLOW} The computer must be restarted to complete the setup ${NC}"
|
||||
echo -e "${YELLOW}------------------------------------------------------${NC}"
|
29
list_smb_shares.sh
Executable file
29
list_smb_shares.sh
Executable file
@ -0,0 +1,29 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Define colors
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
SHARE_DIR="/etc/samba/shares.d"
|
||||
|
||||
# Header
|
||||
printf "${GREEN}%s${NC}\n" "--------------------------------------------------------------------------------------------"
|
||||
printf "${GREEN}%-20s %-40s %-20s${NC}\n" "SHARE NAME" "PATH" "USER"
|
||||
printf "${GREEN}%s${NC}\n" "--------------------------------------------------------------------------------------------"
|
||||
|
||||
# Loop through share config files
|
||||
for file in "$SHARE_DIR"/*.conf; do
|
||||
[ -e "$file" ] || continue # Skip if no .conf files
|
||||
|
||||
SHARE_NAME=$(basename "$file" .conf)
|
||||
PATH_LINE=$(grep -i "^ *path *= *" "$file")
|
||||
USER_LINE=$(grep -i "^ *valid users *= *" "$file")
|
||||
|
||||
# Extract values
|
||||
SHARE_PATH=$(echo "$PATH_LINE" | cut -d'=' -f2- | xargs)
|
||||
VALID_USER=$(echo "$USER_LINE" | cut -d'=' -f2- | xargs)
|
||||
|
||||
# Print each row with fixed width columns
|
||||
printf "%-20s %-40s %-20s\n" "$SHARE_NAME" "$SHARE_PATH" "$VALID_USER"
|
||||
done
|
23
list_smb_users.sh
Executable file
23
list_smb_users.sh
Executable file
@ -0,0 +1,23 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Define colors
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Check if pdbedit is installed
|
||||
if ! command -v pdbedit &> /dev/null; then
|
||||
echo -e "${YELLOW}Error:${NC} pdbedit is not installed. Install Samba first."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Display heading
|
||||
echo -e "${GREEN}------------------------${NC}"
|
||||
echo -e "${GREEN}Registered Samba users:${NC}"
|
||||
echo -e "${GREEN}------------------------${NC}"
|
||||
|
||||
# List users with color
|
||||
pdbedit -L | cut -d: -f1 | while read -r user; do
|
||||
echo -e " ${YELLOW}${user}${NC}"
|
||||
done
|
||||
echo " "
|
37
remove_share.sh
Executable file
37
remove_share.sh
Executable file
@ -0,0 +1,37 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Script to remove a Samba share
|
||||
# Usage: ./remove_samba_share.sh <share_name>
|
||||
|
||||
if [ "$#" -ne 1 ]; then
|
||||
echo "Usage: $0 <share_name>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
SHARE_NAME="$1"
|
||||
SHARE_CONFIG_DIR="/etc/samba/shares.d"
|
||||
SMBCONF="/etc/samba/smb.conf"
|
||||
SHARE_CONFIG_FILE="$SHARE_CONFIG_DIR/$SHARE_NAME.conf"
|
||||
|
||||
# 1. Remove share config file
|
||||
if [ -f "$SHARE_CONFIG_FILE" ]; then
|
||||
echo "Removing share config: $SHARE_CONFIG_FILE"
|
||||
rm -f "$SHARE_CONFIG_FILE"
|
||||
else
|
||||
echo "Warning: Share config file does not exist: $SHARE_CONFIG_FILE"
|
||||
fi
|
||||
|
||||
# 2. Remove include line from smb.conf
|
||||
INCLUDE_LINE="include = $SHARE_CONFIG_FILE"
|
||||
if grep -Fxq "$INCLUDE_LINE" "$SMBCONF"; then
|
||||
echo "Removing include line from $SMBCONF"
|
||||
# Remove both the comment and the include line if present
|
||||
sed -i "/# Include share definition for $SHARE_NAME/d" "$SMBCONF"
|
||||
sed -i "\|$INCLUDE_LINE|d" "$SMBCONF"
|
||||
else
|
||||
echo "Include line not found in $SMBCONF"
|
||||
fi
|
||||
|
||||
# 3. Restart Samba to apply changes
|
||||
echo "Restarting Samba service..."
|
||||
systemctl restart smbd && echo "Samba restarted successfully." || echo "Failed to restart Samba. Check logs."
|
31
remove_smb_user.sh
Executable file
31
remove_smb_user.sh
Executable file
@ -0,0 +1,31 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Usage: ./remove_samba_user.sh <username>
|
||||
|
||||
# Check for root
|
||||
if [[ $EUID -ne 0 ]]; then
|
||||
echo "This script must be run as root."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
USERNAME="$1"
|
||||
|
||||
if [[ -z "$USERNAME" ]]; then
|
||||
read -p "Enter username to remove: " USERNAME
|
||||
fi
|
||||
|
||||
# Remove Samba user
|
||||
if pdbedit -L | grep -q "^$USERNAME:"; then
|
||||
smbpasswd -x "$USERNAME"
|
||||
echo "Samba user $USERNAME removed."
|
||||
else
|
||||
echo "Samba user $USERNAME does not exist."
|
||||
fi
|
||||
|
||||
# Remove system user
|
||||
if id "$USERNAME" &>/dev/null; then
|
||||
userdel -r "$USERNAME"
|
||||
echo "System user $USERNAME removed (including home directory)."
|
||||
else
|
||||
echo "System user $USERNAME does not exist."
|
||||
fi
|
45
smb_utilities_install.sh
Executable file
45
smb_utilities_install.sh
Executable file
@ -0,0 +1,45 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo -e "${GREEN}------------------------${NC}"
|
||||
echo -e "${GREEN} SmbTools installer ${NC}"
|
||||
echo -e "${GREEN}------------------------${NC}"
|
||||
|
||||
apt install samba -y
|
||||
|
||||
rm /etc/samba/smb.conf
|
||||
cp config/smb.conf /etc/samba/smb.conf
|
||||
|
||||
mkdir -p /etc/samba/shares.d
|
||||
|
||||
systemctl enable smbd
|
||||
systemctl restart smbd
|
||||
|
||||
|
||||
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
|
||||
ENV_LINE="export SMB_TOOLS_PATH=\"$SCRIPT_DIR\""
|
||||
|
||||
export SMB_TOOLS_PATH=$SCRIPT_DIR\
|
||||
|
||||
# Check if it's already set in .bashrc
|
||||
if grep -Fxq "$ENV_LINE" "$HOME/.bashrc"; then
|
||||
echo "SMB_TOOLS_PATH already set in .bashrc"
|
||||
else
|
||||
echo "$ENV_LINE" >> "$HOME/.bashrc"
|
||||
echo "Added SMB_TOOLS_PATH to ~/.bashrc"
|
||||
fi
|
||||
|
||||
ALIASES_LINE="source $SMB_TOOLS_PATH/aliases.sh"
|
||||
|
||||
# Check if it's already set in .bashrc
|
||||
if grep -Fxq "$ALIASES_LINE" "$HOME/.bashrc"; then
|
||||
echo "SmbTools aliases already set"
|
||||
else
|
||||
echo "$ALIASES_LINE" >> "$HOME/.bashrc"
|
||||
echo "Set SmbTools aliases"
|
||||
fi
|
||||
|
||||
source $HOME/.bashrc
|
||||
|
||||
# Set it for the current script execution too
|
||||
export SMB_TOOLS_PATH="$SCRIPT_DIR"
|
||||
echo "SMB_TOOLS_PATH set to: $SMB_TOOLS_PATH"
|
Loading…
x
Reference in New Issue
Block a user