Using YAD for an easy Samba file share

135 views
Skip to first unread message

Keegan

unread,
Feb 18, 2018, 4:32:19 PM2/18/18
to yad-common
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! 

Keegan

unread,
Feb 18, 2018, 4:43:37 PM2/18/18
to yad-common
P.S. As you can see, I am currently trying to continuously output the Samaba sharing status by putting the desired response at the end of a file, and then just continuously reading the last line. However, it appears that this causes some sort of inescapable loop in which YAD is never able to actually start.

Any help would be welcome, and thank you so much for developing this for users like me who are just trying to make a quick and easy little GUI application for ourselves, Victor Ananjevsky. I greatly appreciate all your work.

Robert Cooper

unread,
Jul 29, 2024, 2:16:31 PM7/29/24
to yad-common
Hi Keegan, I kow this is an old question but, were you able to get this script working correctly ?
Reply all
Reply to author
Forward
0 new messages