Restcomm-Connect icon indicating copy to clipboard operation
Restcomm-Connect copied to clipboard

gsed_macos.sh only works the first time

Open atsakiridis opened this issue 7 years ago • 3 comments

Reason is that the script is modifying its own contents, as can be seen below

$ cat gsed_macos.sh 
#!/bin/bash
## Description: Change 'sed' to 'gsed' for MacOS users in order for the autoconfig scripts to work properly
## Prerequisites: Install gnu-sed using homebrew (brew install gnu-sed)
## Author: George Vagenas
gsed -i 's/sed/gsed/g' ./*.sh
gsed -i 's/sed/gsed/g' ./autoconfig.d/*.sh
$ ./gsed_macos.sh 
$ cat gsed_macos.sh 
#!/bin/bash
## Description: Change 'gsed' to 'ggsed' for MacOS users in order for the autoconfig scripts to work properly
## Prerequisites: Install gnu-gsed using homebrew (brew install gnu-gsed)
## Author: George Vagenas
ggsed -i 's/gsed/ggsed/g' ./*.sh
ggsed -i 's/gsed/ggsed/g' ./autoconfig.d/*.sh

atsakiridis avatar Jun 12 '17 12:06 atsakiridis

I thought I'd take a quick look at this, and it seems to me like there's a simpler solution than substituting the sed command in all the shell scripts. In fact, according to the brew info gnu-sed output below, it also seems to be the recommended approach.

Instinctively this seems something I'd just replace in the shell environment, either aliasing the command, or by prepending something in the path, etc.

Indeed, overriding the PATH seems to be the recommended approach:

If you need to use these commands with their normal names, you can add a "gnubin" directory to your PATH from your bashrc like: PATH="/usr/local/opt/gnu-sed/libexec/gnubin:$PATH"

Do note that there's also a more radical approach:

installing gnu-sed with the --with-default-names option, meaning the regular sed command will be replaced.

Here's the output from brew info gnu-sed: (do note the "Options" and "Caveats" sections)

$ brew info gnu-sed          
gnu-sed: stable 4.4 (bottled)
GNU implementation of the famous stream editor
https://www.gnu.org/software/sed/
Conflicts with:
  ssed (because both install share/info/sed.info)
Not installed
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/gnu-sed.rb
==> Options
--with-default-names
	Do not prepend 'g' to the binary
==> Caveats
The command has been installed with the prefix "g".
If you do not want the prefix, install using the "with-default-names" option.

If you need to use these commands with their normal names, you
can add a "gnubin" directory to your PATH from your bashrc like:
  PATH="/usr/local/opt/gnu-sed/libexec/gnubin:$PATH"

Additionally, you can access their man pages with normal names if you add
the "gnuman" directory to your MANPATH from your bashrc as well:
  MANPATH="/usr/local/opt/gnu-sed/libexec/gnuman:$MANPATH"

If we do go with this approach, we can just add the export PATH="/usr/local/opt/gnu-sed/libexec/gnubin:$PATH" in this file and include instructions to the user to just source gsed_macos.sh

Please let me know if you want me to open a PR with this approach.

gsaslis avatar Jun 23 '17 14:06 gsaslis

@agafox can you please have a look at this too since you have been testing OSX lately.

deruelle avatar Jun 30 '17 14:06 deruelle

Workaround for this here: https://github.com/RestComm/Restcomm-Connect/pull/2977/commits/7a4cbb9c3c8bdc50dc84e09905fb0e7dee05c708. At some point we can go with better solution as @gsaslis suggested

atsakiridis avatar Jun 29 '18 08:06 atsakiridis