0

I was sent a file to run to help setup my environment to work on my companies network but after making it executable I keep running into this error regarding a curly brace and it wanting then, I have tried adding then where it says that it wants it to no avail . Here is the code I am trying to execute It would be a godsend if somebody could correct it

echo "Setting up /etc/environment with proxy settings"

if ! grep -q proxy /etc/environment; 
    then
echo "Setting proxy system-wide"
{
    echo "http_proxy=\"http://proxy.cat.com:80/\""
    echo "https_proxy=\"http://proxy.cat.com:80/\""
    echo "ftp_proxy=\"http://proxy.cat.com:80/\""
    echo "socks_proxy=\"http://proxy.cat.com:80/\""
    echo "no_proxy=localhost,127.0.0.0/8,::1,cat.com,*.cat.com,165.26.78.0/23"
} >> /etc/environment
echo "Setting proxy for this session"
export http_proxy=http://proxy.cat.com:80/
export https_proxy=http://proxy.cat.com:80/
export ftp_proxy=http://proxy.cat.com:80/
export socks_proxy=http://proxy.cat.com:80/
else
if grep -q "https://proxy.cat.com" /etc/environment; then
    echo "/etc/environment contains invalid proxy settings, please remove all proxy settings from this file and rerun this script"
    echo "Execute the following command, remove all \"proxy\" lines, save and close: 'sudo gedit /etc/environment'"
    exit 2
fi
echo "/etc/environment already configured with a proxy"
fi
Pilot6
  • 88,764
  • 91
  • 205
  • 313
  • 1
    The file is corrupted. It makes no sense. – Pilot6 Jun 15 '22 at 16:09
  • shellcheck doesn't find any issues with that code snippet. Are you sure you're showing us the whole code that fails? – glenn jackman Jun 15 '22 at 16:14
  • @glennjackman thats the entire file. I try and execute it and it just says the first echo then the error message .... – Daredevilspaz Jun 15 '22 at 16:17
  • @Pilot6 what makes you think it is corrupted ? – Daredevilspaz Jun 15 '22 at 16:19
  • Show exactly how you execute it. – glenn jackman Jun 15 '22 at 16:19
  • 2
    ... a carriage return after the `then` would produce this error (in `sh` - bash would be slightly different) - check for DOS style line endings – steeldriver Jun 15 '22 at 16:20
  • @glennjackman I mean the file is in downloads so I just navigate there and type sudo ./proxy.sh – Daredevilspaz Jun 15 '22 at 16:20
  • @steeldriver should I remove all \ slashes ? The person who sent me the file advised to take out the extra \ but I was unsure what that meant since it is not my code – Daredevilspaz Jun 15 '22 at 16:22
  • As steeldriver (implicitly) suggests, use `dos2unix` on that file. Then, because the file does not have a `#!` line, you should specify an interpreter: `sudo bash ./proxy.sh` – glenn jackman Jun 15 '22 at 16:23
  • @glennjackman so the reason I need this proxy is I cannot use ubuntu servers or install /update software from command line. I just tried and am unable to install dos2unix but in running with bash I now get these new errors ./proxy.sh: line 11: syntax error near unexpected token `}' '/proxy.sh: line 11: ` } >> /etc/environment – Daredevilspaz Jun 15 '22 at 16:26
  • I can't find a reference for it, but executing a text file with no `#!` will use `/bin/sh` to interpret it (I recall) – glenn jackman Jun 15 '22 at 16:26
  • Try this: `sed -i 's/\r$//' proxy.sh` to remove the carriage returns – glenn jackman Jun 15 '22 at 16:27
  • @glennjackman wow! That worked, you are a lifesaver ! – Daredevilspaz Jun 15 '22 at 16:28
  • Does this answer your question? [Nessus installation problem on ubuntu 18](https://askubuntu.com/questions/1229943/nessus-installation-problem-on-ubuntu-18) – karel Jun 27 '22 at 05:09

0 Answers0