From 8fe326c83c451657739585e5e0e19b3c4b074703 Mon Sep 17 00:00:00 2001 From: papadave66 Date: Fri, 22 Sep 2023 23:20:21 +0800 Subject: [PATCH] Fix unconditionally using procps-specific ps(1) option '-C'; remove unnecessary uses of $? --- release/install-tr-control-cn.sh | 25 +++++++++++++++++-------- release/install-tr-control-gitee.sh | 26 +++++++++++++++++--------- release/install-tr-control.sh | 25 +++++++++++++++++-------- 3 files changed, 51 insertions(+), 25 deletions(-) diff --git a/release/install-tr-control-cn.sh b/release/install-tr-control-cn.sh index dff55764..834aff64 100644 --- a/release/install-tr-control-cn.sh +++ b/release/install-tr-control-cn.sh @@ -249,12 +249,12 @@ download() { fi showLog "$MSG_DOWNLOADING" echo "" - wget "$DOWNLOAD_URL" --no-check-certificate - # 判断是否下载成功 - if [ $? -eq 0 ]; then + if wget "$DOWNLOAD_URL" --no-check-certificate; then + # 下载成功 showLog "$MSG_DOWNLOAD_COMPLETE" return 0 else + # 下载失败 showLog "$MSG_DOWNLOAD_FAILED" end exit 1 @@ -438,11 +438,20 @@ getLatestReleases() { VERSION=`wget -O - https://api.github.com/repos/ronggang/transmission-web-control/releases/latest | grep tag_name | head -n 1 | cut -d '"' -f 4` } +if ps --version 2> /dev/null | grep -Fq procps; then + checkProcess() { + ps -C "$1" + } +else + checkProcess() { + ps -A -o comm= | grep --fixed-strings --line-regexp --quiet "$1" + } +fi + # 检测 Transmission 进程是否存在 checkTransmissionDaemon() { showLog "$MSG_CHECK_TR_DAEMON" - ps -C transmission-daemon - if [ $? -ne 0 ]; then + if checkProcess transmission-daemon; then showLog "$MSG_CHECK_TR_DAEMON_FAILED" echo -n "$MSG_TRY_START_TR" read input @@ -488,11 +497,11 @@ downloadInstallScript() { rm "$SCRIPT_NAME" fi showLog "$MSG_DOWNLOADING_INSTALL_SCRIPT" - wget "https://github.com/ronggang/transmission-web-control/raw/master/release/$SCRIPT_NAME" --no-check-certificate - # 判断是否下载成功 - if [ $? -eq 0 ]; then + if wget "https://github.com/ronggang/transmission-web-control/raw/master/release/$SCRIPT_NAME" --no-check-certificate; then + # 下载成功 showLog "$MSG_INSTALL_SCRIPT_DOWNLOAD_COMPLETE" else + # 下载失败 showLog "$MSG_INSTALL_SCRIPT_DOWNLOAD_FAILED" sleep 2 showMainMenu diff --git a/release/install-tr-control-gitee.sh b/release/install-tr-control-gitee.sh index c70cce00..3436077c 100644 --- a/release/install-tr-control-gitee.sh +++ b/release/install-tr-control-gitee.sh @@ -251,13 +251,12 @@ download() { fi showLog "$MSG_DOWNLOADING" echo "" - wget -O "$PACK_NAME" "$DOWNLOAD_URL" --no-check-certificate - - # 判断是否下载成功 - if [ $? -eq 0 ]; then + if wget -O "$PACK_NAME" "$DOWNLOAD_URL" --no-check-certificate; then + # 下载成功 showLog "$MSG_DOWNLOAD_COMPLETE" return 0 else + # 下载失败 showLog "$MSG_DOWNLOAD_FAILED" end exit 1 @@ -441,11 +440,20 @@ getLatestReleases() { VERSION=`wget -O - https://gitee.com/api/v5/repos/culturist/transmission-web-control/releases/latest --no-check-certificate | sed -r "s/.*tag_name(.*)target_commitish.*/\1/" | cut -d '"' -f 3` } +if ps --version 2> /dev/null | grep -Fq procps; then + checkProcess() { + ps -C "$1" + } +else + checkProcess() { + ps -A -o comm= | grep --fixed-strings --line-regexp --quiet "$1" + } +fi + # 检测 Transmission 进程是否存在 checkTransmissionDaemon() { showLog "$MSG_CHECK_TR_DAEMON" - ps -C transmission-daemon - if [ $? -ne 0 ]; then + if checkProcess transmission-daemon; then showLog "$MSG_CHECK_TR_DAEMON_FAILED" echo -n "$MSG_TRY_START_TR" read input @@ -491,11 +499,11 @@ downloadInstallScript() { rm "$SCRIPT_NAME" fi showLog "$MSG_DOWNLOADING_INSTALL_SCRIPT" - wget "https://gitee.com/culturist/transmission-web-control/raw/master/release/$SCRIPT_NAME" --no-check-certificate - # 判断是否下载成功 - if [ $? -eq 0 ]; then + if wget "https://gitee.com/culturist/transmission-web-control/raw/master/release/$SCRIPT_NAME" --no-check-certificate; then + # 下载成功 showLog "$MSG_INSTALL_SCRIPT_DOWNLOAD_COMPLETE" else + # 下载失败 showLog "$MSG_INSTALL_SCRIPT_DOWNLOAD_FAILED" sleep 2 showMainMenu diff --git a/release/install-tr-control.sh b/release/install-tr-control.sh index 601ab5a5..cd1d5d6f 100644 --- a/release/install-tr-control.sh +++ b/release/install-tr-control.sh @@ -252,12 +252,12 @@ download() { showLog "$MSG_DOWNLOADING" echo "" # 下载的时候强制命名文件,以免被重定向后文件名发生改变 - wget "$DOWNLOAD_URL" -O "$PACK_NAME" --no-check-certificate - # 判断是否下载成功 - if [ $? -eq 0 ]; then + if wget "$DOWNLOAD_URL" -O "$PACK_NAME" --no-check-certificate; then + # 下载成功 showLog "$MSG_DOWNLOAD_COMPLETE" return 0 else + # 下载失败 showLog "$MSG_DOWNLOAD_FAILED" end exit 1 @@ -445,11 +445,20 @@ getLatestReleases() { VERSION=`curl -s https://api.github.com/repos/ronggang/transmission-web-control/releases/latest | grep tag_name | head -n 1 | cut -d '"' -f 4` } +if ps --version 2> /dev/null | grep -Fq procps; then + checkProcess() { + ps -C "$1" + } +else + checkProcess() { + ps -A -o comm= | grep --fixed-strings --line-regexp --quiet "$1" + } +fi + # 检测 Transmission 进程是否存在 checkTransmissionDaemon() { showLog "$MSG_CHECK_TR_DAEMON" - ps -C transmission-daemon - if [ $? -ne 0 ]; then + if checkProcess transmission-daemon; then showLog "$MSG_CHECK_TR_DAEMON_FAILED" echo -n "$MSG_TRY_START_TR" read input @@ -495,11 +504,11 @@ downloadInstallScript() { rm "$SCRIPT_NAME" fi showLog "$MSG_DOWNLOADING_INSTALL_SCRIPT" - wget "https://github.com/ronggang/transmission-web-control/raw/master/release/$SCRIPT_NAME" --no-check-certificate - # 判断是否下载成功 - if [ $? -eq 0 ]; then + if wget "https://github.com/ronggang/transmission-web-control/raw/master/release/$SCRIPT_NAME" --no-check-certificate; then + # 下载成功 showLog "$MSG_INSTALL_SCRIPT_DOWNLOAD_COMPLETE" else + # 下载失败 showLog "$MSG_INSTALL_SCRIPT_DOWNLOAD_FAILED" sleep 2 showMainMenu