mirror of
https://github.com/RasppleII/a2server.git
synced 2024-12-26 11:30:30 +00:00
95 lines
4.1 KiB
Plaintext
95 lines
4.1 KiB
Plaintext
|
#!/bin/bash
|
||
|
|
||
|
# 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
|
||
|
|
||
|
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 [[ ! $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 = /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
|