mirror of
https://github.com/RasppleII/a2server.git
synced 2025-08-10 15:24:58 +00:00
Didn't touch the Samba workgroup question for now since it's the only question that asks anything else. Maybe when this stuff gets refactored to remove duplication.
133 lines
4.9 KiB
Bash
Executable File
133 lines
4.9 KiB
Bash
Executable File
#! /bin/bash
|
|
# vim: set tabstop=4 shiftwidth=4 expandtab filetype=sh:
|
|
|
|
# Set up A2SERVER to support Samba (Windows File Sharing)
|
|
# this script can also be used if new shares are introduced
|
|
|
|
function askYesNo()
|
|
# Ask a yes/no question of the user, with potential default
|
|
# arg1: Prompt text
|
|
# arg2: Default; 0 for yes, 1 for no, anything else for no default
|
|
# arg3: Info text for the user
|
|
# returns: 0 for yes, 1 for no
|
|
{
|
|
local default
|
|
|
|
case "$2" in
|
|
0) default="y" ;;
|
|
1) default="n" ;;
|
|
*) default="" ;;
|
|
esac
|
|
|
|
if [ -n "$autoAnswerDefault" -a -n "$default" ]; then
|
|
return $2
|
|
fi
|
|
|
|
if [ -n "$3" ]; then
|
|
echo
|
|
echo "$3"
|
|
echo
|
|
fi
|
|
while :; do
|
|
echo -n "$1 "
|
|
[ -n "$default" ] && echo -n "[$default] "
|
|
read
|
|
case "$REPLY" in
|
|
[Yy]*) return 0 ;;
|
|
[Nn]*) return 1 ;;
|
|
"") [ -n "$default" ] && return $2 ;;
|
|
*) echo "Please answer yes or no." ;;
|
|
esac
|
|
done
|
|
}
|
|
|
|
[[ -f /tmp/a2server-autoAnswerDefault ]] && autoAnswerDefault=1 || autoAnswerDefault=
|
|
|
|
if [[ ! $autoAnswerDefault || -f /tmp/a2server-setupWindowsSharing ]]; then
|
|
|
|
if [[ ! $autoAnswerDefault ]]; then
|
|
echo
|
|
askYesNo "Should Windows computers be able to connect to A2SERVER?" 0
|
|
fi
|
|
if [ $? -eq 0 ]; then
|
|
|
|
echo "A2SERVER: Setting up Windows file sharing..."
|
|
sudo true
|
|
|
|
if [[ $(lsb_release -d 2> /dev/null | grep Ubuntu) ]]; then
|
|
[[ -f /etc/init/smbd.conf.off ]] && sudo mv /etc/init/smbd.conf.off /etc/init/smbd.conf
|
|
[[ -f /etc/init/nmbd.conf.off ]] && sudo mv /etc/init/nmbd.conf.off /etc/init/nmbd.conf
|
|
[[ ! -f /etc/init/smbd.conf || ! -f /etc/init/nmbd.conf ]] && installSamba=1
|
|
else
|
|
sudo update-rc.d samba defaults &> /dev/null
|
|
[[ ! -f /etc/init.d/samba ]] && installSamba=1
|
|
fi
|
|
|
|
if (( $installSamba )); then
|
|
if [[ ! -f /tmp/a2server-packageReposUpdated ]]; then
|
|
# prepare for installing packages
|
|
sudo apt-get -y update
|
|
touch /tmp/a2server-packageReposUpdated
|
|
fi
|
|
|
|
sudo apt-get -y install samba
|
|
[[ -f /usr/bin/smbpasswd ]] || sudo apt-get -y install samba-common-bin
|
|
sudo apt-get clean
|
|
fi
|
|
|
|
if [[ $(lsb_release -d 2> /dev/null | grep Ubuntu) ]]; then
|
|
sudo initctl start smbd &> /dev/null
|
|
sudo initctl start nmbd &> /dev/null
|
|
else
|
|
sudo /etc/init.d/samba start &> /dev/null
|
|
fi
|
|
|
|
workgroup=$(grep -o "^ workgroup = .*$" /etc/samba/smb.conf 2> /dev/null | cut -c 16-)
|
|
[[ $workgroup ]] || workgroup="WORKGROUP"
|
|
if [[ ! $autoAnswerDefault ]]; then
|
|
echo
|
|
echo "Enter workgroup name (or press return for '${workgroup}'): "
|
|
read
|
|
[[ $REPLY ]] && workgroup=$REPLY
|
|
fi
|
|
sudo sed -i 's/^ workgroup = .*$/ workgroup = '$workgroup'/' /etc/samba/smb.conf 2> /dev/null
|
|
sudo sed -i 's/^# security = user/ security = user/' /etc/samba/smb.conf 2> /dev/null
|
|
|
|
grep ^/media /usr/local/etc/netatalk/AppleVolumes.default | cut -d" " -f2 \
|
|
| while read sharename; do
|
|
if [[ $(grep $sharename /etc/samba/smb.conf) ]]; then
|
|
echo "A2SERVER: $sharename is already set up for Windows file sharing."
|
|
else
|
|
echo "[$sharename]" | sudo tee -a /etc/samba/smb.conf > /dev/null
|
|
echo " path = /media/A2SHARED/$sharename" | sudo tee -a /etc/samba/smb.conf > /dev/null
|
|
echo " browsable = yes" | sudo tee -a /etc/samba/smb.conf > /dev/null
|
|
echo " guest ok = yes" | sudo tee -a /etc/samba/smb.conf > /dev/null
|
|
echo " read only = no" | sudo tee -a /etc/samba/smb.conf > /dev/null
|
|
echo " create mask = 0666" | sudo tee -a /etc/samba/smb.conf > /dev/null
|
|
echo " force user = $USER" | sudo tee -a /etc/samba/smb.conf > /dev/null
|
|
echo "A2SERVER: $sharename has been set up for Windows file sharing."
|
|
fi
|
|
done
|
|
|
|
echo
|
|
echo "A2SERVER: Setting Windows file sharing password to 'apple2'."
|
|
echo -e 'apple2\napple2' | sudo smbpasswd -s -a $USER
|
|
|
|
echo
|
|
echo "A2SERVER: Windows file sharing is now running."
|
|
else
|
|
if [[ $(lsb_release -d 2> /dev/null | grep Ubuntu) ]]; then
|
|
sudo initctl stop smbd &> /dev/null
|
|
sudo initctl stop nmbd &> /dev/null
|
|
[[ -f /etc/init/smbd.conf ]] && sudo mv /etc/init/smbd.conf /etc/init/smbd.conf.off
|
|
[[ -f /etc/init/nmbd.conf ]] && sudo mv /etc/init/nmbd.conf /etc/init/nmbd.conf.off
|
|
else
|
|
sudo /etc/init.d/samba stop &> /dev/null
|
|
sudo update-rc.d -f samba remove &> /dev/null
|
|
fi
|
|
echo "A2SERVER: Windows file sharing has been turned off."
|
|
fi
|
|
|
|
echo
|
|
fi
|