2022-10-25 16:22:38 +03:00
|
|
|
#!/bin/bash
|
2022-12-14 11:28:25 +03:00
|
|
|
set -Eeuo pipefail
|
|
|
|
|
|
|
|
color_red=$(echo -e "\033[1;31m")
|
2022-12-28 12:33:04 +03:00
|
|
|
color_green=$(echo -ne "\033[1;32m")
|
2022-12-14 11:28:25 +03:00
|
|
|
color_reset=$(echo -e "\033[0m")
|
|
|
|
errors_count=0
|
2022-10-25 16:22:38 +03:00
|
|
|
|
2022-12-14 12:00:47 +03:00
|
|
|
# Check *.rs Orange Copyright
|
|
|
|
echo "------------------------------------------------------------------------------------------"
|
|
|
|
while read -r rust_file ; do
|
2023-01-02 15:39:35 +03:00
|
|
|
if [ "$(grep -c "Copyright (C) 2023 Orange" "$rust_file" || true)" -eq 0 ] ; then
|
|
|
|
echo "Missing [Copyright (C) 2023 Orange] in ${color_red}${rust_file}${color_reset}"
|
2022-12-14 12:00:47 +03:00
|
|
|
((errors_count++))
|
2022-12-28 12:33:04 +03:00
|
|
|
else
|
2023-01-02 15:39:35 +03:00
|
|
|
echo "[Copyright (C) 2023 Orange] is present in ${color_green}${rust_file}${color_reset}"
|
2022-10-25 16:22:38 +03:00
|
|
|
fi
|
2022-12-14 12:00:47 +03:00
|
|
|
done < <(find packages -type f -name "*.rs")
|
|
|
|
|
|
|
|
# Check *sh bash shebang at line 1
|
|
|
|
echo "------------------------------------------------------------------------------------------"
|
|
|
|
while read -r script ; do
|
|
|
|
if [ "$(head -1 "$script" | grep -c "#!/bin/bash" || true)" -eq 0 ] ; then
|
|
|
|
echo "Missing [#!/bin/bash] shebang in ${color_red}${script}${color_reset}"
|
|
|
|
((errors_count++))
|
2022-12-28 12:33:04 +03:00
|
|
|
else
|
|
|
|
echo "[#!/bin/bash] shebang is present in ${color_green}${script}${color_reset}"
|
2022-12-14 12:00:47 +03:00
|
|
|
fi
|
|
|
|
done < <(find . -type f -name "*.sh")
|
|
|
|
|
2022-12-11 13:57:19 +03:00
|
|
|
# Check *sh error handling at first uncommented line
|
2022-12-14 12:00:47 +03:00
|
|
|
echo "------------------------------------------------------------------------------------------"
|
|
|
|
while read -r script ; do
|
2022-12-11 13:57:19 +03:00
|
|
|
if [ "$(grep -Ev "^$|^#" "$script" | head -1 | grep -c "set -Eeuo pipefail" || true)" -eq 0 ] ; then
|
2022-12-14 12:00:47 +03:00
|
|
|
echo "Missing [set -Eeuo pipefail] in ${color_red}${script}${color_reset}"
|
|
|
|
((errors_count++))
|
2022-12-28 12:33:04 +03:00
|
|
|
else
|
|
|
|
echo "[set -Eeuo pipefail] is present in ${color_green}${script}${color_reset}"
|
2022-12-14 12:00:47 +03:00
|
|
|
fi
|
|
|
|
done < <(find . -type f -name "*.sh")
|
|
|
|
|
2023-04-14 15:47:12 +03:00
|
|
|
# Check *PS1 error handling at two first lines
|
2022-12-28 12:20:27 +03:00
|
|
|
echo "------------------------------------------------------------------------------------------"
|
|
|
|
while read -r script ; do
|
|
|
|
if [ "$(head -1 "$script" | grep -c "Set-StrictMode -Version latest" || true)" -eq 0 ] ; then
|
|
|
|
echo "Missing [Set-StrictMode -Version latest] in first line of ${color_red}${script}${color_reset}"
|
|
|
|
((errors_count++))
|
2022-12-28 12:33:04 +03:00
|
|
|
else
|
|
|
|
echo "[Set-StrictMode -Version latest] is present in first line of ${color_green}${script}${color_reset}"
|
2022-12-28 12:20:27 +03:00
|
|
|
fi
|
|
|
|
if [ "$(head -2 "$script" | tail -1 | grep -c "\$ErrorActionPreference = 'Stop'" || true)" -eq 0 ] ; then
|
|
|
|
echo "Missing [\$ErrorActionPreference = 'Stop'] in second line of ${color_red}${script}${color_reset}"
|
|
|
|
((errors_count++))
|
2022-12-28 12:33:04 +03:00
|
|
|
else
|
|
|
|
echo "[\$ErrorActionPreference = 'Stop'] is present in second line of ${color_green}${script}${color_reset}"
|
2022-12-28 12:20:27 +03:00
|
|
|
fi
|
2022-12-28 12:33:04 +03:00
|
|
|
done < <(find . -type f -name "*.ps1")
|
2022-12-28 12:20:27 +03:00
|
|
|
|
2022-12-14 12:00:47 +03:00
|
|
|
# Control errors count
|
|
|
|
if [ "${errors_count}" -gt 0 ] ; then
|
|
|
|
exit 1
|
|
|
|
fi
|
2022-10-25 16:22:38 +03:00
|
|
|
|