Add folds for functions
This commit is contained in:
parent
febfa4ecc4
commit
8bf3031d51
|
@ -6,24 +6,28 @@
|
|||
SUCCESS=0
|
||||
ERROR=1
|
||||
|
||||
# Functions {{{
|
||||
## getDefaultUser {{{
|
||||
function getDefaultUser() {
|
||||
for user in $(ListUsers); do
|
||||
echo $user
|
||||
return
|
||||
done
|
||||
}
|
||||
## }}}
|
||||
|
||||
## allowUserToConnectToThisMachineUsingSsh {{{
|
||||
# this performs the equivalent as adding a remote login user in system preferences using the gui
|
||||
function allowUserToConnectToThisMachineUsingSsh()
|
||||
{
|
||||
local userLogin="$1"
|
||||
|
||||
#dscl . append '/Groups/com.apple.access_ssh' user "${userLogin}"
|
||||
#dscl . append /Groups/com.apple.access_ssh groupmembers $(dscl . read "/Users/${userLogin}" GeneratedUID | cut -d " " -f 2)
|
||||
printf '\e[1;31m%-6s\e[m\n' "DEBUG : Autoriser les accès SSH pour ${userLogin}."
|
||||
}
|
||||
## }}}
|
||||
|
||||
|
||||
## ensurePingIsAllowed {{{
|
||||
function ensurePingIsAllowed()
|
||||
{
|
||||
#sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setstealthmode off
|
||||
|
@ -32,7 +36,9 @@ function ensurePingIsAllowed()
|
|||
printf '\e[1;31m%-6s\e[m' "La désactivation du mode furtif a échoué"; return "$ERROR"
|
||||
fi
|
||||
}
|
||||
## }}}
|
||||
|
||||
## ensureSshdIsRunning {{{
|
||||
function ensureSshdIsRunning()
|
||||
{
|
||||
#sudo launchctl list | grep 'com.openssh.sshd' &> /dev/null
|
||||
|
@ -40,7 +46,6 @@ function ensureSshdIsRunning()
|
|||
if [ $? != 0 ]; then
|
||||
# enable 'Remote login' in 'system preferences'
|
||||
sudo launchctl enable system/com.openssh.sshd &> /dev/null
|
||||
|
||||
sudo launchctl load /System/Library/LaunchDaemons/ssh.plist &> /dev/null
|
||||
fi
|
||||
#sudo launchctl list | grep 'com.openssh.sshd' &> /dev/null
|
||||
|
@ -49,7 +54,9 @@ function ensureSshdIsRunning()
|
|||
printf '\e[1;31m%-6s\e[m' "L'activation du serveur ssh a échoué"; return "$ERROR"
|
||||
fi
|
||||
}
|
||||
## }}}
|
||||
|
||||
## getMyHostKey {{{
|
||||
function getMyHostKey() {
|
||||
hostkey="/etc/ssh_host_rsa_key.pub"
|
||||
if [ ! -f "${hostkey}" ]; then
|
||||
|
@ -61,7 +68,9 @@ function getMyHostKey() {
|
|||
fi
|
||||
echo "${hostkey}"
|
||||
}
|
||||
## }}}
|
||||
|
||||
## IpAddress {{{
|
||||
function IpAddress() {
|
||||
local strMyIpAddress=''
|
||||
local strOsName=$( uname )
|
||||
|
@ -72,13 +81,17 @@ function IpAddress() {
|
|||
fi
|
||||
echo $strMyIpAddress
|
||||
}
|
||||
## }}}
|
||||
|
||||
## MyFqdn {{{
|
||||
function MyFqdn() {
|
||||
local strMyIpAddress=$( IpAddress ) # eg '129.20.27.49'
|
||||
local strMyFqdn=$(host $strMyIpAddress | awk '{print $5}')
|
||||
echo ${strMyFqdn%?} # remove the trailing '.'
|
||||
}
|
||||
## }}}
|
||||
|
||||
## ListUsers {{{
|
||||
function ListUsers() {
|
||||
local users=''
|
||||
for user in $(ls -d /Users/[a-zA-Z]*); do
|
||||
|
@ -93,8 +106,9 @@ function ListUsers() {
|
|||
done
|
||||
echo $users
|
||||
}
|
||||
## }}}
|
||||
|
||||
# AddUserBackuppc {{{
|
||||
## AddUserBackuppc {{{
|
||||
function AddUserBackuppc() {
|
||||
local userToBackup="$1" # the login of the user to backup
|
||||
local homeDir="$2" # par exemple '/var/lib/backuppc'
|
||||
|
@ -127,9 +141,9 @@ function AddUserBackuppc() {
|
|||
|
||||
AllowBackuppcSudo
|
||||
}
|
||||
# }}}
|
||||
## }}}
|
||||
|
||||
# AllowBackuppcSudo {{{
|
||||
## AllowBackuppcSudo {{{
|
||||
function AllowBackuppcSudo() {
|
||||
# Get the configuration directory for sudoers
|
||||
if [ -f /etc/sudoers ]; then
|
||||
|
@ -149,6 +163,7 @@ function AllowBackuppcSudo() {
|
|||
printf '\e[1;31m%-6s\e[m\n' "DEBUG : ajout de '${userLogin} ALL=(ALL:ALL) NOEXEC:NOPASSWD: /usr/bin/rsync'"
|
||||
printf '\e[1;31m%-6s\e[m\n' "DEBUG : dans le fichier ${sudoersDir}/backuppc_noexec."
|
||||
}
|
||||
## }}}
|
||||
# }}}
|
||||
|
||||
#### VÉRIFIER QUE L’ON A BIEN LES DROITS ADMIN ####
|
||||
|
|
Loading…
Reference in New Issue