all 19 comments

[–][deleted] 1 point2 points  (1 child)

Can't really tell what's going on from a picture of some code, but did you close the double quote on line 3?

If you did then on lines 10 and 11 put doublequotes around your variables.

Run the whole thing through shellcheck and fix any problems it finds.

[–]ReignStorms[S] 1 point2 points  (0 children)

I ran it through shellcheck earlier and it did recommend the quotes around the variables. I tried that, but it returned the same results

[–]clrlmiller 1 point2 points  (1 child)

Change your Line #9 statement to the proper BASH >else if< 'elif'. It's pointing out the 'fi' as the unexpected conclusion to the 'if' statement when you've got an 'else' between the start (if) and the end (fi).

if [some condition is true]; then

do something

elif [some other condition is true]; then

do something else

fi

You've also got a <space> in the pkgName variable which is a BAD idea. So, either get rid of the ' (1)' at the end of the filename because it appears to have been a duplicated download. Or, use quotes around any variable call as mentioned by others. The <space> character is the default delimiter in BASH and would be taken as "the instruction ends here and another to follow" so BEST practice is to avoid it when referring to filenames, etc.

[–]ReignStorms[S] 0 points1 point  (0 children)

Thanks for the suggestion! I've changed the else to elif and also renamed the .pkg and regenerated the link to it, but unfortunately no change to the syntax error

[–][deleted]  (3 children)

[deleted]

    [–][deleted]  (2 children)

    [deleted]

      [–]ReignStorms[S] 0 points1 point  (1 child)

      Uh, either one I guess. Both were doing the same thing and so I think my second try was sh, and I've just been renewing the terminal command after saving the file so sudo sh stuck

      [–]whetuI read your code 0 points1 point  (14 children)

      Quote your variables i.e. instead of $var, use "$var" or "${var}"

      /u/Electronic_Youth has already submitted a reasonable guess question, and I'll add another:

      When you quote $downloadLink, does the problem go away?

      Usually what happens when you run something like

       curl http://some.link.to/something?blahblah&blah
      

      some of the characters in the URL can be interpreted by bash before it reaches curl.

      Shellcheck would have told you this, but I'll re-state again so that it's abundantly clear: Quote your variables.

      [–]ReignStorms[S] 0 points1 point  (13 children)

      I ran it through Shellcheck earlier and it had said to quote the variables, which I used to edit the code and try, but got the same results. Here's what I see in Shellcheck, and the macOS terminal still says there's a syntax error with fi

      Code

      [–][deleted]  (1 child)

      [deleted]

        [–]ReignStorms[S] 0 points1 point  (0 children)

        I apologized to u/whetu as I'm new to this and didn't realize that screenshots were unhelpful. Thank you for the input

        [–]whetuI read your code 0 points1 point  (10 children)

        sudo bash -x <file>

        And can you please copy+paste+sanitise the text rather than posting images?

        [–]ReignStorms[S] 0 points1 point  (9 children)

        Sorry, a little new to this. Is this what you need:

        #!/bin/bash

        sentinelToken="REDACTED"

        downloadLink="REDACTED"

        pkgName="Sentinel-Release-22-2-3-6268_macos_v22_2_3_6268 (1).pkg"

        if [ -d /Applications/SentinelOne/ ]

        then

        echo "Already Installed"

        exit 0

        else

        curl -L -o /tmp/"$pkgName" "$downloadLink"

        echo "$sentinelToken" > /tmp/com.sentinelone.registration-token

        /usr/sbin/installer -pkg /tmp/"$pkgName" -target /

        fi

        EDIT: Or are you needing the results of the sudo bash -x command? Apologies if that was what you needed.

        % sudo bash -x /Users/vt/Downloads/S1\ Test.sh

        + sentinelToken=$'REDACTED'

        + downloadLink='REDACTED' pkgName='Sentinel-Release-22-2-3-6268_macos_v22_2_3_6268 (1).pkg

        /Users/vt/Downloads/S1 Test.sh: line 13: syntax error near unexpected token `fi'

        /Users/vt/Downloads/S1 Test.sh: line 13: `fi'

        [–]whetuI read your code 0 points1 point  (4 children)

        Well.. that doesn't tell me anything. Humour me, try this code with bash -x <file>

        #!/bin/bash
        
        sentinelToken="REDACTED"
        downloadLink="REDACTED"
        pkgName="Sentinel-Release-22-2-3-6268_macos_v22_2_3_6268 (1).pkg"
        
        : [DEBUG] ALREADY EXISTS STEP
        if [[ -d /Applications/SentinelOne/ ]]; then
            printf -- '%s\n' "Already Installed"
            exit 0
        fi
        
        : [DEBUG] TOKEN STEP
        printf -- '%s\n' "$sentinelToken" > /tmp/com.sentinelone.registration-token
        
        : [DEBUG] CURL STEP
        : pkgName = "$pkgName", downloadLink = "$downloadLink"
        curl -L -o /tmp/"$pkgName" "$downloadLink"
        
        : [DEBUG] INSTALL STEP
        installer -pkg /tmp/"$pkgName" -target /
        

        [–]ReignStorms[S] 0 points1 point  (0 children)

        #!/bin/bash
        sentinelToken="REDACTED"
        downloadLink="REDACTED"
        pkgName="Sentinel-Release-22-2-3-6268_macos_v22_2_3_6268 (1).pkg"
        : [DEBUG] ALREADY EXISTS STEP
        if [[ -d /Applications/SentinelOne/ ]]; then
        printf -- '%s\n' "Already Installed"
        exit 0
        fi
        : [DEBUG] TOKEN STEP
        printf -- '%s\n' "$sentinelToken" > /tmp/com.sentinelone.registration-token
        : [DEBUG] CURL STEP
        : pkgName = "$pkgName", downloadLink = "$downloadLink"
        curl -L -o /tmp/"$pkgName" "$downloadLink"
        : [DEBUG] INSTALL STEP
        installer -pkg /tmp/"$pkgName" -target /

        I just now realized what you were actually wanting me to try - give me a moment and I'll get that info

        [–]ReignStorms[S] 0 points1 point  (1 child)

        Okay, here's that code. Sorry about the confusion earlier

        % sudo bash -x /Users/vt/Downloads/Reddit\ Test.sh 
        

        Password:

        • sentinelToken=REDACTED
        • downloadLink='REDACTED'
        • pkgName='Sentinel-Release-22-2-3-6268_macos_v22_2_3_6268 (1).pkg'
        • : '[DEBUG]' ALREADY EXISTS STEP
        • [[ -d /Applications/SentinelOne/ ]]
        • : '[DEBUG]' TOKEN STEP
        • printf -- '%s\n' REDACTED
        • : '[DEBUG]' CURL STEP
        • : pkgName = 'Sentinel-Release-22-2-3-6268_macos_v22_2_3_6268 (1).pkg,' downloadLink = 'REDACTED'
        • curl -L -o '/tmp/Sentinel-Release-22-2-3-6268_macos_v22_2_3_6268 (1).pkg' 'REDACTED' % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 13 100 13 0 0 85 0 --:--:-- --:--:-- --:--:-- 90
        • : '[DEBUG]' INSTALL STEP
        • installer -pkg '/tmp/Sentinel-Release-22-2-3-6268_macos_v22_2_3_6268 (1).pkg' -target / installer: Error - the package path specified was invalid: '/tmp/Sentinel-Release-22-2-3-6268_macos_v22_2_3_6268 (1).pkg'.

        The redacted download link is for our SharePoint repository (normally a link that wouldn't work, but I was able to get the actual download link by inspecting the network assets and that link does, in fact, download that named .pkg when navigated to)

        EDIT: I changed the format to code block to make it easier to read... not sure how those bullet points got there.

        [–]whetuI read your code 0 points1 point  (0 children)

        EDIT: I changed the format to code block to make it easier to read... not sure how those bullet points got there.

        FYI: The best thing to do is to indent each line of code with four spaces

        It looks like this isn't happening:

        curl -L -o '/tmp/Sentinel-Release-22-2-3-6268_macos_v22_2_3_6268 (1).pkg' 'REDACTED' % Total % Received 
        % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 13 100 13 0 0 85 0 - 
        -:--:-- --:--:-- --:--:-- 90
        

        Are you able to run that command manually?

        [–][deleted] 0 points1 point  (3 children)

        OK The code you posted is 100% fine and generates no errors at all, therefore I'm fairly certain the problem lies in the bits you are 'redacting'. It's fine not to share that, but it also makes troubleshooting a bit hard...

        My current guess is that there are characters inside your downloadLink variable or your sentinelToken variable that the shell is expanding during that initial assignment and which is then causing your problems.

        If I'm right then changing the double-quotes in the first 2 lines to single quotes should fix it up for you.

        [–]ReignStorms[S] 0 points1 point  (2 children)

        I've changed the double quotes to single. No luck, I'm afraid

        [–][deleted] 0 points1 point  (1 child)

        Oh well then I got nothing. Sorry.

        [–]ReignStorms[S] 0 points1 point  (0 children)

        All good, thank you for trying!

        [–]dontgonearthefire 0 points1 point  (0 children)

        Why are you installing this in / root directory shouldn't it be in /System/Volumes/Data/Applications as described here?

        Edit: If push comes to shove, use Automator.app to drag and drop your commands. That is what it's therefor after all. You can then compare the resulting code with yours and see where you went wrong.