RestComm / Restcomm-Connect

The Open Source Cloud Communications Platform
http://www.restcomm.com/
GNU Affero General Public License v3.0
242 stars 215 forks source link

gsed_macos.sh only works the first time #2224

Open atsakiridis opened 7 years ago

atsakiridis commented 7 years ago

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
gsaslis commented 7 years ago

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.

deruelle commented 7 years ago

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

atsakiridis commented 6 years ago

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