a2server/scripts/a2server-6-samba.txt
T. Joseph Carter 06bc59ece7 scripts/*.txt: Collapse multiple apt-gets in a row
As Debian has gone from large to huge, actions operating on the package
database have gotten slower and slower, so it's best to do them as few
times as possible.

Here we've got the trivial optimization.  A more complete optimization
requires a refactoring of code, and we're kind of in a 1.3.0 "freeze",
so let's not do that here and now.
2015-12-21 16:17:13 -08:00

81 lines
3.3 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
[[ -f /tmp/a2server-autoAnswerYes ]] && autoAnswerYes=1 || autoAnswerYes=
if [[ ! $autoAnswerYes || -f /tmp/a2server-setupWindowsSharing ]]; then
if [[ ! $autoAnswerYes ]]; then
echo
echo -n "Should Windows computers be able to connect to A2SERVER? "
read
fi
if [[ $autoAnswerYes || ${REPLY:0:1} == "Y" || ${REPLY:0:1} == "y" ]]; then
echo "A2SERVER: Setting up Windows file sharing..."
sudo true
sudo update-rc.d samba defaults &> /dev/null
[[ ! -f /etc/init.d/samba ]] && installSamba=1
if (( $installSamba )); then
if [[ ! -f /tmp/a2server-packageReposUpdated ]]; then
# prepare for installing packages
sudo apt-get -y update
touch /tmp/a2server-packageReposUpdated
fi
# Dependency: samba for Windows/modern Macs
# FIXME: Figure out when smbpasswd moved and adjust this as necessary
sudo apt-get -y install samba
command -v smbpasswd >/dev/null || sudo apt-get -y install samba-common-bin
sudo apt-get clean
fi
sudo /etc/init.d/samba start &> /dev/null
workgroup=$(grep -o "^ workgroup = .*$" /etc/samba/smb.conf 2> /dev/null | cut -c 16-)
[[ $workgroup ]] || workgroup="WORKGROUP"
if [[ ! $autoAnswerYes ]]; 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 = /srv/A2SERVER/$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
sudo /etc/init.d/samba stop &> /dev/null
sudo update-rc.d -f samba remove &> /dev/null
echo "A2SERVER: Windows file sharing has been turned off."
fi
echo
fi