ShellCheck: Fix local var definition

This commit is contained in:
Jeremy Gardais 2018-04-26 14:43:28 +02:00
parent 250c8103cf
commit 89724099bf
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
1 changed files with 22 additions and 12 deletions

View File

@ -20,7 +20,8 @@ function GetDefaultUser() {
# 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
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)
[[ "${DEBUG}" == "0" ]] && printf '\e[1;33m%-6s\e[m\n' "DEBUG: Autoriser les accès SSH pour ${userLogin}." [[ "${DEBUG}" == "0" ]] && printf '\e[1;33m%-6s\e[m\n' "DEBUG: Autoriser les accès SSH pour ${userLogin}."
@ -74,7 +75,8 @@ function GetMyHostKey() {
## IpAddress {{{ ## IpAddress {{{
function IpAddress() { function IpAddress() {
local strMyIpAddress='' local strMyIpAddress
strMyIpAddress=''
strMyIpAddress=$(dig +short myip.opendns.com @resolver1.opendns.com) strMyIpAddress=$(dig +short myip.opendns.com @resolver1.opendns.com)
if [ "${strMyIpAddress}" == '' ]; then if [ "${strMyIpAddress}" == '' ]; then
error "failed to retrieve the ip address of this machine" error "failed to retrieve the ip address of this machine"
@ -86,15 +88,18 @@ function IpAddress() {
## MyFqdn {{{ ## MyFqdn {{{
function MyFqdn() { function MyFqdn() {
local strMyIpAddress=$( IpAddress ) # eg '129.20.27.49' local strMyIpAddress
local strMyFqdn=$(host "${strMyIpAddress}" | awk '{print $5}') local strMyFqdn
strMyIpAddress=$( IpAddress ) # eg '129.20.27.49'
strMyFqdn=$(host "${strMyIpAddress}" | awk '{print $5}')
echo "${strMyFqdn%?}" # remove the trailing '.' echo "${strMyFqdn%?}" # remove the trailing '.'
} }
## }}} ## }}}
## ListUsers {{{ ## ListUsers {{{
function ListUsers() { function ListUsers() {
local users='' local users
users=''
for user in $(ls -d /Users/[a-zA-Z]*); do for user in $(ls -d /Users/[a-zA-Z]*); do
user=$(basename "${user}") user=$(basename "${user}")
case "${user}" in case "${user}" in
@ -111,10 +116,14 @@ function ListUsers() {
## AddUserBackuppc {{{ ## AddUserBackuppc {{{
function AddUserBackuppc() { function AddUserBackuppc() {
local userToBackup="$1" # the login of the user to backup local userToBackup
local homeDir="$2" # eg. '/var/lib/backuppc' local homeDir
local userLogin='backuppc' local userLogin
local groupId=$(id -g "${userToBackup}") local groupId
userToBackup="$1" # the login of the user to backup
homeDir="$2" # eg. '/var/lib/backuppc'
userLogin='backuppc'
groupId=$(id -g "${userToBackup}")
maxid=$(dscl . -list /Users UniqueID | awk '$2 < 1000 {print $2}' | sort -ug | tail -1) maxid=$(dscl . -list /Users UniqueID | awk '$2 < 1000 {print $2}' | sort -ug | tail -1)
newid=$((maxid+1)) newid=$((maxid+1))
mkdir -p "$homeDir" mkdir -p "$homeDir"
@ -147,9 +156,10 @@ function AddUserBackuppc() {
## AllowBackuppcSudo {{{ ## AllowBackuppcSudo {{{
function AllowBackuppcSudo() { function AllowBackuppcSudo() {
# Get sudoers directory from the configuration # Get sudoers directory from the configuration
local sudoersDir=$(grep "^#includedir " /etc/sudoers | cut -d" " -f2) local sudoersDir
sudoersDir=$(grep "^#includedir " /etc/sudoers | cut -d" " -f2)
if [ -f /etc/sudoers ]; then if [ -f /etc/sudoers ]; then
local sudoersDir=$(grep "^#includedir " /etc/sudoers | cut -d" " -f2) sudoersDir=$(grep "^#includedir " /etc/sudoers | cut -d" " -f2)
if [ ! "${sudoersDir}" == '' ]; then if [ ! "${sudoersDir}" == '' ]; then
printf '%b\n' "Configuration de sudo pour BackupPC." printf '%b\n' "Configuration de sudo pour BackupPC."
else else
@ -157,7 +167,7 @@ function AllowBackuppcSudo() {
[[ "${DEBUG}" == "0" ]] && printf '\e[1;33m%-6s\e[m\n' "DEBUG: Ajout de ${sudoersDir} dans le fichier sudoers." [[ "${DEBUG}" == "0" ]] && printf '\e[1;33m%-6s\e[m\n' "DEBUG: Ajout de ${sudoersDir} dans le fichier sudoers."
fi fi
elif [ -f /private/etc/sudoers ]; then elif [ -f /private/etc/sudoers ]; then
local sudoersDir=$(grep "^#includedir " /private/etc/sudoers | cut -d" " -f2) sudoersDir=$(grep "^#includedir " /private/etc/sudoers | cut -d" " -f2)
if [ ! "${sudoersDir}" == '' ]; then if [ ! "${sudoersDir}" == '' ]; then
printf '%b\n' "Configuration de sudo pour BackupPC." printf '%b\n' "Configuration de sudo pour BackupPC."
else else