Writing a shell script while using "Packages" to make a .pkg file

703 views Asked by At

I really need your help with this: The thing is: I am trying to build my app into .pkg file, at the same time I want to integrate node.js into my .pkg installation file and it will be installed if the OS doesn't have nodejs. When I try to write a script to judge whether the user has already installed the node, I was stuck by "return value of the external script". I try my script at the end with 'echo' 'return' 'exit' but still not work.enter image description here

Here is the screenshot of "Packages" when I try to insert the script..

And this is the script I wrote.`#!/bin/bash

OUTPUT="$(node -v)"
    echo ${OUTPUT}
if [[ $OUTPUT = "" ]];
then
    echo "1"
    return 1
    #no node
else
    echo "0"
    return 0
    #node found
fi

` Pls help me

1

There are 1 answers

1
Jason Manuta On BEST ANSWER

This script will run the "node -v" command and send output (stderr and stdout) to /dev/null; nothing is displayed to user. The if condition checks if the command ran successfully and sets the exit status to 0 or 1 depending on the outcome.

#/bin/bash

main() {
    node -v >/dev/null 2>&1
    if [[ $? -eq 0 ]]; then
        return 0
    else
        return 1
    fi
}

main