Skip to content
Advertisement

Bash script conversion to fish

I’m trying to convert this script to fish: https://github.com/masahide/OmniSSHAgent/blob/main/hack/ubuntu-bash.setup.sh

This is my progress so far:

set OMNISOCATCMD $HOME/omni-socat/omni-socat.exe
export SSH_AUTH_SOCK=$HOME/.ssh/agent.sock

function __get_omnisocat
  echo "Get omni-socat.exe"
  curl https://github.com/masahide/OmniSSHAgent/releases/latest/download/omni-socat.zip 
      -sLo omni-socat.zip
  unzip -o omni-socat.zip -d (dirname $OMNISOCATCMD)
  rm omni-socat.zip
end

function __get_socat
  echo "Install socat"
  sudo apt -y install socat
end


function setup_omnisocat
  [[ -f $OMNISOCATCMD ]]  || __get_omnisocat
  [[ -f /usr/bin/socat ]] || __get_socat
  
  ss -a | grep -q $SSH_AUTH_SOCK
  [[ $status -ne 0 ]]  || return

  rm -f $SSH_AUTH_SOCK
  
  (setsid socat UNIX-LISTEN:$SSH_AUTH_SOCK; fork EXEC:"$OMNISOCATCMD"; nofork &) >/dev/null 2>&1
end

setup_omnisocat

It should be fully converted except that main command substitution in the last function:

(setsid socat UNIX-LISTEN:$SSH_AUTH_SOCK; fork EXEC:"$OMNISOCATCMD"; nofork &) >/dev/null 2>&1

that raises this error:

omni-socat/ubuntu-fish.setup.fish (line 27): Command substitutions not allowed
  (setsid socat UNIX-LISTEN:$SSH_AUTH_SOCK; fork EXEC:"$OMNISOCATCMD"; nofork &) >/dev/null 2>&1
  ^
from sourcing file omni-socat/ubuntu-fish.setup.fish
.: Error while reading file 'omni-socat/ubuntu-fish.setup.fish'

And I don’t understand how to convert it. Can you help me? Thanks

Advertisement

Answer

Found the correct way to convert it (thanks to @masahide: https://github.com/masahide/OmniSSHAgent/issues/16#issuecomment-1107446991):

setsid nohup socat UNIX-LISTEN:$SSH_AUTH_SOCK,fork EXEC:"$HOME/omni-socat/omni-socat.exe" >/dev/null 2>&1 & disown
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement