[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[debian-knoppix] [script] Samba start script



the script "sambastart" is like "sshstart" starting a service and could therefore go to the same KNOPPIX submenu ;-) this can be handy in a Windows environment where one uses Knoppix as rescue disk. and as nmbd is started it makes it also easy to lookup the Knoppix machine if one does not know its IP number. (hint: "nmblookup Knoppix" on linux)

it updates the samba config files and exports the knoppix users home directory (read/write) and it asks if all the partitions under /mnt should be exported too. if this is done, it adds the corresponding entries to smb.conf, including automatic mount if the share is accessed.
(mounts are r/w as /bin/mount is used with the fstab entry)

that this can work it must have a valid samba password set. the script "knoppix-setpassword" takes care of that (it is automaticaly called within sambastart). i'd recomend to use that in "sshstart" too as it uses a nice (X)dialog interface ;-)

knoppix-setpassword should be installed in /usr/bin or /use/local/bin so that it is found by the sambastart script. (sorry cant provide a ready made deb)

chris
#!/bin/sh
# password dialog for Knoppix  Chris Liechti
# based on sshstart by Klaus Knopper
# apr 2003

PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin"
export PATH

if [ ! -d /KNOPPIX/etc ] ; then 
	echo -e "FATAL ERROR!\nThis Knoppix script must not be run on a regular system.\nAborting."
	exit 1
fi

TITLE="Set password for user \"knoppix\""

# LANG et al.
[ -f /etc/sysconfig/i18n ] && . /etc/sysconfig/i18n

[ "`id -u`" != "0" ] && exec sudo "$0" "$@"

XDIALOG_HIGH_DIALOG_COMPAT=1
export XDIALOG_HIGH_DIALOG_COMPAT

DIALOG="dialog"
[ -n "$DISPLAY" ] && [ -x /usr/bin/Xdialog ] && DIALOG="Xdialog"


# - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#samba password file must be not be a link to the CD
SMBPASS=/etc/samba/smbpasswd
if [ -L $SMBPASS ] ; then
	rm -f $SMBPASS
	cp -a /KNOPPIX$SMBPASS $SMBPASS
fi

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
case "$LANGUAGE" in
	de*) MESSAGE1="Passwort für Benutzer 'knoppix' setzen";
	     MESSAGE2="Wiederhole Passwort";
	     MESSAGE3="Passwoerter stimmen nicht überein"; ;;
	*)   MESSAGE1="Set password for user 'knoppix'";
	     MESSAGE2="Retype password";
	     MESSAGE3="Passwords did not match"; ;;
esac

echo ""

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
FORCE=false
echo "$@" | grep force && FORCE=true

#loop while password is not set
while grep -q '^knoppix:\*:' /etc/shadow || grep -q '^knoppix:1000:XXXXX' /etc/samba/smbpasswd || $FORCE ; do
	PASSWORD1=$($DIALOG --stdout --passwordbox "$MESSAGE1" 0 0) || break
	PASSWORD2=$($DIALOG --stdout --passwordbox "$MESSAGE2" 0 0) || break
	if [ "$PASSWORD1" == "$PASSWORD2" ] ; then
		#set system password and samba password
		echo "knoppix:$PASSWORD1" | chpasswd
		echo -e "$PASSWORD1\n$PASSWORD1" | smbpasswd -a knoppix -s
	else
		$DIALOG --msgbox "$MESSAGE3" 0 0
	fi
	#force is only executed once
	FORCE=false
done

exit 0
#!/bin/bash

PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin:/usr/local/bin:/usr/local/sbin"
export PATH

if [ ! -d /KNOPPIX/etc ] ; then 
	echo -e "FATAL ERROR!\nThis Knoppix script must not be run on a regular system.\nAborting."
	exit 1
fi

# LANG et al.
[ -f /etc/sysconfig/i18n ] && . /etc/sysconfig/i18n

[ "`id -u`" != "0" ] && exec sudo "$0" "$@"

XDIALOG_HIGH_DIALOG_COMPAT=1
export XDIALOG_HIGH_DIALOG_COMPAT

DIALOG="dialog"
[ -n "$DISPLAY" ] && [ -x /usr/bin/Xdialog ] && DIALOG="Xdialog"

TITLE="Configure and start Samba"
MESSAGE_EXPORTS="Export all harddrives so that they can be read and written from the remote machine?"

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#stop server if running
/etc/init.d/samba stop

#make sure password is set
knoppix-setpassword

#update samba config, make home writeable
SMBCONF=/etc/samba/smb.conf
rm -f $SMBCONF
sed "s/read only = yes/read only = no/" /KNOPPIX$SMBCONF >$SMBCONF

#ask user and export hardisks if he decides to do so
#can be done with append to smb.conf as its always a fresh copy
#(made above)
if $DIALOG --title "$TITLE" --yesno "$MESSAGE_EXPORTS" 0 0 ; then
for HD in $(cut -d " " -f 2 /etc/fstab|grep /mnt) ; do
NAME=$(basename $HD)
cat >>$SMBCONF <<EOF
[$NAME]
	comment = $HD
	browseable = yes
	public = yes
	path = $HD
	writeable = no
	preexec = /bin/mount $HD
	postexec = /bin/umount $HD
EOF
done
fi

#and finaly start the server
/etc/init.d/samba start


Reply to: