Commit 382fcee3 authored by Antoine Le Gonidec's avatar Antoine Le Gonidec

2.10.4 — Improve ShellCheck tests coverage

+ Fix syntax issues reported by ShellCheck
parent 806c500e
Pipeline #85413 passed with stage
in 29 seconds
......@@ -10,6 +10,7 @@ shellcheck:
- pacman --noconfirm -S make shellcheck
script:
- ./tests/shellcheck-lib.sh
- ./tests/shellcheck-main-script.sh
artifacts:
paths:
- play.it-2/lib/libplayit2.sh
......@@ -29,6 +29,7 @@ if [ -z "$PLAYIT_LIB2" ]; then
return 1
fi
fi
# shellcheck source=play.it-2/lib/libplayit2.sh
. "$PLAYIT_LIB2"
if [ "$#" = 0 ]; then
......@@ -40,12 +41,14 @@ if [ ! -f "$INPUT_FILE" ]; then
print_error
case "${LANG%_*}" in
('fr')
# shellcheck disable=SC1112
string='%s n’est pas un fichier valide\n'
;;
('en'|*)
string='%s is not a valid file\n'
;;
esac
# shellcheck disable=SC2059
printf "$string" "$INPUT_FILE"
return 1
fi
......@@ -54,12 +57,14 @@ fi
FILE_NAME="${INPUT_FILE##*/}"
case "${LANG%_*}" in
('fr')
# shellcheck disable=SC1112
string='Recherche d’un script par nom de fichier pour le fichier %s\n'
;;
('en'|*)
string='Looking for a script by file name for file %s\n'
;;
esac
# shellcheck disable=SC2059
printf "$string" "$FILE_NAME"
SCRIPT="$(grep --dereference-recursive --files-with-matches "ARCHIVE_.\\+='$FILE_NAME'" "$XDG_DATA_HOME/play.it/play.it-2/" '/usr/local/share/games/play.it/' '/usr/local/share/play.it/' '/usr/share/games/play.it/' '/usr/share/play.it/' 2>/dev/null | head --lines=1)"
......@@ -67,15 +72,17 @@ SCRIPT="$(grep --dereference-recursive --files-with-matches "ARCHIVE_.\\+='$FILE
if [ -z "$SCRIPT" ]; then
case "${LANG%_*}" in
('fr')
# shellcheck disable=SC1112
string='Recherche d’un script par somme de contrôle MD5 pour le fichier %s\n'
;;
('en'|*)
string='Looking for a script by MD5 hash sum for file %s\n'
;;
esac
# shellcheck disable=SC2059
printf "$string" "$FILE_NAME"
check_deps 'md5sum'
FILE_MD5="$(md5sum $INPUT_FILE | cut --delimiter=' ' --fields=1)"
FILE_MD5="$(md5sum "$INPUT_FILE" | cut --delimiter=' ' --fields=1)"
SCRIPT="$(grep --dereference-recursive --files-with-matches "$FILE_MD5" "$XDG_DATA_HOME/play.it/play.it-2/" '/usr/local/share/games/play.it/' '/usr/local/share/play.it/' '/usr/share/games/play.it/' '/usr/share/play.it/' 2>/dev/null | head --lines=1)"
SCRIPT_OPTIONS='--checksum=none'
fi
......@@ -90,6 +97,7 @@ if [ -z "$SCRIPT" ]; then
string='Could not find script for file %s\n'
;;
esac
# shellcheck disable=SC2059
printf "$string" "$FILE_NAME"
return 1
fi
......
2.10.4
* Improve ShellCheck tests coverage
2.10.3
* write_bin - init_prefix_files: Do not ignore symbolic links in
......
......@@ -35,6 +35,7 @@
# send your bug reports to vv221@dotslashplay.it
###
library_version=2.10.3
library_revision=20180929.3
library_version=2.10.4~dev
# shellcheck disable=SC2034
library_revision=20181105.7
......@@ -126,7 +126,7 @@ use_archive_specific_value() {
value="$(get_value "$name")"
if [ -n "$value" ]; then
eval $name_real=\"$value\"
export $name_real
export ${name_real?}
return 0
fi
name="${name%_*}"
......@@ -147,7 +147,7 @@ use_package_specific_value() {
value="$(get_value "$name")"
if [ -n "$value" ]; then
eval $name_real=\"$value\"
export $name_real
export ${name_real?}
return 0
fi
name="${name%_*}"
......
......@@ -19,6 +19,7 @@ archive_set_error_not_found() {
local string_single
case "${LANG%_*}" in
('fr')
# shellcheck disable=SC1112
string_multiple='Aucun des fichiers suivants n’est présent :'
string_single='Le fichier suivant est introuvable :'
;;
......@@ -138,7 +139,7 @@ archive_get_infos() {
type="$(get_value "${ARCHIVE}_TYPE")"
fi
eval ${name}_TYPE=\"$type\"
export ${name}_TYPE
export ${name?}_TYPE
check_deps
if [ -n "$size" ]; then
[ -n "$ARCHIVE_SIZE" ] || ARCHIVE_SIZE='0'
......@@ -146,7 +147,7 @@ archive_get_infos() {
fi
export ARCHIVE_SIZE
export PKG_VERSION
export $name
export ${name?}
export ARCHIVE
}
......@@ -196,7 +197,7 @@ archive_guess_type() {
;;
esac
eval ${archive}_TYPE=\'$type\'
export ${archive}_TYPE
export ${archive?}_TYPE
}
# display an error message if archive_guess_type failed to guess the type of an archive
......@@ -206,6 +207,7 @@ archive_guess_type_error() {
local string
case "${LANG%_*}" in
('fr')
# shellcheck disable=SC1112
string='ARCHIVE_TYPE n’est pas défini pour %s et n’a pas pu être détecté automatiquement.'
;;
('en'|*)
......@@ -281,6 +283,7 @@ archive_integrity_check_print() {
file="$1"
case "${LANG%_*}" in
('fr')
# shellcheck disable=SC1112
string='Contrôle de l’intégrité de %s'
;;
('en'|*)
......@@ -298,6 +301,7 @@ archive_integrity_check_error() {
local string2
case "${LANG%_*}" in
('fr')
# shellcheck disable=SC1112
string1='Somme de contrôle incohérente. %s n’est pas le fichier attendu.'
string2='Utilisez --checksum=none pour forcer son utilisation.'
;;
......@@ -318,7 +322,7 @@ archives_get_list() {
local script
[ -n "$ARCHIVES_LIST" ] && return 0
script="$0"
while read archive; do
while read -r archive; do
if [ -z "$ARCHIVES_LIST" ]; then
ARCHIVES_LIST="$archive"
else
......
......@@ -8,6 +8,7 @@ help() {
case "${LANG%_*}" in
('fr')
string='Utilisation :'
# shellcheck disable=SC1112
string_archive='Ce script reconnaît l’archive suivante :'
string_archives='Ce script reconnaît les archives suivantes :'
;;
......@@ -59,10 +60,12 @@ help_architecture() {
local string_auto
case "${LANG%_*}" in
('fr')
# shellcheck disable=SC1112
string='Choix de l’architecture à construire'
string_all='toutes les architectures disponibles (méthode par défaut)'
string_32='paquets 32-bit seulement'
string_64='paquets 64-bit seulement'
# shellcheck disable=SC1112
string_auto='paquets pour l’architecture du système courant uniquement'
;;
('en'|*)
......@@ -92,6 +95,7 @@ help_checksum() {
local string_none
case "${LANG%_*}" in
('fr')
# shellcheck disable=SC1112
string='Choix de la méthode de vérification d’intégrité de l’archive'
string_md5='vérification via md5sum (méthode par défaut)'
string_none='pas de vérification'
......@@ -153,6 +157,7 @@ help_prefix() {
local string_default
case "${LANG%_*}" in
('fr')
# shellcheck disable=SC1112
string='Choix du chemin d’installation du jeu'
string_absolute='Cette option accepte uniquement un chemin absolu.'
string_default='chemin par défaut :'
......@@ -210,6 +215,7 @@ help_dryrun() {
local string
case "${LANG%_*}" in
('fr')
# shellcheck disable=SC1112
string='Effectue des tests de syntaxe mais n’extrait pas de données et ne construit pas de paquets.'
;;
('en'|*)
......
......@@ -6,7 +6,9 @@ select_package_architecture() {
[ "$OPTION_ARCHITECTURE" = 'all' ] && return 0
local version_major_target
local version_minor_target
# shellcheck disable=SC2154
version_major_target="${target_version%%.*}"
# shellcheck disable=SC2154
version_minor_target=$(printf '%s' "$target_version" | cut --delimiter='.' --fields=2)
if [ $version_major_target -lt 2 ] || [ $version_minor_target -lt 6 ]; then
select_package_architecture_warning_unsupported
......@@ -83,6 +85,7 @@ select_package_architecture_warning_unavailable() {
local string
case "${LANG%_*}" in
('fr')
# shellcheck disable=SC1112
string='L’architecture demandée n’est pas disponible : %s\n'
;;
('en'|*)
......@@ -101,6 +104,7 @@ select_package_architecture_error_unknown() {
local string
case "${LANG%_*}" in
('fr')
# shellcheck disable=SC1112
string='L’architecture demandée n’est pas supportée : %s\n'
;;
('en'|*)
......@@ -120,6 +124,7 @@ select_package_architecture_warning_unsupported() {
local string
case "${LANG%_*}" in
('fr')
# shellcheck disable=SC1112
string='L’option --architecture n’est pas gérée par ce script.'
;;
('en'|*)
......
......@@ -7,6 +7,7 @@ get_package_version() {
if [ -z "$PKG_VERSION" ]; then
PKG_VERSION='1.0-1'
fi
# shellcheck disable=SC2154
PKG_VERSION="${PKG_VERSION}+$script_version"
export PKG_VERSION
}
......
......@@ -86,7 +86,7 @@ set_temp_directories_pkg() {
pkg_id="$(get_value "${PKG}_ID")"
if [ -z "$pkg_id" ]; then
eval ${PKG}_ID=\"$GAME_ID\"
export ${PKG}_ID
export ${PKG?}_ID
pkg_id="$GAME_ID"
fi
......@@ -100,7 +100,7 @@ set_temp_directories_pkg() {
fi
get_package_version
eval ${PKG}_PATH=\"$PLAYIT_WORKDIR/${pkg_id}_${PKG_VERSION}_${pkg_architecture}\"
export ${PKG}_PATH
export ${PKG?}_PATH
}
# display an error if set_temp_directories() is called before setting $ARCHIVE_SIZE
......@@ -131,6 +131,7 @@ set_temp_directories_error_not_enough_space() {
print_error
case "${LANG%_*}" in
('fr')
# shellcheck disable=SC1112
string='Il n’y a pas assez d’espace libre dans les différents répertoires testés :\n'
;;
('en'|*)
......
......@@ -131,6 +131,7 @@ archive_extraction_innosetup_error_version() {
print_error
case "${LANG%_*}" in
('fr')
# shellcheck disable=SC1112
string='La version de innoextract disponible sur ce système est trop ancienne pour extraire les données de l’archive suivante :'
;;
('en'|*)
......
......@@ -27,6 +27,7 @@ prepare_package_layout_error_no_list() {
print_error
case "${LANG%_*}" in
('fr')
# shellcheck disable=SC1112
string='prepare_package_layout ne peut pas être appelé sans argument si $PACKAGES_LIST n’est pas défini.'
;;
('en'|*)
......@@ -83,6 +84,7 @@ organize_data_error_missing_pkg() {
print_error
case "${LANG%_*}" in
('fr')
# shellcheck disable=SC1112
string='organize_data ne peut pas être appelé si $PKG n’est pas défini.\n'
;;
('en'|*)
......
......@@ -249,7 +249,9 @@ icon_get_resolution_from_file() {
local version_major_target
local version_minor_target
file="$1"
# shellcheck disable=SC2154
version_major_target="${target_version%%.*}"
# shellcheck disable=SC2154
version_minor_target=$(printf '%s' "$target_version" | cut --delimiter='.' --fields=2)
if
{ [ $version_major_target -lt 2 ] || [ $version_minor_target -lt 8 ] ; } &&
......@@ -282,7 +284,9 @@ icons_linking_postinst() {
local path_pkg
local version_major_target
local version_minor_target
# shellcheck disable=SC2154
version_major_target="${target_version%%.*}"
# shellcheck disable=SC2154
version_minor_target=$(printf '%s' "$target_version" | cut --delimiter='.' --fields=2)
path_pkg="$(get_value "${PKG}_PATH")"
[ -n "$path_pkg" ] || missing_pkg_error 'icons_linking_postinst' "$PKG"
......@@ -366,6 +370,7 @@ icon_file_not_found_error() {
file="$1"
case "${LANG%_*}" in
('fr')
# shellcheck disable=SC1112
string1='Le fichier d’icône suivant est introuvable : %s'
string2='Merci de signaler cette erreur sur notre outil de gestion de bugs : %s'
;;
......
......@@ -6,8 +6,11 @@
write_bin_winecfg() {
if [ "$winecfg_launcher" != '1' ]; then
winecfg_launcher='1'
# shellcheck disable=SC2034
APP_WINECFG_ID="${GAME_ID}_winecfg"
# shellcheck disable=SC2034
APP_WINECFG_TYPE='wine'
# shellcheck disable=SC2034
APP_WINECFG_EXE='winecfg'
write_bin 'APP_WINECFG'
local target
......@@ -133,8 +136,11 @@ write_desktop_winecfg() {
local pkg_path
pkg_path="$(get_value "${PKG}_PATH")"
[ -n "$pkg_path" ] || missing_pkg_error 'write_desktop_winecfg' "$PKG"
# shellcheck disable=SC2034
APP_WINECFG_ID="${GAME_ID}_winecfg"
# shellcheck disable=SC2034
APP_WINECFG_NAME="$GAME_NAME - WINE configuration"
# shellcheck disable=SC2034
APP_WINECFG_CAT='Settings'
write_desktop 'APP_WINECFG'
sed --in-place 's/Icon=.\+/Icon=winecfg/' "${pkg_path}${PATH_DESK}/${APP_WINECFG_ID}.desktop"
......
......@@ -140,6 +140,7 @@ packages_guess_format() {
print_warning
case "${LANG%_*}" in
('fr')
# shellcheck disable=SC1112
string1='L’auto-détection du format de paquet le plus adapté a échoué.\n'
string2='Le format de paquet %s sera utilisé par défaut.\n'
;;
......@@ -153,6 +154,6 @@ packages_guess_format() {
printf '\n'
;;
esac
export $variable_name
export ${variable_name?}
}
......@@ -5,6 +5,7 @@
pkg_write_arch() {
local pkg_deps
if [ "$(get_value "${pkg}_DEPS")" ]; then
# shellcheck disable=SC2046
pkg_set_deps_arch $(get_value "${pkg}_DEPS")
fi
use_archive_specific_value "${pkg}_DEPS_ARCH"
......@@ -31,10 +32,12 @@ pkg_write_arch() {
EOF
if [ -n "$pkg_description" ]; then
# shellcheck disable=SC2154
cat >> "$target" <<- EOF
pkgdesc = $GAME_NAME - $pkg_description - ./play.it script version $script_version
EOF
else
# shellcheck disable=SC2154
cat >> "$target" <<- EOF
pkgdesc = $GAME_NAME - ./play.it script version $script_version
EOF
......@@ -327,7 +330,7 @@ pkg_build_arch() {
if [ -e "$pkg_filename" ]; then
pkg_build_print_already_exists "${pkg_filename##*/}"
eval ${pkg}_PKG=\"$pkg_filename\"
export ${pkg}_PKG
export ${pkg?}_PKG
return 0
fi
......@@ -357,7 +360,7 @@ pkg_build_arch() {
if [ "$DRY_RUN" = '1' ]; then
printf '\n'
eval ${pkg}_PKG=\"$pkg_filename\"
export ${pkg}_PKG
export ${pkg?}_PKG
return 0
fi
......@@ -372,7 +375,7 @@ pkg_build_arch() {
)
eval ${pkg}_PKG=\"$pkg_filename\"
export ${pkg}_PKG
export ${pkg?}_PKG
print_ok
}
......
......@@ -5,6 +5,7 @@
pkg_write_deb() {
local pkg_deps
if [ "$(get_value "${pkg}_DEPS")" ]; then
# shellcheck disable=SC2046
pkg_set_deps_deb $(get_value "${pkg}_DEPS")
fi
use_archive_specific_value "${pkg}_DEPS_DEB"
......@@ -50,11 +51,13 @@ pkg_write_deb() {
fi
if [ -n "$pkg_description" ]; then
# shellcheck disable=SC2154
cat >> "$target" <<- EOF
Description: $GAME_NAME - $pkg_description
./play.it script version $script_version
EOF
else
# shellcheck disable=SC2154
cat >> "$target" <<- EOF
Description: $GAME_NAME
./play.it script version $script_version
......@@ -231,7 +234,7 @@ pkg_build_deb() {
if [ -e "$pkg_filename" ]; then
pkg_build_print_already_exists "${pkg_filename##*/}"
eval ${pkg}_PKG=\"$pkg_filename\"
export ${pkg}_PKG
export ${pkg?}_PKG
return 0
fi
......@@ -249,12 +252,12 @@ pkg_build_deb() {
if [ "$DRY_RUN" = '1' ]; then
printf '\n'
eval ${pkg}_PKG=\"$pkg_filename\"
export ${pkg}_PKG
export ${pkg?}_PKG
return 0
fi
TMPDIR="$PLAYIT_WORKDIR" fakeroot -- dpkg-deb $dpkg_options --build "$1" "$pkg_filename" 1>/dev/null
eval ${pkg}_PKG=\"$pkg_filename\"
export ${pkg}_PKG
export ${pkg?}_PKG
print_ok
}
......
......@@ -6,9 +6,11 @@ if [ "${0##*/}" != 'libplayit2.sh' ] && [ -z "$LIB_ONLY" ]; then
# Check library version against script target version
version_major_library="${library_version%%.*}"
# shellcheck disable=SC2154
version_major_target="${target_version%%.*}"
version_minor_library=$(printf '%s' "$library_version" | cut --delimiter='.' --fields=2)
# shellcheck disable=SC2154
version_minor_target=$(printf '%s' "$target_version" | cut --delimiter='.' --fields=2)
if [ $version_major_library -ne $version_major_target ] || [ $version_minor_library -lt $version_minor_target ]; then
......@@ -24,6 +26,7 @@ if [ "${0##*/}" != 'libplayit2.sh' ] && [ -z "$LIB_ONLY" ]; then
;;
esac
printf "$string1"
# shellcheck disable=SC2154
printf "$string2" "$target_version"
exit 1
fi
......@@ -34,17 +37,26 @@ if [ "${0##*/}" != 'libplayit2.sh' ] && [ -z "$LIB_ONLY" ]; then
# Set allowed values for common options
# shellcheck disable=SC2034
ALLOWED_VALUES_ARCHITECTURE='all 32 64 auto'
# shellcheck disable=SC2034
ALLOWED_VALUES_CHECKSUM='none md5'
# shellcheck disable=SC2034
ALLOWED_VALUES_COMPRESSION='none gzip xz bzip2'
# shellcheck disable=SC2034
ALLOWED_VALUES_PACKAGE='arch deb'
# Set default values for common options
# shellcheck disable=SC2034
DEFAULT_OPTION_ARCHITECTURE='all'
# shellcheck disable=SC2034
DEFAULT_OPTION_CHECKSUM='md5'
# shellcheck disable=SC2034
DEFAULT_OPTION_COMPRESSION='none'
# shellcheck disable=SC2034
DEFAULT_OPTION_PREFIX='/usr/local'
# shellcheck disable=SC2034
DEFAULT_OPTION_PACKAGE='deb'
unset winecfg_desktop
unset winecfg_launcher
......@@ -87,7 +99,9 @@ if [ "${0##*/}" != 'libplayit2.sh' ] && [ -z "$LIB_ONLY" ]; then
eval help_$option
exit 0
else
# shellcheck disable=SC2046
eval OPTION_$(printf '%s' "$option" | tr '[:lower:]' '[:upper:]')=\"$value\"
# shellcheck disable=SC2046
export OPTION_$(printf '%s' "$option" | tr '[:lower:]' '[:upper:]')
fi
unset option
......@@ -127,6 +141,7 @@ if [ "${0##*/}" != 'libplayit2.sh' ] && [ -z "$LIB_ONLY" ]; then
for option in 'ARCHITECTURE' 'CHECKSUM' 'COMPRESSION' 'PREFIX'; do
if [ -z "$(get_value "OPTION_$option")" ]\
&& [ -n "$(get_value "DEFAULT_OPTION_$option")" ]; then
# shellcheck disable=SC2046
eval OPTION_$option=\"$(get_value "DEFAULT_OPTION_$option")\"
export OPTION_$option
fi
......@@ -151,7 +166,9 @@ if [ "${0##*/}" != 'libplayit2.sh' ] && [ -z "$LIB_ONLY" ]; then
local string2
case "${LANG%_*}" in
('fr')
# shellcheck disable=SC1112
string1='%s n’est pas une valeur valide pour --%s.\n'
# shellcheck disable=SC1112
string2='Lancez le script avec l’option --%s=help pour une liste des valeurs acceptés.\n'
;;
('en'|*)
......@@ -178,6 +195,7 @@ if [ "${0##*/}" != 'libplayit2.sh' ] && [ -z "$LIB_ONLY" ]; then
print_error
case "${LANG%_*}" in
('fr')
# shellcheck disable=SC1112
string='Le mode de compression bzip2 n’est pas compatible avec la génération de paquets deb.'
;;
('en'|*)
......
......@@ -2,6 +2,10 @@
set -o errexit
make libplayit2.sh
shellcheck --shell=sh --exclude=SC2016,SC2034,SC2039,SC2046,SC2059,SC2086,SC1112,SC2154,SC2163,SC2162 'play.it-2/lib/libplayit2.sh'
file='play.it-2/lib/libplayit2.sh'
for shell in 'sh' 'bash' 'dash' 'ksh'; do
printf 'Testing %s validity using ShellCheck in %s mode…\n' "$file" "$shell"
shellcheck --shell="$shell" --exclude=SC2016,SC2039,SC2059,SC2086 "$file"
done
exit 0
#!/usr/bin/env sh
set -o errexit
file='play.it'
for shell in 'sh' 'bash' 'dash' 'ksh'; do
printf 'Testing %s validity using ShellCheck in %s mode…\n' "$file" "$shell"
shellcheck --external-sources --shell="$shell" "$file"
done
exit 0
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment