diff --git a/HACKING.md b/HACKING.md index ae14b784..a16d6496 100644 --- a/HACKING.md +++ b/HACKING.md @@ -163,12 +163,15 @@ The rules are mostly sorted in the alphabetical order. ## Shell Scripting - * Avoid bashisms, prefer *POSIX* features only. + * Avoid bashisms and GNUisms, prefer *POSIX* features only. * Prefer `'raw strings'` to `"double quoted strings"` whenever possible. * Put spaces within `$( cmd )`, `$(( expr ))`, and `{ cmd; }`. + * Put utility flags in the ASCII order and **don't** group them together. For + example, `ls -1 -A -q`. + * `snake_case`, not `camelCase`. * Use `set -e -f -u` and also `set -x` in verbose mode. @@ -176,6 +179,24 @@ The rules are mostly sorted in the alphabetical order. * Use the `"$var"` form instead of the `$var` form, unless word splitting is required. + * When concatenating, always use the form with curly braces to prevent + accidental bad variable names. That is, `"${var}_tmp.txt"` and **not** + `"$var_tmp.txt"`. The latter will try to lookup variable `var_tmp`. + + * When concatenating, surround the whole string with quotes. That is, use + this: + + ```sh + dir="${TOP_DIR}/sub" + ``` + + And **not** this: + + ```sh + # Bad! + dir="${TOP_DIR}"/sub + ``` + ## Text, Including Comments * End sentences with appropriate punctuation. diff --git a/scripts/install.sh b/scripts/install.sh index b983322c..6f1fa85f 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -190,6 +190,7 @@ main() { SCRIPT_URL="https://raw.githubusercontent.com/AdguardTeam/AdGuardHome/master/scripts/install.sh" URL="https://static.adguard.com/adguardhome/${CHANNEL}/${PKG_NAME}" OUT_DIR=/opt + AGH_DIR="${OUT_DIR}/AdGuardHome" # Root check if [ "$(id -u)" -eq 0 ]; then @@ -208,22 +209,22 @@ main() { fi fi - log_info "AdGuard Home will be installed to ${OUT_DIR}/AdGuardHome" + log_info "AdGuard Home will be installed to ${AGH_DIR}" - [ -d "${OUT_DIR}/AdGuardHome" ] && error_exit "Directory ${OUT_DIR}/AdGuardHome already exists, abort installation" + [ -d "${AGH_DIR}" ] && [ -n "$(ls -1 -A -q ${AGH_DIR})" ] && error_exit "Directory ${AGH_DIR} is not empty, abort installation" download "${URL}" "${PKG_NAME}" || error_exit "Cannot download the package" unpack "${PKG_NAME}" "${OUT_DIR}" "${PKG_EXT}" || error_exit "Cannot unpack the package" # Install AdGuard Home service and run it - ${OUT_DIR}/AdGuardHome/AdGuardHome -s install || error_exit "Cannot install AdGuardHome as a service" + ${AGH_DIR}/AdGuardHome -s install || error_exit "Cannot install AdGuardHome as a service" rm "${PKG_NAME}" log_info "AdGuard Home is now installed and running." log_info "You can control the service status with the following commands:" - log_info " sudo ${OUT_DIR}/AdGuardHome/AdGuardHome -s start|stop|restart|status|install|uninstall" + log_info " sudo ${AGH_DIR}/AdGuardHome -s start|stop|restart|status|install|uninstall" } main "$@" \ No newline at end of file