program-rename (LTS) #1

Merged
TheOnePath merged 6 commits from program-rename into main 2022-02-20 14:37:21 +00:00
Showing only changes of commit 4f58db256e - Show all commits

View File

@ -302,8 +302,8 @@ log "DEBUG" "There is a more recent release of Microsoft Edge ($edge_channel) av
[[ ! $quiet -eq 0 ]] && >&2 echo "Identified a new release of Microsoft Edge ($edge_channel) [Current: v$current_version. New: v$release_version]. Starting the download and installation process..."
## check if msedge process is already running
is_running=$(ps -aux | grep -oc "msedge-$edge_channel")
if [[ $is_running -gt 1 ]] ; then
is_running="$(pidof msedge | xargs ps -ocmd -p | grep -m1 "msedge-$edge_channel")"

This check works, However I can see a false positive scenario occuring.
If a long running command contains msedge-$edge_channel then it will be included in the ouput of the check.

For example

watch pidof msedge-dev &
ps -aux | grep -oc "msedge-dev" # assume dev channel

Would give an output of 1 Even though msedge is not actually running.

I would suggest the use of a longer and slightly more verbose check.

pidof msedge | xargs ps -ocmd -p | grep -m1 "msedge-$edge_channel"

In this check we:

  • Use pidof msedge to return the PID(s) of any/all running msedge process(es)
  • Pipe the PID(s) to xargs, which uses ps to get the cmdline
    • We need xargs to position the PID(s)
    • The ps flag -ocmddefines the output as just the cmdline
    • The ps flag -p tells ps to just look for the given PID(s)
  • Grep for a maximum of one match for the given edge channel

It's also uneccesary to use the count flag in grep since no matches returns an empty result which is easy to test for.
EDIT: fix minortypo

This check works, However I can see a false positive scenario occuring. If a long running command contains `msedge-$edge_channel` then it will be included in the ouput of the check. For example ```bash watch pidof msedge-dev & ps -aux | grep -oc "msedge-dev" # assume dev channel ``` Would give an output of 1 Even though msedge is not actually running. I would suggest the use of a longer and slightly more verbose check. ```bash pidof msedge | xargs ps -ocmd -p | grep -m1 "msedge-$edge_channel" ``` In this check we: - Use `pidof msedge` to return the PID(s) of any/all running msedge process(es) - Pipe the PID(s) to xargs, which uses ps to get the cmdline - We need xargs to position the PID(s) - The ps flag `-ocmd`defines the output as just the cmdline - The ps flag `-p` tells ps to just look for the given PID(s) - Grep for a maximum of one match for the given edge channel It's also uneccesary to use the count flag in grep since no matches returns an empty result which is easy to test for. EDIT: fix minortypo
if [[ ! -z "$is_running" ]] ; then
log "DEBUG" "Identified running processes for msedge. Determining how script should handle process..." "$log_file"
if [[ ! $yes_flag -eq 0 ]] ; then
echo -n "Microsoft Edge ($edge_channel) is already open. To continue update, the browser must be closed. Are you sure you wish to proceed? [(Y)es/No]: " && read -n 1 choice ; echo