2 files changed
+235
install-unix.sh
new
+163
@@ -0,0 +1,163 @@
1
+#!/usr/bin/env bash
2
+
3
+set -euo pipefail
4
+
5
+# =============================================================================
6
+# Define helper functions
7
+# =============================================================================
8
+
9
+text_bold() {
10
+ echo -e "\033[1m$1\033[0m"
11
+}
12
+text_title() {
13
+ echo ""
14
+ text_bold "$1"
15
+ if [ "$2" != "" ]; then echo "$2"; fi
16
+}
17
+text_title_error() {
18
+ echo ""
19
+ echo -e "\033[1;31m$1\033[00m"
20
+}
21
+
22
+# =============================================================================
23
+# Define base variables
24
+# =============================================================================
25
+
26
+NAME="smbcloud-cli"
27
+VERSION="0.3.26"
28
+GITHUB_REPO="https://github.com/smbcloudXYZ/smbcloud-cli"
29
+DOWNLOAD_BASE_URL="https://github.com/$GITHUB_REPO/releases/download/$VERSION"
30
+
31
+if [ "$VERSION" == "latest" ]; then
32
+ # The latest version is accessible from a slightly different URL
33
+ DOWNLOAD_BASE_URL="https://github.com/$GITHUB_REPO/releases/latest/download"
34
+fi
35
+
36
+# =============================================================================
37
+# Define binary list for supported OS & Arch
38
+# - this is a map of "OS:Arch" -> "download binary name"
39
+# - you can remove or add to this list as needed
40
+# =============================================================================
41
+
42
+declare -A BINARIES=(
43
+ ["Linux:x86_64"]="smb"
44
+ ["Darwin:x86_64"]="smb"
45
+ ["Darwin:arm64"]="smb"
46
+)
47
+
48
+# =============================================================================
49
+# Get the user's OS and Arch
50
+# =============================================================================
51
+
52
+OS="$(uname -s)"
53
+ARCH="$(uname -m)"
54
+SYSTEM="${OS}:${ARCH}"
55
+
56
+# =============================================================================
57
+# Match a binary to check if the system is supported
58
+# =============================================================================
59
+
60
+if [[ ! ${BINARIES["$SYSTEM"]+_} ]]; then
61
+ text_title_error "Error"
62
+ echo " Unsupported OS or arch: ${SYSTEM}"
63
+ echo ""
64
+ exit 1
65
+fi
66
+
67
+# =============================================================================
68
+# Set the default installation variables
69
+# =============================================================================
70
+
71
+INSTALL_DIR="/usr/local/bin"
72
+BINARY="${BINARIES["$SYSTEM"]}"
73
+DOWNLOAD_URL="$DOWNLOAD_BASE_URL/$BINARY"
74
+
75
+# =============================================================================
76
+# Handle script arguments if passed
77
+# -u: install to user bin directory
78
+# -d <path>: specify installation directory
79
+# =============================================================================
80
+
81
+if [ $# -gt 0 ]; then
82
+ while getopts ":ud:" opt; do
83
+ case $opt in
84
+ u)
85
+ # Set default install dir based on OS
86
+ [ "$OS" == "Darwin" ] && INSTALL_DIR="$HOME/bin" || INSTALL_DIR="$HOME/.local/bin"
87
+
88
+ # Check that the user bin directory is in their PATH
89
+ IFS=':' read -ra PATHS <<< "$PATH"
90
+ INSTALL_DIR_IN_PATH="false"
91
+ for P in "${PATHS[@]}"; do
92
+ if [[ "$P" == "$INSTALL_DIR" ]]; then
93
+ INSTALL_DIR_IN_PATH="true"
94
+ fi
95
+ done
96
+
97
+ # If user bin directory doesn't exist or not in PATH, exit
98
+ if [ ! -d "$INSTALL_DIR" ] || [ "$INSTALL_DIR_IN_PATH" == "false" ]; then
99
+ text_title_error "Error"
100
+ echo " The user bin directory '$INSTALL_DIR' does not exist or is not in your environment PATH variable"
101
+ echo " To fix this error:"
102
+ echo " - Omit the '-u' option and to install system-wide"
103
+ echo " - Specify an installation directory with -d <path>"
104
+ echo ""
105
+ exit 1
106
+ fi
107
+
108
+ ;;
109
+ d)
110
+ # Get absolute path in case a relative path is provided
111
+ INSTALL_DIR=$(cd "$OPTARG"; pwd)
112
+
113
+ if [ ! -d "$INSTALL_DIR" ]; then
114
+ text_title_error "Error"
115
+ echo " The installation directory '$INSTALL_DIR' does not exist or is not a directory"
116
+ echo ""
117
+ exit 1
118
+ fi
119
+
120
+ ;;
121
+ \?)
122
+ text_title_error "Error"
123
+ echo " Invalid option: -$OPTARG" >&2
124
+ echo ""
125
+ exit 1
126
+ ;;
127
+ :)
128
+ text_title_error "Error"
129
+ echo " Option -$OPTARG requires an argument." >&2
130
+ echo ""
131
+ exit 1
132
+ ;;
133
+ esac
134
+done
135
+fi
136
+
137
+# =============================================================================
138
+# Create and change to temp directory
139
+# =============================================================================
140
+
141
+cd "$(mktemp -d)"
142
+
143
+# =============================================================================
144
+# Download binary
145
+# =============================================================================
146
+
147
+text_title "Downloading Binary" " $DOWNLOAD_URL"
148
+curl -LO --proto '=https' --tlsv1.2 -sSf "$DOWNLOAD_URL"
149
+
150
+# =============================================================================
151
+# Make binary executable and move to install directory with appropriate name
152
+# =============================================================================
153
+
154
+text_title "Installing Binary" " $INSTALL_DIR/$NAME"
155
+chmod +x "$BINARY"
156
+mv "$BINARY" "$INSTALL_DIR/$NAME"
157
+
158
+# =============================================================================
159
+# Display post install message
160
+# =============================================================================
161
+
162
+text_title "Installation Complete" " Run $NAME --help for more information"
163
+echo ""
install-windows.sh
new
+72
@@ -0,0 +1,72 @@
1
+$ErrorActionPreference = "Stop"
2
+
3
+# =============================================================================
4
+# Define base variables
5
+# =============================================================================
6
+
7
+$name = "smbcloud-cli"
8
+$binary="$name.exe"
9
+$version="0.3.26"
10
+$githubRepo="https://github.com/smbcloudXYZ/smbcloud-cli"
11
+$downloadBaseUrl="https://github.com/$githubRepo/releases/download/$version"
12
+
13
+if ($version -eq "latest") {
14
+ # The latest version is accessible from a slightly different URL
15
+ $downloadBaseUrl="https://github.com/$githubRepo/releases/latest/download"
16
+}
17
+
18
+# =============================================================================
19
+# Determine system architecture and obtain the relevant binary to download
20
+# - you can add more "if" conditions to support additional architectures
21
+# =============================================================================
22
+
23
+$type = (Get-ComputerInfo).CsSystemType.ToLower()
24
+if ($type.StartsWith("x64")) {
25
+ $downloadFile = "smb"
26
+} else {
27
+ Write-Host "[Error]" -ForegroundColor Red
28
+ Write-Host "Unsupported Archi<tecture: $type" -ForegroundColor Red
29
+ [Environment]::Exit(1)
30
+}
31
+
32
+# =============================================================================
33
+# Create installation directory
34
+# =============================================================================
35
+
36
+$destDir = "$env:USERPROFILE\AppData\Local\$name"
37
+$destBin = "$destDir\$binary"
38
+Write-Host "Creating Install Directory" -ForegroundColor White
39
+Write-Host " $destDir"
40
+
41
+# Create the directory if it doesn't exist
42
+if (-Not (Test-Path $destDir)) {
43
+ New-Item -ItemType Directory -Path $destDir
44
+}
45
+
46
+# =============================================================================
47
+# Download the binary to the installation directory
48
+# =============================================================================
49
+
50
+$downloadUrl = "$downloadBaseUrl/$downloadFile"
51
+Write-Host "Downloading Binary" -ForegroundColor White
52
+Write-Host " From: $downloadUrl"
53
+Write-Host " Path: $destBin"
54
+Invoke-WebRequest -Uri $downloadUrl -OutFile "$destBin"
55
+
56
+# =============================================================================
57
+# Add installation directory to the user's PATH if not present
58
+# =============================================================================
59
+
60
+$currentPath = [System.Environment]::GetEnvironmentVariable('Path', [System.EnvironmentVariableTarget]::User)
61
+if (-Not ($currentPath -like "*$destDir*")) {
62
+ Write-Host "Adding Install Directory To System Path" -ForegroundColor White
63
+ Write-Host " $destBin"
64
+ [System.Environment]::SetEnvironmentVariable('Path', "$currentPath;$destDir", [System.EnvironmentVariableTarget]::User)
65
+}
66
+
67
+# =============================================================================
68
+# Display post installation message
69
+# =============================================================================
70
+
71
+Write-Host "Installation Complete" -ForegroundColor Green
72
+Write-Host " Restart your shell to starting using '$binary'. Run '$binary --help' for more information"