Add folds for functions

This commit is contained in:
Jeremy Gardais 2018-04-25 15:39:24 +02:00
parent febfa4ecc4
commit 8bf3031d51
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
1 changed files with 21 additions and 6 deletions

View File

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