In this tutorial, we're going to look at writing a simple installer for the wsdd server, and a samba setup script. When that's done, we package a self-extracting installer.
So, let's rock :)

Here I'm writing a Samba.conf setup script, made for configuring samba very simple. This is something a couple of people have asked for, since setting up samba seems difficult, so let's help them a bit shall we ?

└─# cat -n setup.sh        
     1	#!/bin/bash
     2	#!/bin/bash
     3	# Samba & WSDD setup script.
     4	# For newly installed machines !!
     5	# By nx <This email address is being protected from spambots. You need JavaScript enabled to view it.>
     6	# Version 0.1 - April 2021 
     7	#
     8	# Defining af function for smb_conf
     9	
    10	#echo "This is the Samba & wsdd install script. Run as root"
    11	
    12	check_root() 
    13	{
    14	if [ "$EUID" -ne 0 ]; then
    15	    echo "Not running as root..quitting"
    16	exit
    17	fi
    18	}
    19	
    20	smb_param() {
    21	read -p " What's the system workgroup ? :" workgroup
    22	read -p " What's the system hostname ? : " netbios_name
    23	}
    24	
    25	smb_conf() {
    26	cat > /etc/samba/smb.conf << EOF
    27	[global]
    28	workgroup = $workgroup
    29	netbios name = $netbios_name 
    30	ntlm auth = yes
    31	client NTLMv2 auth = yes
    32	client max protocol = SMB3
    33	server max protocol = SMB3
    34	name resolve order = bcast wins host
    35	# These parameters NOT used for simplicity
    36	# hosts allow = 192.168.1.0/24 127.0.0.1/24
    37	# hosts deny = 0.0.0.0/24
    38	domain master = yes
    39	preferred master = yes
    40	local master = yes
    41	server string = %h server (Samba, Ubuntu)
    42	log file = /var/log/samba/log.%m
    43	max log size = 1000
    44	server role = standalone server
    45	obey pam restrictions = yes
    46	unix password sync = yes
    47	passwd program = /usr/bin/passwd %u
    48	passwd chat = *Enter\snew\s*\spassword:* %n\n *Retype\snew\s*\spassword:* %n\n *password\supdated\ssuccessfully*
    49	pam password change = yes
    50	map to guest = bad user
    51	usershare allow guests = yes
    52	EOF
    53	}
    54	
    55	setup_wsdd() 
    56	{
    57	sleep 2
    58	echo " "
    59	echo "standby..setting up wsdd.py"
    60	sleep 2
    61	cp wsdd.py /usr/bin/wsdd.py
    62	chmod +x /usr/bin/wsdd.py
    63	echo "done copying wsdd.py"
    64	sleep 2
    65	echo " "
    66	echo "setting up wsdd.service"
    67	cp wsdd.service /etc/systemd/system/wsdd.service
    68	echo "Done setting up services file.."
    69	echo " "
    70	sleep 2
    71	#echo 'Now, start wsdd with "systemctl start wsdd"'
    72	#echo 'To enable at boot, use "systemctl enable wsdd"'
    73	}
    74	smb_exist() 
    75	{
    76	smbconf=/etc/smb/smb.conf
    77	if [ -f $smbconf ] 
    78	then
    79		echo "smb.conf exists"
    80		echo "renaming smb.conf to smb.old.."
    81		mv /etc/samba/smb.conf /etc/samba/smb.old
    82	else
    83		echo "smb.conf doesn't exist"
    84		sleep 2
    85		echo "Let's write a smb.conf file"
    86		echo "Enter new details"
    87		echo " "
    88	fi
    89	}
    90	
    91	setup_samba()
    92	{
    93	echo "Setting up samba..."
    94	sleep 2
    95	smb_exist
    96	smb_param
    97	smb_conf
    98	}
    99	
   100	start_services()
   101	{
   102	echo " "
   103	read -p "All done, should we start services now ? y/n" svrans
   104	if [ $svrans = y ] ; then
   105	systemctl start smbd
   106	systemctl start nmbd
   107	systemctl start wsdd
   108	else
   109	echo " "
   110	echo " NOT starting services.."
   111	echo ' Start manually via "systemctl start <service>"'
   112	fi
   113	}
   114	
   115	enable_services()
   116	{
   117	echo " "
   118	read -p "All done, should we enable services at boot ? y/n" enabans
   119	if [ $enabans = y ] ; then
   120	systemctl enable smbd
   121	systemctl enable nmbd
   122	systemctl enable wsdd
   123	else
   124	echo " "
   125	echo " NOT enabling services.."
   126	echo ' Enable manually via "systemctl enable <service>"'
   127	fi
   128	}
   129	
   130	header() {
   131	echo "__________________________________________________________________"
   132	echo " "
   133	echo "Welcome to the Samba and WSDD setup script."
   134	echo "For this to work, install samba first via your package manager"
   135	echo " "
   136	echo "This script will sleep for ten seconds now, press Control+C to stop it"
   137	echo "__________________________________________________________________"
   138	sleep 10
   139	}
   140	
   141	credits() {
   142	
   143	echo "__________________________________________________________________"
   144	echo " "
   145	echo " Samba template file by Torben J..."
   146	echo " "
   147	echo " wsdd.py by Steffen Christgau - https://github.com/christgau "
   148	echo " "
   149	echo " setup script, packaging and testing by NX <This email address is being protected from spambots. You need JavaScript enabled to view it.>"
   150	echo " "
   151	echo "___________________________________________________________________"
   152	
   153	}
   154	check_root
   155	header
   156	setup_samba
   157	setup_wsdd
   158	start_services
   159	enable_services
   160	credits
   161	sleep 2
   162	echo " "
   163	echo "The setup is done."

This script takes two files from the wsdd.py and copies it into place. The wsdd.py into /usr/bin/, and the service file under /etc/systemd/system/, so it's pretty basic. I suggest you read through the script, and figure out what it does, it's pretty simple.

Next, go download wsdd from here https://github.com/christgau/wsdd

Next up, we need makeself, a shellscript for making the run file. Get it from https://github.com/megastep/makeself/blob/master/makeself.sh

So, make a new folder, call it something, eg wsdd_install. Copy the wsdd files into it, so you have wsdd.py and wsdd.service in there, and make a new file called setup.sh, and paste the above script into it.

Now, in the folder you're currently in, copy these files from the makeself project, so you have them in the folder next to your wsdd_install folder.

make-release.sh     
makeself.lsm
makeself.1
makeself.sh
run-tests.sh
makeself-header.sh                                                                                                                  

Now, we just need to run makeself.sh, and we do that like this, passing in our parameters

# Example command from makeself.sh

makeself.sh [args] archive_dir file_name label startup_script [script_args]

# example two

makeself.sh /full/path/to/source/folder/wsdd_install wsdd-installer.run "wsdd-installer" ./setup.sh

Let it run, and you should end up with a file called wsdd-installer.run. Now we simply run it with

./wsdd-installer.run

When it runs, it will run the setup script, and do what's in there, and when it's done, clean up after itself. Pretty neat huh ?

Much Happy Installer Making ;)

You have no rights to post comments