From a1abb46b90b492faba7142bde49ccff20f143a1d Mon Sep 17 00:00:00 2001 From: Christian Hoffmann Date: Thu, 24 Mar 2022 00:02:43 +0100 Subject: [PATCH 1/2] mac/deploy_may.sh: Replace eval magic by explicit variables The previous logic used eval to dynamically create variables. This is hard to follow. Instead, explicitly name the relevant two variables. Also, introduce readable variable names. Related: #2474 --- mac/deploy_mac.sh | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/mac/deploy_mac.sh b/mac/deploy_mac.sh index 58ec0b6c43..175641f586 100755 --- a/mac/deploy_mac.sh +++ b/mac/deploy_mac.sh @@ -41,6 +41,8 @@ cleanup() build_app() { + local client_or_server="${1}" + # Build Jamulus qmake "${project_path}" -o "${build_path}/Makefile" "CONFIG+=release" ${@:2} local target_name=$(sed -nE 's/^QMAKE_TARGET *= *(.*)$/\1/p' "${build_path}/Makefile") @@ -60,12 +62,25 @@ build_app() make -f "${build_path}/Makefile" -C "${build_path}" distclean # Return app name for installer image - eval "$1=${target_name}" + case "${client_or_server}" in + client_app) + CLIENT_TARGET_NAME="${target_name}" + ;; + server_app) + SERVER_TARGET_NAME="${target_name}" + ;; + *) + echo "build_app: invalid parameter '${client_or_server}'" + exit 1 + esac } build_installer_image() { + local client_target_name="${1}" + local server_target_name="${2}" + # Install create-dmg via brew. brew needs to be installed first. # Download and later install. This is done to make caching possible brew_install_pinned "create-dmg" "1.0.9" @@ -76,17 +91,17 @@ build_installer_image() # Build installer image create-dmg \ - --volname "${1} Installer" \ + --volname "${client_target_name} Installer" \ --background "${resources_path}/installerbackground.png" \ --window-pos 200 400 \ --window-size 900 320 \ --app-drop-link 820 210 \ --text-size 12 \ --icon-size 72 \ - --icon "${1}.app" 630 210 \ - --icon "${2}.app" 530 210 \ + --icon "${client_target_name}.app" 630 210 \ + --icon "${server_target_name}.app" 530 210 \ --eula "${root_path}/COPYING" \ - "${deploy_path}/$1-${app_version}-installer-mac.dmg" \ + "${deploy_path}/${client_target_name}-${app_version}-installer-mac.dmg" \ "${deploy_path}/" } @@ -132,4 +147,4 @@ build_app client_app build_app server_app "CONFIG+=server_bundle" # Create versioned installer image -build_installer_image "${client_app}" "${server_app}" +build_installer_image "${CLIENT_TARGET_NAME}" "${SERVER_TARGET_NAME}" From 06bffcc4145b4f6731c2b7b55983ecc575446e34 Mon Sep 17 00:00:00 2001 From: Christian Hoffmann Date: Thu, 24 Mar 2022 00:04:57 +0100 Subject: [PATCH 2/2] Scripts: Apply shellcheck suggestions Some suggestions do not apply. For those, a comment is added to disable the check and explain why shellcheck cannot properly judge it. Related: #2474 --- linux/deploy_deb.sh | 2 +- mac/deploy_mac.sh | 55 +++++++++---------- tools/changelog-helper.sh | 67 ++++++++++++++++-------- tools/check-wininstaller-translations.sh | 14 +++-- tools/create-translation-issues.sh | 13 +++-- tools/update-copyright-notices.sh | 5 +- 6 files changed, 91 insertions(+), 65 deletions(-) diff --git a/linux/deploy_deb.sh b/linux/deploy_deb.sh index e59ad7e23d..475463f5b7 100755 --- a/linux/deploy_deb.sh +++ b/linux/deploy_deb.sh @@ -16,7 +16,7 @@ export DEBFULLNAME=GitHubActions DEBEMAIL=noemail@example.com echo -n generating changelog rm -f debian/changelog dch --create --package jamulus --empty --newversion "${VERSION}" '' -perl .github/actions_scripts/getChangelog.pl ChangeLog "${VERSION}" --line-per-entry | while read entry +perl .github/actions_scripts/getChangelog.pl ChangeLog "${VERSION}" --line-per-entry | while read -r entry do echo -n . dch "$entry" diff --git a/mac/deploy_mac.sh b/mac/deploy_mac.sh index 175641f586..9a4514f379 100755 --- a/mac/deploy_mac.sh +++ b/mac/deploy_mac.sh @@ -1,31 +1,28 @@ #!/bin/bash -set -e +set -eu -root_path="$(pwd)" +root_path=$(pwd) project_path="${root_path}/Jamulus.pro" resources_path="${root_path}/src/res" build_path="${root_path}/build" deploy_path="${root_path}/deploy" cert_name="" - while getopts 'hs:' flag; do case "${flag}" in - s) - cert_name=$OPTARG - if [[ -z "$cert_name" ]]; then - echo "Please add the name of the certificate to use: -s \"\"" - fi - # shift 2 - ;; - h) - echo "Usage: -s for signing mac build" - exit 0 - ;; - *) - exit 1 - ;; - + s) + cert_name=$OPTARG + if [[ -z "$cert_name" ]]; then + echo "Please add the name of the certificate to use: -s \"\"" + fi + ;; + h) + echo "Usage: -s for signing mac build" + exit 0 + ;; + *) + exit 1 + ;; esac done @@ -44,9 +41,11 @@ build_app() local client_or_server="${1}" # Build Jamulus - qmake "${project_path}" -o "${build_path}/Makefile" "CONFIG+=release" ${@:2} - local target_name=$(sed -nE 's/^QMAKE_TARGET *= *(.*)$/\1/p' "${build_path}/Makefile") - local job_count="$(sysctl -n hw.ncpu)" + qmake "${project_path}" -o "${build_path}/Makefile" "CONFIG+=release" "${@:2}" + local target_name + target_name=$(sed -nE 's/^QMAKE_TARGET *= *(.*)$/\1/p' "${build_path}/Makefile") + local job_count + job_count=$(sysctl -n hw.ncpu) make -f "${build_path}/Makefile" -C "${build_path}" -j "${job_count}" @@ -75,7 +74,6 @@ build_app() esac } - build_installer_image() { local client_target_name="${1}" @@ -86,7 +84,8 @@ build_installer_image() brew_install_pinned "create-dmg" "1.0.9" # Get Jamulus version - local app_version="$(sed -nE 's/^VERSION *= *(.*)$/\1/p' "${project_path}")" + local app_version + app_version=$(sed -nE 's/^VERSION *= *(.*)$/\1/p' "${project_path}") # Build installer image @@ -103,7 +102,6 @@ build_installer_image() --eula "${root_path}/COPYING" \ "${deploy_path}/${client_target_name}-${app_version}-installer-mac.dmg" \ "${deploy_path}/" - } brew_install_pinned() { @@ -129,16 +127,13 @@ brew_install_pinned() { popd } - # Check that we are running from the correct location -if [ ! -f "${project_path}" ]; -then - echo Please run this script from the Qt project directory where $(basename "${project_path}") is located. - echo Usage: mac/$(basename "${0}") +if [[ ! -f "${project_path}" ]]; then + echo "Please run this script from the Qt project directory where $(basename "${project_path}") is located." + echo "Usage: mac/$(basename "${0}")" exit 1 fi - # Cleanup previous deployments cleanup diff --git a/tools/changelog-helper.sh b/tools/changelog-helper.sh index 0bc0b22aac..abdc8319e6 100755 --- a/tools/changelog-helper.sh +++ b/tools/changelog-helper.sh @@ -29,8 +29,10 @@ declare -A LANGS=( ) find_or_add_missing_entries() { - local changelog=$(sed -rne '/^###.*'"${target_release//./\.}"'\b/,/^### '"${prev_release//./\.}"'\b/p' ChangeLog) - local changelog_begin_position=$(grep -nP '^### .*\d+\.\d+\.\d+\b' ChangeLog | head -n1 | cut -d: -f1) + local changelog + changelog=$(sed -rne '/^###.*'"${target_release//./\.}"'\b/,/^### '"${prev_release//./\.}"'\b/p' ChangeLog) + local changelog_begin_position + changelog_begin_position=$(grep -nP '^### .*\d+\.\d+\.\d+\b' ChangeLog | head -n1 | cut -d: -f1) echo "Checking if all merged Github PRs since ${prev_release} are included for ${target_release}..." for id in $(gh pr list --limit "${PR_LIST_LIMIT}" --search 'milestone:"Release '"${target_release}"'"' --state merged | awk '{print $1}'); do @@ -57,17 +59,22 @@ find_or_add_missing_entries() { } group_entries() { - local changelog_begin_position=$(grep -nP '^### .*\d+\.\d+\.\d+\b' ChangeLog | head -n1 | cut -d: -f1) - local changelog_prev_release_position=$(grep -nP '^### .*\d+\.\d+\.\d+\b' ChangeLog | head -n2 | tail -n1 | cut -d: -f1) + local changelog_begin_position + changelog_begin_position=$(grep -nP '^### .*\d+\.\d+\.\d+\b' ChangeLog | head -n1 | cut -d: -f1) + local changelog_prev_release_position + changelog_prev_release_position=$(grep -nP '^### .*\d+\.\d+\.\d+\b' ChangeLog | head -n2 | tail -n1 | cut -d: -f1) # Save everything before the actual release changelog content: - local changelog_header=$(head -n "${changelog_begin_position}" ChangeLog) + local changelog_header + changelog_header=$(head -n "${changelog_begin_position}" ChangeLog) # Save everything after the actual release changelog content: - local changelog_prev_releases=$(tail -n "+${changelog_prev_release_position}" ChangeLog) + local changelog_prev_releases + changelog_prev_releases=$(tail -n "+${changelog_prev_release_position}" ChangeLog) # Save the current release's changelog content: - local changelog=$(sed -rne '/^###.*'"${target_release//./\.}"'\b/,/^### '"${prev_release//./\.}"'\b/p' ChangeLog | tail -n +2 | head -n -1) + local changelog + changelog=$(sed -rne '/^###.*'"${target_release//./\.}"'\b/,/^### '"${prev_release//./\.}"'\b/p' ChangeLog | tail -n +2 | head -n -1) # Remove trailing whitespace on all lines of the current changelog: changelog=$(sed -re 's/\s+$//' <<<"$changelog") @@ -100,7 +107,7 @@ group_entries() { local index=0 for category in "${category_order[@]}"; do changelog=$(sed -re 's/^(- '"${category}"')/'"${index}"' \1/' <<<"${changelog}") - index=$(($index+1)) + index=$((index+1)) done # Reduce blocks ("entries") to a single line by replacing \n with \v. @@ -131,15 +138,21 @@ check_or_add_pr() { # (\> ensures that we only match full, standalone IDs) return fi - local json=$(gh pr view "${id/#/}" --json title,author,state) - local state=$(jq -r .state <<<"${json}") - local title=$(jq -r .title <<<"${json}" | sanitize_title) - local author=$(jq -r .author.login <<<"${json}") + local json + json=$(gh pr view "${id/#/}" --json title,author,state) + local state + state=$(jq -r .state <<<"${json}") + local title + title=$(jq -r .title <<<"${json}" | sanitize_title) + local author + author=$(jq -r .author.login <<<"${json}") if [[ "${state}" != "MERGED" ]]; then echo "-> Ignoring PR #${id} as state ${state} != MERGED" return fi - local title_suggestion_in_pr=$(gh pr view "$id" --json body,comments,reviews --jq '(.body), (.comments[] .body), (.reviews[] .body)' | grep -oP '\bCHANGELOG:\s*\K([^\\]{5,})' | tail -n1 | sanitize_title) + local title_suggestion_in_pr + title_suggestion_in_pr=$(gh pr view "$id" --json body,comments,reviews --jq '(.body), (.comments[] .body), (.reviews[] .body)' | + grep -oP '\bCHANGELOG:\s*\K([^\\]{5,})' | tail -n1 | sanitize_title) if [[ "${title_suggestion_in_pr}" ]]; then title="${title_suggestion_in_pr}" if [[ "${title_suggestion_in_pr}" == "SKIP" ]]; then @@ -153,7 +166,8 @@ check_or_add_pr() { fi echo ", adding new entry" local new_entry="" - local lang=$(grep -oP 'Updated? \K(\S+)(?= app translations? for )' <<<"$title" || true) + local lang + lang=$(grep -oP 'Updated? \K(\S+)(?= app translations? for )' <<<"$title" || true) if [[ "${lang}" ]]; then # Note: This creates a top-level entry for each language. # group-entries can merge those to a single one. @@ -165,8 +179,10 @@ check_or_add_pr() { echo "- ${title} (#${id})." echo " (contributed by @${author})" ) - local changelog_before=$(head -n "${changelog_begin_position}" ChangeLog) - local changelog_after=$(tail -n "+$((${changelog_begin_position}+1))" ChangeLog) + local changelog_before + changelog_before=$(head -n "${changelog_begin_position}" ChangeLog) + local changelog_after + changelog_after=$(tail -n "+$((changelog_begin_position+1))" ChangeLog) (echo "$changelog_before"; echo; echo "$new_entry"; echo "$changelog_after") > ChangeLog } @@ -174,17 +190,22 @@ add_translation_pr() { local lang="${1}" local author="${2}" local id="${3}" - local changelog_begin_position=$(grep -nP '^### .*\d+\.\d+\.\d+\b' ChangeLog | head -n1 | cut -d: -f1) - local changelog_prev_release_position=$(grep -nP '^### .*\d+\.\d+\.\d+\b' ChangeLog | head -n2 | tail -n1 | cut -d: -f1) + local changelog_begin_position + changelog_begin_position=$(grep -nP '^### .*\d+\.\d+\.\d+\b' ChangeLog | head -n1 | cut -d: -f1) + local changelog_prev_release_position + changelog_prev_release_position=$(grep -nP '^### .*\d+\.\d+\.\d+\b' ChangeLog | head -n2 | tail -n1 | cut -d: -f1) # Save everything before the actual release changelog content: - local changelog_header=$(head -n "${changelog_begin_position}" ChangeLog) + local changelog_header + changelog_header=$(head -n "${changelog_begin_position}" ChangeLog) # Save everything after the actual release changelog content: - local changelog_prev_releases=$(tail -n "+${changelog_prev_release_position}" ChangeLog) + local changelog_prev_releases + changelog_prev_releases=$(tail -n "+${changelog_prev_release_position}" ChangeLog) # Save the current release's changelog content: - local changelog=$(sed -rne '/^###.*'"${target_release//./\.}"'\b/,/^### '"${prev_release//./\.}"'\b/p' ChangeLog | tail -n +2 | head -n -1) + local changelog + changelog=$(sed -rne '/^###.*'"${target_release//./\.}"'\b/,/^### '"${prev_release//./\.}"'\b/p' ChangeLog | tail -n +2 | head -n -1) local changelog_orig="${changelog}" # Is there an existing entry for this language already? @@ -227,12 +248,12 @@ add_translation_pr() { changelog_after_translations="${changelog_after_translations}${line}"$'\n' fi done <<< "${changelog}" - changelog="$( + changelog=$( # echo -n strips whitespace. we need that here. echo -n "${changelog_before_translations}" echo -n "$(grep -vP '^$' <<< "${changelog_translations}" | sort)" echo -n "${changelog_after_translations}" - )" + ) fi fi # Rebuild the changelog and write back to file: diff --git a/tools/check-wininstaller-translations.sh b/tools/check-wininstaller-translations.sh index c72782ed8e..ff7ca8b545 100755 --- a/tools/check-wininstaller-translations.sh +++ b/tools/check-wininstaller-translations.sh @@ -6,12 +6,16 @@ BASE_LANG=en INSTALLERLNG=installerlng.nsi BASE_LANGSTRINGS=$(grep LangString "${BASE_DIR}/${BASE_LANG}.nsi" | cut -d' ' -f2) EXIT=0 -LANGUAGE_FILES="$(ls -1 src/res/translation/wininstaller/{??.nsi,??_??.nsi} | grep -vF "${BASE_LANG}.nsi")" -for LANGUAGE_FILE in ${LANGUAGE_FILES}; do +for LANGUAGE_FILE in src/res/translation/wininstaller/{??.nsi,??_??.nsi}; do + if [[ ${LANGUAGE_FILE} =~ /${BASE_LANG}.nsi$ ]]; then + continue + fi echo echo "* ${LANGUAGE_FILE}" echo -n " - Checking language file is included in ${INSTALLERLNG}... " - if grep -q '^!include "\${ROOT_PATH}\\'$(sed -re 's|/|\\\\|g' <<<"${LANGUAGE_FILE}")'"' "${BASE_DIR}/${INSTALLERLNG}"; then + # shellcheck disable=SC2016 # shellcheck is confused here as NSI files use variables which look like shell variables + # shellcheck disable=SC1003 # shellcheck misinterprets the verbatim backslash as an attempt to escape the single quote. it's not. + if grep -q '^!include "\${ROOT_PATH}\\'"$(sed -re 's|/|\\\\|g' <<<"${LANGUAGE_FILE}")"'"' "${BASE_DIR}/${INSTALLERLNG}"; then echo "ok" else echo "ERROR" @@ -35,7 +39,7 @@ for LANGUAGE_FILE in ${LANGUAGE_FILES}; do fi echo -n " - Checking for wrong macros... " - LANG_MACROS="$(grep -oP '\$\{LANG_[^}]+\}' "${LANGUAGE_FILE}")" + LANG_MACROS=$(grep -oP '\$\{LANG_[^}]+\}' "${LANGUAGE_FILE}") if grep ENGLISH <<<"$LANG_MACROS"; then echo "ERROR, found LANG_ENGLISH" EXIT=1 @@ -52,7 +56,7 @@ for LANGUAGE_FILE in ${LANGUAGE_FILES}; do fi echo -n " - Checking if LANG_ macro is in ${INSTALLERLNG}..." - LANG_NAME="$(sort -u <<<"${LANG_MACROS}" | sed -rne 's/\$\{LANG_(.*)\}/\1/p')" + LANG_NAME=$(sort -u <<<"${LANG_MACROS}" | sed -rne 's/\$\{LANG_(.*)\}/\1/p') if grep -qi '^!insertmacro MUI_LANGUAGE "'"${LANG_NAME}"'"' "$BASE_DIR/${INSTALLERLNG}"; then echo "ok" else diff --git a/tools/create-translation-issues.sh b/tools/create-translation-issues.sh index 0fd7469b7b..5a4b0d904d 100755 --- a/tools/create-translation-issues.sh +++ b/tools/create-translation-issues.sh @@ -64,6 +64,7 @@ declare -A TRANSLATORS_BY_LANG=( [web_pt]="Snayler,melcon,ewarning" ) +# shellcheck disable=SC2016 # shellcheck can't know that this will be used with envsubst, so verbatim variables are correct here. BODY_TEMPLATE_APP='Hi ${SPLIT_TRANSLATORS}, We are getting ready for the ${RELEASE} release. No further changes to translatable strings are currently planned for this release. @@ -89,6 +90,7 @@ Further documentation can be found in [TRANSLATING.md](https://github.com/jamulu Thanks for contributing to Jamulus!' +# shellcheck disable=SC2016 # shellcheck can't know that this will be used with envsubst, so verbatim variables are correct here. BODY_TEMPLATE_WEB='Hi ${SPLIT_TRANSLATORS}, We are getting ready for the ${RELEASE} release and have created the [${TRANSLATE_BRANCH}](https://github.com/jamulussoftware/jamuluswebsite/tree/${TRANSLATE_BRANCH}) branch ([full diff](https://github.com/jamulussoftware/jamuluswebsite/compare/release..${TRANSLATE_BRANCH})). @@ -149,7 +151,7 @@ get_languages() { echo "Error: Please ensure that you are at the root of a jamuluswebsite checkout" >/dev/stderr exit 1 fi - for LANG in $(cd _translator-files/po/ && ls -d *); do + for LANG in $(cd _translator-files/po/ && ls -d -- *); do [[ -d _translator-files/po/$LANG ]] || continue [[ $LANG == en ]] && continue # does not have to be translated echo "$LANG" @@ -184,7 +186,8 @@ create_translation_issue_for_lang() { multiple_translators_text="" [[ $translators == *,* ]] && multiple_translators_text=$'\n\n''This Issue is assigned to multiple people. Please coordinate who will translate what part.' [[ $TYPE == app ]] && body_template="$BODY_TEMPLATE_APP" || body_template="$BODY_TEMPLATE_WEB" - local body=$( + local body + body=$( # Note: Those line continuation backslashes are required for variables # to be passed through: DEADLINE="$DEADLINE" \ @@ -199,7 +202,8 @@ create_translation_issue_for_lang() { ) # Check for an existing issue - local existing_issue=$(gh issue list --milestone "$MILESTONE" --state all --search "$title" --json number --jq '.[0].number' || true) + local existing_issue + existing_issue=$(gh issue list --milestone "$MILESTONE" --state all --search "$title" --json number --jq '.[0].number' || true) # If there's no existing issue, create one if [[ -z $existing_issue ]]; then @@ -214,7 +218,8 @@ create_translation_issue_for_lang() { # update the issue if the bodies differ. # This is used on initial creation to fill in the issue number and it # can be used to update the body text afterwards. - local online_body=$(gh issue view "$existing_issue" --json body --jq .body) + local online_body + online_body=$(gh issue view "$existing_issue" --json body --jq .body) body=${body///${existing_issue}} if [[ "$online_body" != "$body" ]]; then echo "Updating Issue to translate $lang for $RELEASE" diff --git a/tools/update-copyright-notices.sh b/tools/update-copyright-notices.sh index 249a82c204..35045ce7ed 100755 --- a/tools/update-copyright-notices.sh +++ b/tools/update-copyright-notices.sh @@ -6,8 +6,9 @@ echo "Updating global copyright strings..." sed -re 's/(Copyright.*2[0-9]{3}-)[0-9]{4}/\1'"${YEAR}"'/g' -i src/res/translation/*.ts src/util.cpp src/aboutdlgbase.ui echo "Updating copyright comment headers..." -for file in $(find android ios linux mac src windows -regex '.*\.\(cpp\|h\|mm\)' -not -regex '\./\(\.git\|libs/\|moc_\|ui_\).*'); do - sed -re 's/(\*.*Copyright.*[^-][0-9]{4})(\s*-\s*\b[0-9]{4})?\s*$/\1-'"${YEAR}"'/' -i "${file}" +find android ios linux mac src windows -regex '.*\.\(cpp\|h\|mm\)' -not -regex '\./\(\.git\|libs/\|moc_\|ui_\).*' | while read -r file; do + sed -re 's/(\*.*Copyright.*[^-][0-9]{4})(\s*-\s*\b[0-9]{4})?\s*$/\1-'"${YEAR}"'/' -i "${file}" done + sed -re 's/^( [0-9]{4}-)[0-9]{4}( The Jamulus)/\1'"${YEAR}"'\2/' -i distributions/debian/copyright