Skip to content

Commit

Permalink
Fix unconditionally using procps-specific ps(1) option '-C'; remove u…
Browse files Browse the repository at this point in the history
…nnecessary uses of $?
  • Loading branch information
papadave66 committed Sep 22, 2023
1 parent 5aeb20c commit 8fe326c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 25 deletions.
25 changes: 17 additions & 8 deletions release/install-tr-control-cn.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
26 changes: 17 additions & 9 deletions release/install-tr-control-gitee.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
25 changes: 17 additions & 8 deletions release/install-tr-control.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8fe326c

Please sign in to comment.