[PATCH 1/4] gnu-linux: ignore shellcheck warning
Export this patch
Shellcheck is a static analyzer for shell script. It helps you avoid
making silly mistakes that can be hard to find. Check it out here:
https://u27125094.ct.sendgrid.net/ls/click?upn=Y73ls-2FpqpPk8ipT8ZhG2-2FiJYe-2FjtN70wBMZydtGEpCHAVZsNVxE9JkeOE8-2BavGqoA-2FEd-2FVmtXYKZv-2FPbcdI5Fg-3D-3D-oKI_XjzyZYWgSQeZavOB6BObZ9cPKBJyq2WB2rtE-2B8bIpruHZ-2F9H6Qv-2ByTU5Jovqej-2BlyrTyjX4UU33GvUwNu8g9DQ26mgX64AT9cigmJnGlsgMTB5ORZ1YFVVuEck5KcwzDcrA5aYM12ZxkCdCc-2FvmrjFpmb2AC68mZZqD-2BoJXEOj4v31Y7oDpQyJiTtwy3rnjk2oDdLiwx4WFW5vH21ja05iVfuIyhH58fcyKEG90vHf0-3D
This shellcheck warning can be ignored because assigning a variable
should always be safe to do, the only reason I could think it wouldn't
succeed is if the variable was read-only, and I've only seen that used
with docker containers.
---
gnu-linux/install.sh.in | 1 +
1 file changed, 1 insertion(+)
diff --git a/gnu-linux/install.sh.in b/gnu-linux/install.sh.in
index 7889365..d627f12 100755
--- a/gnu-linux/install.sh.in
+++ b/gnu-linux/install.sh.in
@@ -31,6 +31,7 @@ trial="@DASH_TRIAL@"
zenity_width=360
have_zenity=0
+ # shellcheck disable=SC2015
command -v zenity > /dev/null && have_zenity=1 || true
if [ -z "$XDG_DATA_HOME" ]; then
--
2.37.2
[PATCH 2/4] gnu-linux: error if unset variables are used
Export this patch
---
gnu-linux/install.sh.in | 6 +++ ---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/gnu-linux/install.sh.in b/gnu-linux/install.sh.in
index d627f12..9178504 100755
--- a/gnu-linux/install.sh.in
+++ b/gnu-linux/install.sh.in
@@ -17,11 +17,11 @@
# You should have received a copy of the GNU Affero General Public License
# along with Zrythm. If not, see <https://u27125094.ct.sendgrid.net/ls/click?upn=Y73ls-2FpqpPk8ipT8ZhG2-2Fstf4u35TFLhhGeTeMp6tKRbzPCTqPDIOkLN4iU-2BYLyKU1vY_XjzyZYWgSQeZavOB6BObZ9cPKBJyq2WB2rtE-2B8bIpruHZ-2F9H6Qv-2ByTU5Jovqej-2Blvj2x9-2Bv8L3bG7yhTWKjW5F4if4IU2Hhxju5fJHWLlP9JdkmQEf-2BHp3NNFFqogFtKc3HdYb2GIma0-2B-2Fio3utb6EnBvdjVG-2BEWGnO8X3RWH-2FkGQLyDAS-2BQFT95kpihgJCIzbQOmS-2FT0G8Q2XzbFold-2FYAcehMbYHUps4rTCD9mRWk-3D>.
- set -ex
+ set -eu
uninstall=0
uninstall_prefix_txt=""
- if [ "$1" = "-u" ]; then
+ if [ "${1:-}" = "-u" ]; then
uninstall=1
uninstall_prefix_txt="un"
fi
@@ -34,7 +34,7 @@ have_zenity=0
# shellcheck disable=SC2015
command -v zenity > /dev/null && have_zenity=1 || true
- if [ -z "$XDG_DATA_HOME" ]; then
+ if [ -z "${XDG_DATA_HOME:-}" ]; then
Same here. Why is this needed?
XDG_DATA_HOME="$HOME/.local/share"
fi
trash_dir="$XDG_DATA_HOME/Trash"
--
2.37.2
2022-10-14 (金) の 04:56 +0000 に PowerUser64 さんは書きました:
What exactly does the dash thing do?
[PATCH 3/4] gnu-linux: add vim modeline
Export this patch
This is so editors know what the file type is.
---
gnu-linux/install.sh.in | 1 +
1 file changed, 1 insertion(+)
diff --git a/gnu-linux/install.sh.in b/gnu-linux/install.sh.in
index 9178504..fe4189a 100755
--- a/gnu-linux/install.sh.in
+++ b/gnu-linux/install.sh.in
@@ -157,3 +157,4 @@ if [ $proceed -ne 0 ]; then
print_install_success
fi
+ # vim: ft=sh ts=2 sw=2
--
2.37.2
2022-10-14 (金) の 04:57 +0000 に PowerUser64 さんは書きました:
Applied, thanks (besides the logging).
[PATCH 4/4] gnu-linux: add logging
Export this patch
`sudo` commands are logged with the sudo() function, and if the
`line_num` variable is set before appending to the log, the line
number will be included in the log.
---
gnu-linux/install.sh.in | 67 +++++++++++++++++++++++++++++ ------------
1 file changed, 47 insertions(+), 20 deletions(-)
diff --git a/gnu-linux/install.sh.in b/gnu-linux/install.sh.in
index fe4189a..2bc681e 100755
--- a/gnu-linux/install.sh.in
+++ b/gnu-linux/install.sh.in
@@ -41,8 +41,28 @@ trash_dir="$XDG_DATA_HOME/Trash"
trash_dir="$trash_dir/zrythm-installer-deleted-files-$(date +"%Y_%m_%d_%H_%M")"
mkdir -p "$trash_dir"
+ log_file=/tmp/zrythm_installer_log-"$(date +'%y-%m-%d_%H:%M:%S')"
+ touch "$log_file"
+
# ---- Helper funcs ----
+ log_msg() {
+ { # any stdout in here goes to the log file
+ # only try to output the line number if line_num is set to a number
+ if [ -n "${line_num:-}" ]; then
+ printf '%s: ' "${line_num:-}"
+ fi
+ echo "$@"
+ line_num= # Set line_num to a blank string so we don't print an old line number if it isn't given next time
+ } >> "$log_file"
+ }
+
+ # log sudo commands
+ sudo() {
+ log_msg 'sudo' "$@"
+ command sudo "$@"
+ }
+
show_error()
{
if [ $have_zenity -ne 0 ]; then
@@ -50,6 +70,7 @@ show_error()
else
echo "$1"
fi
+ log_msg "show_error(): $1"
}
show_info()
@@ -59,25 +80,28 @@ show_info()
else
echo "$1"
fi
+ log_msg "show_info(): $1"
}
ask_for_root_pw()
{
ask_for_root_pw_text="Please enter your root password in the terminal to continue (if asked)"
- show_info "$ask_for_root_pw_text"
+ line_num="$LINENO" && show_info "$ask_for_root_pw_text"
}
print_install_success()
{
if [ $uninstall -eq 0 ]; then
- show_info "Install successful!"
+ line_num="$LINENO" && show_info "Install successful!"
else
- show_info "Uninstall successful!"
+ line_num="$LINENO" && show_info "Uninstall successful!"
fi
}
# ---- Install ----
+ log_msg "Log of $(realpath "$0")"
+
proceed=0
proceed_txt="Proceed with the ${uninstall_prefix_txt}installation of Zrythm$trial v$zrythm_ver?"
if [ $have_zenity -ne 0 ]; then
@@ -85,76 +109,79 @@ if [ $have_zenity -ne 0 ]; then
proceed=1
fi
else
- echo "$proceed_txt (type Y or y): " | tr -d '\n' &&
+ echo "$proceed_txt [y/n]: " | tr -d '\n' &&
read -r
if [ "$REPLY" = "y" ] || [ "$REPLY" = "Y" ]; then
proceed=1
fi
fi
+ line_num="$LINENO" && log_msg "proceed=$proceed"
sudo_copy_file()
{
src_path="$1"
dest_path="$2"
- sudo mkdir -p "$(dirname "$dest_path")"
- sudo cp "$src_path" "$dest_path"
+ line_num="$LINENO" && sudo mkdir -p "$(dirname "$dest_path")"
+ line_num="$LINENO" && sudo cp "$src_path" "$dest_path"
+ log_msg "$LINENO: proceed=$proceed"
}
# install packages
+ # shellcheck disable=SC2015 # setting a variable should always succeed
if [ $proceed -ne 0 ]; then
pkgname="zrythm$trial-$zrythm_ver"
prefix="opt/$pkgname"
installed_prefix="/opt/$pkgname"
- sudo mv "$installed_prefix" "$trash_dir/" || true
+ line_num="$LINENO" && sudo mv "$installed_prefix" "$trash_dir/" || true
if [ $uninstall -eq 0 ]; then
- sudo cp -r "$prefix" "$installed_prefix"
+ line_num="$LINENO" && sudo cp -r "$prefix" "$installed_prefix"
fi
# application
application_path_in_zip="share/applications/org.zrythm.Zrythm.desktop"
application_path_installed="/usr/local/share/applications/org.zrythm.Zrythm-installer.desktop"
- sudo mv "$application_path_installed" "$trash_dir/" || true
+ line_num="$LINENO" && sudo mv "$application_path_installed" "$trash_dir/" || true
if [ $uninstall -eq 0 ]; then
- sudo_copy_file "$prefix/$application_path_in_zip" "$application_path_installed"
+ line_num="$LINENO" && sudo_copy_file "$prefix/$application_path_in_zip" "$application_path_installed"
fi
# app icon
appicon_path_in_zip="share/icons/hicolor/scalable/apps/zrythm.svg"
appicon_path_installed="/usr/local/share/icons/hicolor/scalable/apps/zrythm.svg"
- sudo mv "$appicon_path_installed" "$trash_dir/" || true
+ line_num="$LINENO" && sudo mv "$appicon_path_installed" "$trash_dir/" || true
if [ $uninstall -eq 0 ]; then
- sudo_copy_file "$prefix/$appicon_path_in_zip" "$appicon_path_installed"
+ line_num="$LINENO" && sudo_copy_file "$prefix/$appicon_path_in_zip" "$appicon_path_installed"
fi
# manpage
manpage_path_in_zip="share/man/man1/zrythm.1"
manpage_path_installed="/usr/local/share/man/man1/zrythm.1"
- sudo mv "$manpage_path_installed" "$trash_dir/" || true
+ line_num="$LINENO" && sudo mv "$manpage_path_installed" "$trash_dir/" || true
if [ $uninstall -eq 0 ]; then
- sudo_copy_file "$prefix/$manpage_path_in_zip" "$manpage_path_installed"
+ line_num="$LINENO" && sudo_copy_file "$prefix/$manpage_path_in_zip" "$manpage_path_installed"
fi
# metainfo
metainfo_path_in_zip="share/metainfo/org.zrythm.Zrythm.appdata.xml"
metainfo_path_installed="/usr/local/share/metainfo/org.zrythm.Zrythm-installer.appdata.xml"
- sudo mv "$metainfo_path_installed" "$trash_dir/" || true
+ line_num="$LINENO" && sudo mv "$metainfo_path_installed" "$trash_dir/" || true
if [ $uninstall -eq 0 ]; then
- sudo_copy_file "$prefix/$metainfo_path_in_zip" "$metainfo_path_installed"
+ line_num="$LINENO" && sudo_copy_file "$prefix/$metainfo_path_in_zip" "$metainfo_path_installed"
fi
# mime type
mimetype_path_in_zip="share/mime/packages/org.zrythm.Zrythm-mime.xml"
mimetype_path_installed="/usr/local/share/mime/packages/org.zrythm.Zrythm-mime.xml"
- sudo mv "$mimetype_path_installed" "$trash_dir/" || true
+ line_num="$LINENO" && sudo mv "$mimetype_path_installed" "$trash_dir/" || true
if [ $uninstall -eq 0 ]; then
- sudo_copy_file "$prefix/$mimetype_path_in_zip" "$mimetype_path_installed"
+ line_num="$LINENO" && sudo_copy_file "$prefix/$mimetype_path_in_zip" "$mimetype_path_installed"
fi
# workaround for missing libcrypt.so.1 (version 2) on arch based systems
#if [ $uninstall -eq 0 ]; then
- #sudo ln -s /usr/lib/libcrypt.so.2 "$installed_prefix/lib/x86_64-linux-gnu/libcrypt.so.1" || true
+ #line_num="$LINENO" && sudo ln -s /usr/lib/libcrypt.so.2 "$installed_prefix/lib/x86_64-linux-gnu/libcrypt.so.1" || true
#fi
- print_install_success
+ line_num="$LINENO" && print_install_success
fi
# vim: ft=sh ts=2 sw=2
--
2.37.2