Hi there everyone! I'm currently building a simple little application that offers an easy way to use Samba via the GUI. I've almost got it figured out, but am missing one option. In the top field, I would like to be able to display the status of whether or not a user is sharing folders via Samba, with this response obviously being changed upon the user click the "Start Folder Share" button. Here's the whole script so you can get a better idea of what I'm trying to do:
#!/bin/bash
#
# Simple Samba share with a (Yad based) GUI, for local network.
#
#
# Requirements:
# - python 3
# - yad
# - samba
#
#
# Originally adopted from: @manuel at Antergos.com
# Date: 2018-01-27
# Changes: 2018-01-29:
# - managing only port $SRV_PORT of the firewall (thanks casquinhas!)
# - added info about starting directory
# - added option --dir=<starting-directory> (thanks Keegan!)
_message() # show a message with yad
{
# User may give extra options (e.g. --geometry=AxB+C+D)
# before the actual message.
local opts xx
for xx in "$@"
do
case "$xx" in
--*) opts+="$xx " ; shift ;;
*) break ;;
esac
done
local line="$*"
local width=$((${#line} * 8))
local width_limit=600
if [ $width -gt $width_limit ] ; then
width=$width_limit
fi
yad --form --title="Message" \
--width=$width \
--button=gtk-quit:1 \
--field="":TXT "$line" $opts
}
function Stop()
{
sudo systemctl stop smbd.service nmbd.service
echo "Stopped"
echo "Stopped" >> /tmp/sharing.txt
STATUS=stopped
}
function Start()
{
local yadfield="$1"
SRV_STATUS=Started
echo "$yadfield:$SRV_STATUS"
echo "Restarting..."
sudo systemctl restart smbd.service nmbd.service
echo "Restarted"
STATUS=started
}
function File()
{
SHARING=$(sed '1q;d' /tmp/sharing.txt)
echo "changing directory to $SHARING"
sudo sed -i "225s/.*/path = ${SHARING//\//\\/}/" /etc/samba/smb.conf
echo "Restarting..."
sudo systemctl restart smbd.service nmbd.service
echo "Restarted"
echo "DONE"
echo "Started" >> /tmp/sharing.txt
STATUS=started
}
export -f Stop File Start # for yad!
# trap "{ gksu -w 'ufw delete allow 8000/tcp' ; }" EXIT # enable firewall at exit
StartHere()
{
sharing=$(yad --center --width=350 --height=100 --form --separator='' --title="Samba File Share" --save --field="Share":DIR >/tmp/sharing.txt)
SHARING=$(sed '1q;d' /tmp/sharing.txt)
echo "Using $SHARING Directory"
echo "inactive" >> /tmp/sharing.txt
WATCHING=$(watch tail -n 1 /tmp/sharing.txt)
yad --form --center --title "Samba File Share" --width=400 \
--field="Status::RO" "$WATCHING" \
--field="Folder to Share::RO" "$SHARING" \
--field='Start Folder Share:FBTN' '@bash -c "File"' \
--field='Stop Folder Share:FBTN' 'bash -c "Stop"' \
--button='gtk-quit:1'
Stop
rm /tmp/sharing.txt
}
StartHere "$@"
My script is actually adopted from someone else, but I am just trying to tweak it. Thus, there may be some obsolete, strange code hanging around in there. However, I am working on cleaning it up.
Thank you in advance!