smb_utilities/install.sh
2025-05-25 10:27:47 +00:00

79 lines
2.0 KiB
Bash
Executable File

#!/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}"