Declare and assign separately to avoid masking return values

This commit is contained in:
Pierre-Louis Bonicoli 2024-06-17 02:18:17 +02:00
parent 3e30a986bc
commit 302d2303c7
Signed by: pilou
GPG Key ID: 06914C4A5EDAA6DD

View File

@ -50,22 +50,28 @@ generateHTTPReport()
echo "=§= Rapport d'activité HTTP" echo "=§= Rapport d'activité HTTP"
echo echo
local httpRequestCount=$(zgrep "$monthEnglish" $LOG_PREFIX-access.log*|grep -c $year) local httpRequestCount
httpRequestCount=$(zgrep "$monthEnglish" $LOG_PREFIX-access.log*|grep -c "$year")
echo "Nombre total de requêtes http = $httpRequestCount" echo "Nombre total de requêtes http = $httpRequestCount"
local trueHttpRequestCount=$(zgrep "$monthEnglish" $LOG_PREFIX-access.log*|grep $year|grep -vi bot|grep -c -v check_http) local trueHttpRequestCount
trueHttpRequestCount=$(zgrep "$monthEnglish" $LOG_PREFIX-access.log*|grep "$year"|grep -vi bot|grep -c -v check_http)
echo "Nombre de vraies requêtes http = $trueHttpRequestCount" echo "Nombre de vraies requêtes http = $trueHttpRequestCount"
local botRequestCount=$(zgrep "$monthEnglish" $LOG_PREFIX-access.log*|grep "$year"|grep -i bot|grep -c -v check_http) local botRequestCount
botRequestCount=$(zgrep "$monthEnglish" $LOG_PREFIX-access.log*|grep "$year"|grep -i bot|grep -c -v check_http)
echo "Nombre de requêtes bot = $botRequestCount" echo "Nombre de requêtes bot = $botRequestCount"
local errorRequestCount=$(zgrep "$monthEnglish" $LOG_PREFIX-error.log*|grep -c "$year") local errorRequestCount
errorRequestCount=$(zgrep "$monthEnglish" "$LOG_PREFIX-error.log*"|grep -c "$year")
echo "Nombre de requêtes http en erreur = $errorRequestCount" echo "Nombre de requêtes http en erreur = $errorRequestCount"
local ipv4VisitorCount=$(zgrep -h "$monthEnglish" $LOG_PREFIX-access.log*|grep "$year"|grep -vi bot|grep -v check_http|grep -E "^$IPV4_PATTERN "|cut -d' ' -f1|sort|uniq|wc -l ) local ipv4VisitorCount
ipv4VisitorCount=$(zgrep -h "$monthEnglish" $LOG_PREFIX-access.log*|grep "$year"|grep -vi bot|grep -v check_http|grep -E "^$IPV4_PATTERN "|cut -d' ' -f1|sort|uniq|wc -l )
echo "Nombre d'ipv4 ayant visité le service = $ipv4VisitorCount" echo "Nombre d'ipv4 ayant visité le service = $ipv4VisitorCount"
local ipv6VisitorCount=$(zgrep -h "$monthEnglish" $LOG_PREFIX-access.log*|grep "$year"|grep -vi bot|grep -v check_http|grep -E "^$IPV6_PATTERN "|cut -d' ' -f1|sort|uniq|wc -l ) local ipv6VisitorCount
ipv6VisitorCount=$(zgrep -h "$monthEnglish" $LOG_PREFIX-access.log*|grep "$year"|grep -vi bot|grep -v check_http|grep -E "^$IPV6_PATTERN "|cut -d' ' -f1|sort|uniq|wc -l )
echo "Nombre d'ipv6 ayant visité le service = $ipv6VisitorCount" echo "Nombre d'ipv6 ayant visité le service = $ipv6VisitorCount"
echo "Nombre total d'ip ayant visité le service = $((ipv4VisitorCount+ipv6VisitorCount))" echo "Nombre total d'ip ayant visité le service = $((ipv4VisitorCount+ipv6VisitorCount))"
@ -95,45 +101,56 @@ generateSpecificReport()
# https://forge.chapril.org/api/swagger # https://forge.chapril.org/api/swagger
#$(curl -s --dump-header - "https://forge.chapril.org/api/v1/admin/orgs?limit=1&page1&token=$GITEA_API_KEY" > t) #$(curl -s --dump-header - "https://forge.chapril.org/api/v1/admin/orgs?limit=1&page1&token=$GITEA_API_KEY" > t)
#$(curl -s "https://forge.chapril.org/api/v1/users/search?limit=1&token=$GITEA_API_KEY" | jq '. | length' > t) #$(curl -s "https://forge.chapril.org/api/v1/users/search?limit=1&token=$GITEA_API_KEY" | jq '. | length' > t)
local accountCount=$(curl -s "https://forge.chapril.org/api/v1/users/search?limit=100000&token=$GITEA_API_KEY" | jq '.data | length') local accountCount
accountCount=$(curl -s "https://forge.chapril.org/api/v1/users/search?limit=100000&token=$GITEA_API_KEY" | jq '.data | length')
echo "Nombre de comptes = $accountCount" echo "Nombre de comptes = $accountCount"
local connectedAccountCount=$(curl -s "https://forge.chapril.org/api/v1/users/search?limit=100000&token=$GITEA_API_KEY" | jq '.data[].last_login' | grep -cv "1970") local connectedAccountCount
connectedAccountCount=$(curl -s "https://forge.chapril.org/api/v1/users/search?limit=100000&token=$GITEA_API_KEY" | jq '.data[].last_login' | grep -cv "1970")
echo "Nombre de comptes connectés au moins une fois = $connectedAccountCount" echo "Nombre de comptes connectés au moins une fois = $connectedAccountCount"
local unconnectedAccountCount=$(curl -s "https://forge.chapril.org/api/v1/users/search?limit=100000&token=$GITEA_API_KEY" | jq '.data[].last_login' | grep -c "1970") local unconnectedAccountCount
unconnectedAccountCount=$(curl -s "https://forge.chapril.org/api/v1/users/search?limit=100000&token=$GITEA_API_KEY" | jq '.data[].last_login' | grep -c "1970")
echo "Nombre de comptes jamais connectés = $unconnectedAccountCount" echo "Nombre de comptes jamais connectés = $unconnectedAccountCount"
#$(curl -s "https://forge.chapril.org/api/v1/admin/orgs?limit=100000&token=$GITEA_API_KEY" | jq '. | length' > t) #$(curl -s "https://forge.chapril.org/api/v1/admin/orgs?limit=100000&token=$GITEA_API_KEY" | jq '. | length' > t)
local organizationCount=$(curl -s "https://forge.chapril.org/api/v1/admin/orgs?limit=100000&token=$GITEA_API_KEY" | jq '. | length') local organizationCount
organizationCount=$(curl -s "https://forge.chapril.org/api/v1/admin/orgs?limit=100000&token=$GITEA_API_KEY" | jq '. | length')
if [[ -z "$organizationCount" ]]; then if [[ -z "$organizationCount" ]]; then
organizationCount=0 organizationCount=0
fi fi
echo "Nombre d'organisations = $organizationCount" echo "Nombre d'organisations = $organizationCount"
#$(curl -s "https://forge.chapril.org/api/v1/orgs?limit=100000" > t) #$(curl -s "https://forge.chapril.org/api/v1/orgs?limit=100000" > t)
local publicOrganizationCount=$(curl -s "https://forge.chapril.org/api/v1/orgs?limit=100000" | jq '. | length') local publicOrganizationCount
publicOrganizationCount=$(curl -s "https://forge.chapril.org/api/v1/orgs?limit=100000" | jq '. | length')
if [[ -z "$publicOrganizationCount" ]]; then if [[ -z "$publicOrganizationCount" ]]; then
publicOrganizationCount=0 publicOrganizationCount=0
fi fi
echo "Nombre d'organisations publiques = $publicOrganizationCount" echo "Nombre d'organisations publiques = $publicOrganizationCount"
local repositoryCount=$(curl -s --dump-header - "https://forge.chapril.org/api/v1/repos/search?limit=1&token=$GITEA_API_KEY" | grep "X-Total-Count\:" | awk '{ print $2 }' | jq '.') local repositoryCount
repositoryCount=$(curl -s --dump-header - "https://forge.chapril.org/api/v1/repos/search?limit=1&token=$GITEA_API_KEY" | grep "X-Total-Count\:" | awk '{ print $2 }' | jq '.')
echo "Nombre de dépôts = $repositoryCount" echo "Nombre de dépôts = $repositoryCount"
local publicRepositoryCount=$(curl -s --dump-header - "https://forge.chapril.org/api/v1/repos/search?limit=1" | grep "X-Total-Count\:" | awk '{ print $2 }' | jq '.') local publicRepositoryCount
publicRepositoryCount=$(curl -s --dump-header - "https://forge.chapril.org/api/v1/repos/search?limit=1" | grep "X-Total-Count\:" | awk '{ print $2 }' | jq '.')
echo "Nombre de dépôts publics = $publicRepositoryCount" echo "Nombre de dépôts publics = $publicRepositoryCount"
local repositorySpaceDisk=$(du -sh "$GITEA_REPO_HOME" | head -1 | awk '{ print $1 } ') local repositorySpaceDisk
repositorySpaceDisk=$(du -sh "$GITEA_REPO_HOME" | head -1 | awk '{ print $1 } ')
echo "Espace disque occupé par les dépôts = $repositorySpaceDisk" echo "Espace disque occupé par les dépôts = $repositorySpaceDisk"
local directoryCount=$(find "$GITEA_REPO_HOME" -type d | wc -l ) local directoryCount
directoryCount=$(find "$GITEA_REPO_HOME" -type d | wc -l )
echo "Nombre de dossiers de l'espace disque = $directoryCount" echo "Nombre de dossiers de l'espace disque = $directoryCount"
local fileCount=$(find "$GITEA_REPO_HOME" -type f | wc -l ) local fileCount
fileCount=$(find "$GITEA_REPO_HOME" -type f | wc -l )
echo "Nombre de fichiers de l'espace disque = $fileCount" echo "Nombre de fichiers de l'espace disque = $fileCount"
local totalFileCount=$(find "$GITEA_REPO_HOME" | wc -l ) local totalFileCount
totalFileCount=$(find "$GITEA_REPO_HOME" | wc -l )
echo "Nombre total de fichiers de l'espace disque = $totalFileCount" echo "Nombre total de fichiers de l'espace disque = $totalFileCount"
echo echo
@ -169,13 +186,13 @@ elif [ "$#" = 1 ] && [ "$1" = "-p" ]; then
year="$(($(date +%Y)-1))" year="$(($(date +%Y)-1))"
yearMonth="$year-$precedingMonth" yearMonth="$year-$precedingMonth"
fi fi
monthEnglish=$(LANG=en_EN.UTF-8;date -d $year-$precedingMonth-01 +%b) monthEnglish=$(LANG=en_EN.UTF-8;date -d "$year-$precedingMonth-01" +%b)
generateReport "$monthEnglish" "$year" "$yearMonth" generateReport "$monthEnglish" "$year" "$yearMonth"
elif [ "$#" -eq 2 ]; then elif [ "$#" -eq 2 ]; then
if ! (let "$1") 2>/dev/null; then if ! (let "$1") 2>/dev/null; then
echo -e "Le mois doit être numérique." echo -e "Le mois doit être numérique."
help help
elif ([ "$1" -lt 1 ] || [ "$1" -gt 12 ]); then elif [ "$1" -lt 1 ] || [ "$1" -gt 12 ]; then
echo -e "Numéro du mois non valable $1." echo -e "Numéro du mois non valable $1."
help help
elif ! (let "$2") 2>/dev/null; then elif ! (let "$2") 2>/dev/null; then