|
18 | 18 | exit 1 |
19 | 19 | fi |
20 | 20 |
|
21 | | -command -v unzip >/dev/null || |
22 | | - error 'unzip is required to install sfcompute cli' |
| 21 | +# Function to check if a command exists |
| 22 | +command_exists() { |
| 23 | + command -v "$1" >/dev/null 2>&1 |
| 24 | +} |
| 25 | + |
| 26 | +# Check if unzip is installed, if not, try to install it |
| 27 | +if ! command_exists unzip; then |
| 28 | + echo "unzip is not installed. Attempting to install..." |
| 29 | + if command_exists apt-get; then |
| 30 | + sudo apt-get update && sudo apt-get install -y unzip |
| 31 | + elif command_exists yum; then |
| 32 | + sudo yum install -y unzip |
| 33 | + else |
| 34 | + echo "Unable to install unzip. Please install it manually and run this script again." |
| 35 | + exit 1 |
| 36 | + fi |
| 37 | +fi |
| 38 | + |
| 39 | +# Verify unzip is now available |
| 40 | +if ! command_exists unzip; then |
| 41 | + echo "Failed to install unzip. Please install it manually and run this script again." |
| 42 | + exit 1 |
| 43 | +fi |
23 | 44 |
|
24 | 45 | # Make sure the target dir exists |
25 | 46 | mkdir -p "${TARGET_DIR}" |
@@ -72,7 +93,7 @@ curl -L -o "${TMPDIR}/${BINARY_NAME}.zip" "${SF_BINARY_URL}" |
72 | 93 | # Extract the zip file in the temporary directory. |
73 | 94 | echo "unzip -o \"${TMPDIR}/${BINARY_NAME}.zip\" -d \"${TMPDIR}/dist\"" |
74 | 95 | unzip -o "${TMPDIR}/${BINARY_NAME}.zip" -d "${TMPDIR}/dist" || |
75 | | - error 'Failed to extract sf' |
| 96 | + { echo "Failed to extract sf"; exit 1; } |
76 | 97 |
|
77 | 98 | # Move the binary to the target directory. |
78 | 99 | mv "${TMPDIR}/dist/sf-$target" "${TARGET_DIR}/${BINARY_NAME}" |
@@ -100,6 +121,9 @@ if [ -f "${TARGET_FILE}" ]; then |
100 | 121 | echo -e "\033[1m echo 'export PATH=\"${TARGET_DIR}:\$PATH\"' >> ~/.zshrc && source ~/.zshrc\033[0m" |
101 | 122 | echo -e "\033[0;32m" |
102 | 123 | echo -e "After running the appropriate command, you can use '${BINARY_NAME}'.\033[0m" |
| 124 | + echo -e "\033[0;32m" |
| 125 | + echo -e "To get started, run: 'sf login'\033[0m" |
| 126 | + echo -e "\033[0;32m" |
103 | 127 |
|
104 | 128 | else |
105 | 129 | echo "Installation failed. '${BINARY_NAME}' CLI could not be installed." |
|
0 commit comments