2018-06-02 15:55:06 +02:00
#!/bin/bash
##############################################################
# Crear carpetas compartidas en Linux (GTK) #
2021-03-28 22:16:51 +02:00
# U. Modificacion: 28-03-2021 #
2018-06-02 15:55:06 +02:00
# Autor: q3aql #
2018-12-27 09:17:16 +01:00
# Contacto: q3aql@protonmail.ch #
2018-06-02 15:55:06 +02:00
# Licencia: GPL v2.0 #
##############################################################
2018-12-27 09:17:16 +01:00
VERSION="1.6.2 (GTK)"
2021-03-28 22:16:51 +02:00
M_DATE="280321"
2018-06-02 15:55:06 +02:00
# Parametros globales
linuxSambaFolder="/opt/easy-samba"
sambaConfig="/etc/samba/smb.conf"
sambaBackup="/etc/samba/smb.conf.orig"
homeUsers="/home"
homeUsersList="/tmp/easy-samba-users.list"
sambaFoldersList="/tmp/easy-samba-folders.list"
sambaSedFolder="/tmp/easy-samba/word/"
2018-07-26 12:58:36 +02:00
# Funcion para comprobar permisos de administrador
function rootMessage() {
mkdir -p /etc/root &> /dev/null
administrador=$?
if [ ${administrador} -eq 0 ] ; then
rm -rf /etc/root
else
2021-03-28 22:16:51 +02:00
zenity --title "easy-samba-gtk ${VERSION} (${M_DATE})" --warning --width=340 --text "Administrator permissions are required"
2018-07-26 12:58:36 +02:00
echo ""
echo "* easy-samba-gtk ${VERSION} (${M_DATE}) (GPL v2.0)"
echo ""
2021-03-28 22:16:51 +02:00
echo "* Administrator permissions are required"
2018-07-26 12:58:36 +02:00
echo ""
exit
fi
}
2018-06-02 15:55:06 +02:00
# Funcion para realizar copia del fichero smb.conf original
function backupSmbConf() {
2018-07-26 13:01:01 +02:00
if [ -f ${sambaBackup} ] ; then
echo "OK" > /dev/null
else
echo "" >> ${sambaConfig}
echo "" >> ${sambaConfig}
cp -rf ${sambaConfig} ${sambaBackup} 2> /dev/null
fi
2018-06-02 15:55:06 +02:00
}
# Funcion para eliminar espacios y simbolos
# Sintaxis: convertText "<text>"
function convertText() {
2018-07-26 13:01:01 +02:00
wordToConvert=${1}
sambaSedFile="${sambaSedFolder}/easy-samba-${RANDOM}.txt"
mkdir -p ${sambaSedFolder} && chmod 777 -R ${sambaSedFolder} 2> /dev/null
echo "${wordToConvert}" > ${sambaSedFile}
# Borrar espacios
sed -i 's/ /_/g' "${sambaSedFile}" &> /dev/null
# Borrar simbolos
symbolsList="[ ] @ { } | \ / ~ # $ % & ? ¿ = ( ) < > ! ¡"
for findSymbol in ${symbolsList} ; do
sed -i "s/${findSymbol}//g" "${sambaSedFile}" &> /dev/null
done
# Borrar el resto de simbolos
sed -i 's/*//g' "${sambaSedFile}" &> /dev/null
sed -i 's/"//g' "${sambaSedFile}" &> /dev/null
sed -i "s/^//g" "${sambaSedFile}" &> /dev/null
# Cambiar algunos simbolos
sed -i 's/+/_/g' "${sambaSedFile}" &> /dev/null
sed -i 's/:/-/g' "${sambaSedFile}" &> /dev/null
sed -i 's/;/-/g' "${sambaSedFile}" &> /dev/null
# Mostrar texto convertido
wordToConvert=$(cat ${sambaSedFile})
echo ${wordToConvert}
2018-06-02 15:55:06 +02:00
}
2021-03-28 22:16:51 +02:00
# Funcion para extraer el nombre de The folder de una ruta
2018-06-07 15:46:50 +02:00
function extractFolder() {
2018-07-26 13:01:01 +02:00
pathToExtract="${1}/"
findFolder=0
count=1
nameFolder=$(echo ${pathToExtract} | cut -d "/" -f ${count})
count=$(expr $count + 1)
while [ ${findFolder} -eq 0 ] ; do
nameFolderTemp=$(echo ${pathToExtract} | cut -d "/" -f ${count})
if [ -z "${nameFolderTemp}" ] ; then
findFolder=1
else
nameFolder="${nameFolderTemp}"
count=$(expr $count + 1)
fi
done
echo "${nameFolder}"
2018-06-07 15:46:50 +02:00
}
2018-06-02 15:55:06 +02:00
# Funcion para crear enlace en el escritorio/home de los usuarios
# Sintaxis: createFolderLink [carpeta]
function createFolderLink() {
2021-03-28 22:16:51 +02:00
zenity --question --title "easy-samba ${VERSION} (${M_DATE})" --cancel-label="No" --ok-label="Yes" --width=530 \
--text "Do you want to create a link on the desktop/home for local users?"
2018-07-26 13:01:01 +02:00
createLink=$?
if [ ${createLink} -eq 1 ] ; then
echo "nule" > /dev/null
else
if [ "$(ls -A ${homeUsers})" ] ; then
cd ${homeUsers}
ls > ${homeUsersList}
for userDetected in $(cat ${homeUsersList}) ; do
if [ -d ${homeUsers}/${userDetected}/Desktop ] ; then
ln -s ${linuxSambaFolder}/${1} ${homeUsers}/${userDetected}/Desktop/ 2> /dev/null
ln -s ${linuxSambaFolder}/${1} ${homeUsers}/${userDetected}/ 2> /dev/null
output=$?
elif [ -d ${homeUsers}/${userDetected}/Escritorio ] ; then
ln -s ${linuxSambaFolder}/${1} ${homeUsers}/${userDetected}/Escritorio/ 2> /dev/null
ln -s ${linuxSambaFolder}/${1} ${homeUsers}/${userDetected}/ 2> /dev/null
output=$?
elif [ -d ${homeUsers}/${userDetected}/Escriptori ] ; then
ln -s ${linuxSambaFolder}/${1} ${homeUsers}/${userDetected}/Escriptori/ 2> /dev/null
ln -s ${linuxSambaFolder}/${1} ${homeUsers}/${userDetected}/ 2> /dev/null
output=$?
else
ln -s ${linuxSambaFolder}/${1} ${homeUsers}/${userDetected}/ 2> /dev/null
output=$?
fi
done
if [ ${output} -eq 0 ] ; then
2021-03-28 22:16:51 +02:00
zenity --title "easy-samba ${VERSION} (${M_DATE})" --info --width=280 --text "Links created successfully!"
2018-07-26 13:01:01 +02:00
else
2021-03-28 22:16:51 +02:00
zenity --title "easy-samba ${VERSION} (${M_DATE})" --error --width=280 --text "Error: Failed to create links!"
2018-07-26 13:01:01 +02:00
fi
else
2021-03-28 22:16:51 +02:00
zenity --title "easy-samba ${VERSION} (${M_DATE})" --warning --width=310 --text "Users not found in ${homeUsers}"
2018-07-26 13:01:01 +02:00
fi
fi
2018-06-02 15:55:06 +02:00
}
# Funcion para borrar los enlaces en el escritorio/home de los usuarios
# Sintaxis: deleteFolderLink [carpeta]
function deleteFolderLink() {
2021-03-28 22:16:51 +02:00
zenity --question --title "easy-samba ${VERSION} (${M_DATE})" --cancel-label="No" --ok-label="Yes" --width=530 \
--text "Do you want to delete the links on the desktop/home of the local users?"
2018-07-26 13:01:01 +02:00
deleteLink=$?
if [ ${deleteLink} -eq 1 ] ; then
echo "nule" > /dev/null
else
if [ "$(ls -A ${homeUsers})" ] ; then
cd ${homeUsers}
ls > ${homeUsersList}
for userDetected in $(cat ${homeUsersList}) ; do
if [ -d ${homeUsers}/${userDetected}/Desktop ] ; then
rm -f ${homeUsers}/${userDetected}/Desktop/${1} 2> /dev/null
rm -f ${homeUsers}/${userDetected}/${1} 2> /dev/null
output=$?
elif [ -d ${homeUsers}/${userDetected}/Escritorio ] ; then
rm -f ${homeUsers}/${userDetected}/Escritorio/${1} 2> /dev/null
rm -f ${homeUsers}/${userDetected}/${1} 2> /dev/null
output=$?
elif [ -d ${homeUsers}/${userDetected}/Escriptori ] ; then
rm -f ${homeUsers}/${userDetected}/Escriptori/${1} 2> /dev/null
rm -f ${homeUsers}/${userDetected}/${1} 2> /dev/null
output=$?
else
rm -f ${homeUsers}/${userDetected}/${1} 2> /dev/null
output=$?
fi
done
if [ ${output} -eq 0 ] ; then
2021-03-28 22:16:51 +02:00
zenity --title "easy-samba ${VERSION} (${M_DATE})" --info --width=280 --text "Links deleted successfully!"
2018-07-26 13:01:01 +02:00
else
2021-03-28 22:16:51 +02:00
zenity --title "easy-samba ${VERSION} (${M_DATE})" --error --width=290 --text "Error: Failed to delete links!"
2018-07-26 13:01:01 +02:00
fi
else
2021-03-28 22:16:51 +02:00
zenity --title "easy-samba ${VERSION} (${M_DATE})" --warning --width=310 --text "Users not found in ${homeUsers}"
2018-07-26 13:01:01 +02:00
fi
fi
2018-06-02 15:55:06 +02:00
}
2018-06-24 21:12:30 +02:00
# Funcion para corregir los permisos en la home de un usuario
# Sintaxis: fixHomePermissions <directorio>
function fixHomePermissions() {
2018-07-26 13:01:01 +02:00
homeFolder="${1}"
checkHomeFolder=$(echo ${homeFolder} | grep "/home")
if [ -z ${checkHomeFolder} ] ; then
echo "null" > /dev/null
else
userFolder=$(echo ${homeFolder} | cut -d "/" -f 3)
chmod o+rx "/home/${userFolder}"
fi
2018-06-24 21:12:30 +02:00
}
2018-06-07 15:46:50 +02:00
# Funcion para agregar una carpeta a Samba
function addNewFolder() {
2021-03-28 22:16:51 +02:00
folder=$(zenity --entry --title "easy-samba ${VERSION} (${M_DATE})" --text "Enter the absolute path of the folder to add:")
2018-07-26 13:01:01 +02:00
pathExtracted=$(extractFolder "${folder}")
endFolder=$(convertText "${pathExtracted}")
if [ -z ${folder} ] ; then
2021-03-28 22:16:51 +02:00
zenity --title "easy-samba ${VERSION} (${M_DATE})" --warning --width=410 --text "You must enter the absolute path of a folder!"
2018-07-26 13:01:01 +02:00
elif [ -d "${folder}" ] ; then
if [ -d ${linuxSambaFolder}/${endFolder} ] ; then
2021-03-28 22:16:51 +02:00
zenity --title "easy-samba ${VERSION} (${M_DATE})" --error --width=530 --text "A folder with the same name is already added or created!"
2018-07-26 13:01:01 +02:00
else
fixHomePermissions "${folder}"
ln -s "${folder}" ${linuxSambaFolder}/${endFolder} 2> /dev/null
output=$?
if [ ${output} -ne 0 ] ; then
2021-03-28 22:16:51 +02:00
zenity --title "easy-samba ${VERSION} (${M_DATE})" --error --width=520 --text "Error: Failed to add folder '${folder}'"
2018-07-26 13:01:01 +02:00
else
echo "[${endFolder}]" >> ${sambaConfig}
echo "# Folder to ${linuxSambaFolder}/${endFolder} # 00bc00" >> ${sambaConfig}
echo "path = ${linuxSambaFolder}/${endFolder}" >> ${sambaConfig}
echo "comment = Folder by easy-samba ${VERSION} (${M_DATE})" >> ${sambaConfig}
echo "browseable = yes" >> ${sambaConfig}
echo "writeable = yes" >> ${sambaConfig}
echo "read only = no" >> ${sambaConfig}
echo "guest ok = yes" >> ${sambaConfig}
echo "" >> ${sambaConfig}
zenity --title "easy-samba ${VERSION} (${M_DATE})" --info --width=390 --text "Carpeta '${folder}' agregada con exito!"
createFolderLink ${endFolder}
fi
fi
else
2021-03-28 22:16:51 +02:00
zenity --title "easy-samba ${VERSION} (${M_DATE})" --error --width=300 --text "The inserted folder does not exist!"
2018-07-26 13:01:01 +02:00
fi
2018-06-07 15:46:50 +02:00
}
2021-03-28 22:16:51 +02:00
# Funcion para Create shared folder con acceso para todos
2018-06-02 15:55:06 +02:00
function newFolderEveryone() {
2021-03-28 22:16:51 +02:00
folder=$(zenity --entry --title "easy-samba ${VERSION} (${M_DATE})" --text "Enter the name of the folder you want to create (without accents):")
2018-07-26 13:01:01 +02:00
formatText=$(convertText "${folder}")
folder=${formatText}
if [ -z ${folder} ] ; then
2021-03-28 22:16:51 +02:00
zenity --title "easy-samba ${VERSION} (${M_DATE})" --warning --width=350 --text "You must enter a folder name!"
2018-07-26 13:01:01 +02:00
elif [ -d ${linuxSambaFolder}/${folder} ] ; then
2021-03-28 22:16:51 +02:00
zenity --title "easy-samba ${VERSION} (${M_DATE})" --error --width=530 --text "The folder '${folder}' is already created, choose another name"
2018-07-26 13:01:01 +02:00
else
mkdir -p ${linuxSambaFolder}/${folder} 2> /dev/null
output=$?
if [ ${output} -ne 0 ] ; then
2021-03-28 22:16:51 +02:00
zenity --title "easy-samba ${VERSION} (${M_DATE})" --error --width=520 --text "Error: Failed to create shared folder '${folder}'"
2018-07-26 13:01:01 +02:00
else
chmod 777 -R ${linuxSambaFolder}/${folder}
echo "[${folder}]" >> ${sambaConfig}
echo "# Folder to ${linuxSambaFolder}/${folder} # 00bc00" >> ${sambaConfig}
echo "path = ${linuxSambaFolder}/${folder}" >> ${sambaConfig}
echo "comment = Folder by easy-samba ${VERSION} (${M_DATE})" >> ${sambaConfig}
echo "browseable = yes" >> ${sambaConfig}
echo "writeable = yes" >> ${sambaConfig}
echo "read only = no" >> ${sambaConfig}
echo "guest ok = yes" >> ${sambaConfig}
echo "" >> ${sambaConfig}
2021-03-28 22:16:51 +02:00
zenity --title "easy-samba ${VERSION} (${M_DATE})" --info --width=530 --text "Shared folder '${folder}' created sucessfully!"
2018-07-26 13:01:01 +02:00
createFolderLink ${folder}
fi
fi
2018-06-02 15:55:06 +02:00
}
2021-03-28 22:16:51 +02:00
# Funcion para Create shared folder de solo lectura
2018-06-02 15:55:06 +02:00
function newFolderReadOnly() {
2021-03-28 22:16:51 +02:00
folder=$(zenity --entry --title "easy-samba ${VERSION} (${M_DATE})" --text "Enter the name of the folder you want to create (without accents):")
2018-07-26 13:01:01 +02:00
formatText=$(convertText "${folder}")
folder=${formatText}
if [ -z ${folder} ] ; then
2021-03-28 22:16:51 +02:00
zenity --title "easy-samba ${VERSION} (${M_DATE})" --warning --width=350 --text "You must enter a folder name!"
2018-07-26 13:01:01 +02:00
elif [ -d ${linuxSambaFolder}/${folder} ] ; then
2021-03-28 22:16:51 +02:00
zenity --title "easy-samba ${VERSION} (${M_DATE})" --error --width=530 --text "The folder '${folder}' is already created, choose another name"
2018-07-26 13:01:01 +02:00
else
mkdir -p ${linuxSambaFolder}/${folder} 2> /dev/null
output=$?
if [ ${output} -ne 0 ] ; then
2021-03-28 22:16:51 +02:00
zenity --title "easy-samba ${VERSION} (${M_DATE})" --error --width=520 --text "Error: Failed to create shared folder '${folder}'"
2018-07-26 13:01:01 +02:00
else
chmod 777 -R ${linuxSambaFolder}/${folder}
echo "[${folder}]" >> ${sambaConfig}
echo "# Folder to ${linuxSambaFolder}/${folder} # 00bc00" >> ${sambaConfig}
echo "path = ${linuxSambaFolder}/${folder}" >> ${sambaConfig}
echo "comment = Folder by easy-samba ${VERSION} (${M_DATE})" >> ${sambaConfig}
echo "browseable = yes" >> ${sambaConfig}
echo "writeable = no" >> ${sambaConfig}
echo "read only = yes" >> ${sambaConfig}
echo "guest ok = yes" >> ${sambaConfig}
echo "" >> ${sambaConfig}
2021-03-28 22:16:51 +02:00
zenity --title "easy-samba ${VERSION} (${M_DATE})" --info --width=530 --text "Shared folder '${folder}' (solo lectura) created sucessfully!"
2018-07-26 13:01:01 +02:00
createFolderLink ${folder}
fi
fi
2018-06-02 15:55:06 +02:00
}
2021-03-28 22:16:51 +02:00
# Create shared folder para un usuario
2018-06-02 15:55:06 +02:00
function newFolderForUser() {
2021-03-28 22:16:51 +02:00
folder=$(zenity --entry --title "easy-samba ${VERSION} (${M_DATE})" --text "Enter the name of the folder you want to create (without accents):")
2018-07-26 13:01:01 +02:00
formatText=$(convertText "${folder}")
folder=${formatText}
if [ -z ${folder} ] ; then
2021-03-28 22:16:51 +02:00
zenity --title "easy-samba ${VERSION} (${M_DATE})" --warning --width=350 --text "You must enter a folder name!"
2018-07-26 13:01:01 +02:00
elif [ -d ${linuxSambaFolder}/${folder} ] ; then
2021-03-28 22:16:51 +02:00
zenity --title "easy-samba ${VERSION} (${M_DATE})" --error --width=530 --text "The folder '${folder}' is already created, choose another name"
2018-07-26 13:01:01 +02:00
else
mkdir -p ${linuxSambaFolder}/${folder} 2> /dev/null
output=$?
if [ ${output} -ne 0 ] ; then
2021-03-28 22:16:51 +02:00
zenity --title "easy-samba ${VERSION} (${M_DATE})" --error --width=520 --text "Error: Failed to create shared folder '${folder}'"
2018-07-26 13:01:01 +02:00
else
2021-03-28 22:16:51 +02:00
forUser=$(zenity --entry --title "easy-samba ${VERSION} (${M_DATE})" --text "Enter the username:")
2018-07-26 13:01:01 +02:00
randomFolder=/tmp/easy-samba/${RANDOM}-${RANDOM}
mkdir -p ${randomFolder}
chown ${forUser} ${randomFolder} 2> /dev/null
output=$?
if [ ${output} -ne 0 ] ; then
rm -rf ${linuxSambaFolder}/${folder}
2021-03-28 22:16:51 +02:00
zenity --title "easy-samba ${VERSION} (${M_DATE})" --error --width=330 --text "Error: The specified user does not exist!"
2018-07-26 13:01:01 +02:00
else
chmod 755 -R ${linuxSambaFolder}/${folder}
2018-12-27 09:17:16 +01:00
chown ${forUser} -R ${linuxSambaFolder}/${folder}
2018-07-26 13:01:01 +02:00
echo "[${folder}]" >> ${sambaConfig}
echo "# Folder to ${linuxSambaFolder}/${folder} # 00bc00" >> ${sambaConfig}
echo "path = ${linuxSambaFolder}/${folder}" >> ${sambaConfig}
echo "comment = Folder by easy-samba ${VERSION} (${M_DATE})" >> ${sambaConfig}
echo "browseable = yes" >> ${sambaConfig}
echo "writeable = yes" >> ${sambaConfig}
echo "read only = no" >> ${sambaConfig}
echo "guest ok = yes" >> ${sambaConfig}
echo "" >> ${sambaConfig}
2021-03-28 22:16:51 +02:00
zenity --title "easy-samba ${VERSION} (${M_DATE})" --info --width=530 --text "Shared folder '${folder}' (para ${forUser}) created sucessfully!"
2018-07-26 13:01:01 +02:00
createFolderLink ${folder}
fi
fi
fi
2018-06-02 15:55:06 +02:00
}
2021-03-28 22:16:51 +02:00
# Create shared folder para imprimir
2018-06-02 15:55:06 +02:00
function newFolderPrintable() {
2021-03-28 22:16:51 +02:00
folder=$(zenity --entry --title "easy-samba ${VERSION} (${M_DATE})" --text "Enter the name of the folder you want to create (without accents):")
2018-07-26 13:01:01 +02:00
formatText=$(convertText "${folder}")
folder=${formatText}
if [ -z ${folder} ] ; then
2021-03-28 22:16:51 +02:00
zenity --title "easy-samba ${VERSION} (${M_DATE})" --warning --width=350 --text "You must enter a folder name!"
2018-07-26 13:01:01 +02:00
elif [ -d ${linuxSambaFolder}/${folder} ] ; then
2021-03-28 22:16:51 +02:00
zenity --title "easy-samba ${VERSION} (${M_DATE})" --error --width=530 --text "The folder '${folder}' is already created, choose another name"
2018-07-26 13:01:01 +02:00
else
mkdir -p ${linuxSambaFolder}/${folder} 2> /dev/null
output=$?
if [ ${output} -ne 0 ] ; then
2021-03-28 22:16:51 +02:00
zenity --title "easy-samba ${VERSION} (${M_DATE})" --error --width=520 --text "Error: Failed to create shared folder '${folder}'"
2018-07-26 13:01:01 +02:00
else
chmod 777 -R ${linuxSambaFolder}/${folder}
echo "[${folder}]" >> ${sambaConfig}
echo "# Folder to ${linuxSambaFolder}/${folder} # 00bc00" >> ${sambaConfig}
echo "path = ${linuxSambaFolder}/${folder}" >> ${sambaConfig}
echo "comment = Folder by easy-samba ${VERSION} (${M_DATE})" >> ${sambaConfig}
echo "browseable = yes" >> ${sambaConfig}
echo "writeable = yes" >> ${sambaConfig}
echo "printable = yes" >> ${sambaConfig}
echo "guest ok = yes" >> ${sambaConfig}
echo "" >> ${sambaConfig}
2021-03-28 22:16:51 +02:00
zenity --title "easy-samba ${VERSION} (${M_DATE})" --info --width=530 --text "Shared folder '${folder}' (printable) created sucessfully!"
2018-07-26 13:01:01 +02:00
createFolderLink ${folder}
fi
fi
2018-06-02 15:55:06 +02:00
}
2018-06-24 20:53:44 +02:00
# Funcion de reinicio de samba
function reiniciandoSamba() {
2018-07-26 13:01:01 +02:00
sleep 2
/etc/init.d/samba restart &> /dev/null
systemctl restart smbd.service 2> /dev/null
systemctl restart nmbd.service 2> /dev/null
systemctl restart smb.service 2> /dev/null
2018-06-24 20:53:44 +02:00
}
2018-06-02 15:55:06 +02:00
# Funcion para reiniciar el servicio de Samba
function restartSamba() {
2021-03-28 22:16:51 +02:00
zenity --question --title "easy-samba ${VERSION} (${M_DATE})" --cancel-label="No" --ok-label="Yes" --width=320 --text "Do you want to restart the Samba services?"
2018-07-26 13:01:01 +02:00
sambaSN=$?
if [ "${sambaSN}" == "1" ] ; then
echo "nule" > /dev/null
else
2021-03-28 22:16:51 +02:00
reiniciandoSamba | zenity --progress --pulsate --title "easy-samba ${VERSION} (${M_DATE})" --auto-close --text "Restarting Samba services"
zenity --title "easy-samba ${VERSION} (${M_DATE})" --info --width=300 --text "Samba services restarted"
2018-07-26 13:01:01 +02:00
fi
2018-06-02 15:55:06 +02:00
}
# Funcion para borrar todas las carpetas compartidas
function restoreSmb() {
2018-07-26 13:01:01 +02:00
echo ""
2021-03-28 22:16:51 +02:00
zenity --question --title "easy-samba ${VERSION} (${M_DATE})" --cancel-label="No" --ok-label="Yes" --width=530 \
--text "Note: All shared folders and their content will be deleted \n\nImportant: It will return to the initial state of the file 'smb.conf' before\nexecuting 'easy-samba' for the first time\n\nDo you want continue?"
2018-07-26 13:01:01 +02:00
deleteFolder=$?
if [ ${deleteFolder} -eq 0 ] ; then
2021-03-28 22:16:51 +02:00
sleep 2 | zenity --progress --pulsate --title "easy-samba ${VERSION} (${M_DATE})" --auto-close --text "Deleting folders"
rm -rf ${linuxSambaFolder}/* | zenity --progress --pulsate --title "easy-samba ${VERSION} (${M_DATE})" --auto-close --text "Finalizing the deletion process"
2018-07-26 13:01:01 +02:00
output=$?
if [ ${output} -eq 0 ] ; then
cp -rf ${sambaBackup} ${sambaConfig} 2> /dev/null
#rm -rf ${sambaBackup} 2> /dev/null
2021-03-28 22:16:51 +02:00
zenity --title "easy-samba ${VERSION} (${M_DATE})" --info --width=350 --text "Folders deleted successfully!"
2018-07-26 13:01:01 +02:00
restartSamba
else
2021-03-28 22:16:51 +02:00
zenity --title "easy-samba ${VERSION} (${M_DATE})" --error --width=360 --text "Failed to delete shared folders"
2018-07-26 13:01:01 +02:00
fi
else
2021-03-28 22:16:51 +02:00
zenity --title "easy-samba ${VERSION} (${M_DATE})" --warning --width=360 --text "The restore process has been aborted"
2018-07-26 13:01:01 +02:00
fi
2018-06-02 15:55:06 +02:00
}
# Funcion para mostrar carpetas compartidas
function viewFolders() {
2018-07-26 13:01:01 +02:00
if [ "$(ls -A ${linuxSambaFolder})" ] ; then
cd ${linuxSambaFolder}
ls > ${sambaFoldersList}
folderList=""
for folderDetected in $(cat ${sambaFoldersList}) ; do
folderList="${folderList} ${folderDetected}"
done
folder=$(zenity --width=390 --height=300 --list --title "easy-samba ${VERSION} ($M_DATE)" \
2021-03-28 22:16:51 +02:00
--column "List of available shared folders:" ${folderList})
2018-07-26 13:01:01 +02:00
if [ -z ${folder} ] ; then
echo "nule" > /dev/null
elif [ -d ${linuxSambaFolder}/${folder} ] ; then
2021-03-28 22:16:51 +02:00
zenity --title "easy-samba ${VERSION} (${M_DATE})" --info --width=350 --text "Folder name: ${folder}\n\nPath: ${linuxSambaFolder}/${folder}"
2018-07-26 13:01:01 +02:00
else
2021-03-28 22:16:51 +02:00
zenity --title "easy-samba ${VERSION} (${M_DATE})" --error --width=400 --text "Error: The folder '${folder}' does not exist!"
2018-07-26 13:01:01 +02:00
fi
else
2021-03-28 22:16:51 +02:00
zenity --title "easy-samba ${VERSION} (${M_DATE})" --info --width=370 --text "There are currently no shared folders!"
2018-07-26 13:01:01 +02:00
fi
2018-06-02 15:55:06 +02:00
}
2021-03-28 22:16:51 +02:00
# Funcion para borrar una Shared folder
2018-06-02 15:55:06 +02:00
function removeFolder() {
2018-07-26 13:01:01 +02:00
if [ "$(ls -A ${linuxSambaFolder})" ] ; then
cd ${linuxSambaFolder}
ls > ${sambaFoldersList}
folderList=""
for folderDetected in $(cat ${sambaFoldersList}) ; do
folderList="${folderList} ${folderDetected}"
done
folder=$(zenity --width=390 --height=300 --list --title "easy-samba ${VERSION} ($M_DATE)" \
2021-03-28 22:16:51 +02:00
--column "Select folder to delete:" ${folderList})
2018-07-26 13:01:01 +02:00
if [ -z ${folder} ] ; then
2021-03-28 22:16:51 +02:00
zenity --title "easy-samba ${VERSION} (${M_DATE})" --warning --width=350 --text "You must select a folder from the list"
2018-07-26 13:01:01 +02:00
elif [ -d ${linuxSambaFolder}/${folder} ] ; then
2021-03-28 22:16:51 +02:00
sleep 2 | zenity --progress --pulsate --title "easy-samba ${VERSION} (${M_DATE})" --auto-close --text "Deleting folder..."
2018-07-26 13:01:01 +02:00
rm -rf ${linuxSambaFolder}/${folder} 2> /dev/null
output=$?
if [ ${output} -eq 0 ] ; then
readLine=$(cat ${sambaConfig} | grep "# Folder to ${linuxSambaFolder}/${folder} # 00bc00" -n | cut -d ":" -f 1)
if [ -z ${readLine} ] ; then
2021-03-28 22:16:51 +02:00
zenity --title "easy-samba ${VERSION} (${M_DATE})" --warning --width=530 --text "The folder '${folder}' has been deleted but not found in 'smb.conf'"
2018-07-26 13:01:01 +02:00
else
initLine=$(expr ${readLine} - 1)
endLine=$(expr ${readLine} + 7)
totalLines=$(cat /etc/samba/smb.conf | wc -l)
count=1
mkdir -p /tmp/easy-samba/
echo > /tmp/easy-samba/smb.conf
while [ ${count} -lt $initLine ] ; do
cat /etc/samba/smb.conf | head -${count} | tail -1 >> /tmp/easy-samba/smb.conf
count=$(expr ${count} + 1)
done
count=$(expr ${endLine} + 1)
while [ ${count} -le ${totalLines} ] ; do
cat ${sambaConfig} | head -${count} | tail -1 >> /tmp/easy-samba/smb.conf
count=$(expr ${count} + 1)
done
cp -rf /tmp/easy-samba/smb.conf ${sambaConfig}
2021-03-28 22:16:51 +02:00
zenity --title "easy-samba ${VERSION} (${M_DATE})" --info --width=460 --text "The folder '${folder}' has been deleted successfully!"
2018-07-26 13:01:01 +02:00
deleteFolderLink ${folder}
restartSamba
fi
else
2021-03-28 22:16:51 +02:00
zenity --title "easy-samba ${VERSION} (${M_DATE})" --error --width=450 --text "Error: Could not delete folder '${folder}'"
2018-07-26 13:01:01 +02:00
fi
else
2021-03-28 22:16:51 +02:00
zenity --title "easy-samba ${VERSION} (${M_DATE})" --error --width=400 --text "Error: The folder '${folder}' does not exist!"
2018-07-26 13:01:01 +02:00
fi
else
2021-03-28 22:16:51 +02:00
zenity --title "easy-samba ${VERSION} (${M_DATE})" --info --width=350 --text "There are no folders available to delete!"
2018-07-26 13:01:01 +02:00
fi
2018-06-02 15:55:06 +02:00
}
2021-03-28 22:16:51 +02:00
# Funcion para mostrar el "About" del programa
function mostrarAbout() {
zenity --title "About" --info --width=330 \
--text "Software: easy-samba ${VERSION} (${M_DATE})\nAuthor: q3aql\nContact: q3aql@protonmail.ch\nLicense: GPL v2.0"
2018-06-24 20:46:51 +02:00
}
2018-06-02 15:55:06 +02:00
# Mostrar menu con todas las opciones
mostrarMenu=0
2018-07-26 12:58:36 +02:00
rootMessage
2018-06-02 15:55:06 +02:00
backupSmbConf
while [ ${mostrarMenu} -eq 0 ] ; do
2018-07-26 13:01:01 +02:00
clear
opcion=$(zenity --width=390 --height=400 --list --title "easy-samba ${VERSION} ($M_DATE)" \
2021-03-28 22:16:51 +02:00
--column "Select an option :" "Add folder to Samba" "Create shared folder" \
"Create shared folder (read only)" "Create shared folder (for a user)" \
"Create shared folder (printable)" "Restart Samba services" \
"View available shared folders" "Delete shared folder" "Restore smb.conf" \
"About" "Exit")
if [ "${opcion}" == "Add folder to Samba" ] ; then
2018-07-26 13:01:01 +02:00
addNewFolder
restartSamba
2021-03-28 22:16:51 +02:00
elif [ "${opcion}" == "Create shared folder" ] ; then
2018-07-26 13:01:01 +02:00
newFolderEveryone
restartSamba
2021-03-28 22:16:51 +02:00
elif [ "${opcion}" == "Create shared folder (read only)" ] ; then
2018-07-26 13:01:01 +02:00
newFolderReadOnly
restartSamba
2021-03-28 22:16:51 +02:00
elif [ "${opcion}" == "Create shared folder (for a user)" ] ; then
2018-07-26 13:01:01 +02:00
newFolderForUser
restartSamba
2021-03-28 22:16:51 +02:00
elif [ "${opcion}" == "Create shared folder (printable)" ] ; then
2018-07-26 13:01:01 +02:00
newFolderPrintable
restartSamba
2021-03-28 22:16:51 +02:00
elif [ "${opcion}" == "Restart Samba services" ] ; then
2018-07-26 13:01:01 +02:00
restartSamba
2021-03-28 22:16:51 +02:00
elif [ "${opcion}" == "View available shared folders" ] ; then
2018-07-26 13:01:01 +02:00
viewFolders
2021-03-28 22:16:51 +02:00
elif [ "${opcion}" == "Delete shared folder" ] ; then
2018-07-26 13:01:01 +02:00
removeFolder
2021-03-28 22:16:51 +02:00
elif [ "${opcion}" == "Restore smb.conf" ] ; then
2018-07-26 13:01:01 +02:00
restoreSmb
2021-03-28 22:16:51 +02:00
elif [ "${opcion}" == "About" ] ; then
mostrarAbout
elif [ "${opcion}" == "Exit" ] ; then
2018-07-26 13:01:01 +02:00
mostrarMenu=1
else
2021-03-28 22:16:51 +02:00
zenity --title "easy-samba ${VERSION} (${M_DATE})" --warning --width=300 --text "Choose one of the menu options"
2018-07-26 13:01:01 +02:00
fi
2018-06-02 15:55:06 +02:00
done