Skip to content

Commit

Permalink
Modifies configuration according to MacOS
Browse files Browse the repository at this point in the history
Signed-off-by: Saahil Bhavsar <saahil_bhavsar@outlook.com>
  • Loading branch information
SaahilNotSahil committed Apr 7, 2024
1 parent 88a1d0d commit 29149e9
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 16 deletions.
48 changes: 43 additions & 5 deletions cli/cmd/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,53 @@ var configureCmd = &cobra.Command{

for i, dir := range configDirs {
configPath = dir + "/scripts/configure-spok-server.sh"

_, err := os.Stat(configPath)
if err == nil {
break
} else if i == len(configDirs) - 1 {
} else if i == len(configDirs)-1 {
log.Fatal("Configuration script not found.")
}
}

fmt.Println("Configuration script found at:", configPath)

serverConfigPath := "/root/configure-spok-server.sh"
var serverConfigPath string

var osCommand *exec.Cmd

if privateKeyAuth && privateKeyPath != "" {
osCommand = exec.Command(
"ssh",
"-i",
privateKeyPath,
userArgs,
"uname",
"-o",
)
} else {
osCommand = exec.Command(
"ssh",
userArgs,
"uname",
"-o",
)
}

output, err := osCommand.Output()
cobra.CheckErr(err)

if strings.Contains(string(output), "Linux") {
fmt.Println("Remote platform detected: Linux")

serverConfigPath = "/root/configure-spok-server.sh"
} else if strings.Contains(string(output), "Darwin") {
fmt.Println("Remote platform detected: Mac")

serverConfigPath = "/var/root/configure-spok-server.sh"
} else {
log.Fatal("Unsupported remote platform.")
}

var scpCommandScript []string
var sshCommandChmod []string
Expand Down Expand Up @@ -131,9 +166,12 @@ var configureCmd = &cobra.Command{
scpCommandScript[0], scpCommandScript[1:]...,
)

fmt.Println("Copying configuration script to server...")
fmt.Printf(
"Copying configuration script to server at %s ...\n",
serverConfigPath,
)

err := scpCmdScript.Run()
err = scpCmdScript.Run()
if err != nil {
log.Fatal(err)
}
Expand Down
44 changes: 33 additions & 11 deletions scripts/configure-spok-server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,31 @@ if [ -z "${EMAIL}" ] || [ -z "${USER}" ]; then
exit 1
fi

if sudo -nl &> /dev/null || $(id -u) -ne 0; then
if sudo -nl &> /dev/null || [ "$(id -u)" -ne 0 ]; then
echo "User has sudo privileges without a password."

# Check for wget or curl availability
DOWNLOADER=""
if command -v wget &> /dev/null; then
DOWNLOADER="wget"
elif command -v curl &> /dev/null; then
DOWNLOADER="curl -LO"
else
echo "Neither wget nor curl is available. Please install either of them."
exit 1
fi

if [[ "$OS_VAL" == *"Linux"* && "$ARCH" == *"x86_64"* ]]; then
wget https://github.com/devlup-labs/spok/releases/download/${VERSION}/verifier_${VERSION}_linux_amd64
$DOWNLOADER https://github.com/devlup-labs/spok/releases/download/${VERSION}/verifier_${VERSION}_linux_amd64
mv verifier_${VERSION}_linux_amd64 verifier
elif [[ "$OS_VAL" == *"Linux"* && "$ARCH" == *"arm64"* ]]; then
wget https://github.com/devlup-labs/spok/releases/download/${VERSION}/verifier_${VERSION}_linux_arm64
$DOWNLOADER https://github.com/devlup-labs/spok/releases/download/${VERSION}/verifier_${VERSION}_linux_arm64
mv verifier_${VERSION}_linux_arm64 verifier
elif [[ "$OS_VAL" == *"Darwin"* && "$ARCH" == *"x86_64"* ]]; then
wget https://github.com/devlup-labs/spok/releases/download/${VERSION}/verifier_${VERSION}_darwin_amd64
$DOWNLOADER https://github.com/devlup-labs/spok/releases/download/${VERSION}/verifier_${VERSION}_darwin_amd64
mv verifier_${VERSION}_darwin_amd64 verifier
elif [[ "$OS_VAL" == *"Darwin"* && "$ARCH" == *"arm64"* ]]; then
wget https://github.com/devlup-labs/spok/releases/download/${VERSION}/verifier_${VERSION}_darwin_arm64
elif [[ "$OS_VAL" == *"Darwin"* && "$ARCH" == *"arm64"* ]]; then
$DOWNLOADER https://github.com/devlup-labs/spok/releases/download/${VERSION}/verifier_${VERSION}_darwin_arm64
mv verifier_${VERSION}_darwin_arm64 verifier
else
echo "This OS: $OS_VAL and ARCH: $ARCH is not supported please contact the developers for help :)"
Expand Down Expand Up @@ -66,17 +77,28 @@ else

mkdir ~/.spok

# Check for wget or curl availability
DOWNLOADER=""
if command -v wget &> /dev/null; then
DOWNLOADER="wget"
elif command -v curl &> /dev/null; then
DOWNLOADER="curl -LO"
else
echo "Neither wget nor curl is available. Please install either of them."
exit 1
fi

if [[ "$OS_VAL" == *"Linux"* && "$ARCH" == *"x86_64"* ]]; then
wget https://github.com/devlup-labs/spok/releases/download/${VERSION}/verifier_${VERSION}_linux_amd64
$DOWNLOADER https://github.com/devlup-labs/spok/releases/download/${VERSION}/verifier_${VERSION}_linux_amd64
mv verifier_${VERSION}_linux_amd64 verifier
elif [[ "$OS_VAL" == *"Linux"* && "$ARCH" == *"arm64"* ]]; then
wget https://github.com/devlup-labs/spok/releases/download/${VERSION}/verifier_${VERSION}_linux_arm64
$DOWNLOADER https://github.com/devlup-labs/spok/releases/download/${VERSION}/verifier_${VERSION}_linux_arm64
mv verifier_${VERSION}_linux_arm64 verifier
elif [[ "$OS_VAL" == *"Darwin"* && "$ARCH" == *"x86_64"* ]]; then
wget https://github.com/devlup-labs/spok/releases/download/${VERSION}/verifier_${VERSION}_darwin_amd64
$DOWNLOADER https://github.com/devlup-labs/spok/releases/download/${VERSION}/verifier_${VERSION}_darwin_amd64
mv verifier_${VERSION}_darwin_amd64 verifier
elif [[ "$OS_VAL" == *"Darwin"* && "$ARCH" == *"arm64"* ]]; then
wget https://github.com/devlup-labs/spok/releases/download/${VERSION}/verifier_${VERSION}_darwin_arm64
elif [[ "$OS_VAL" == *"Darwin"* && "$ARCH" == *"arm64"* ]]; then
$DOWNLOADER https://github.com/devlup-labs/spok/releases/download/${VERSION}/verifier_${VERSION}_darwin_arm64
mv verifier_${VERSION}_darwin_arm64 verifier
else
echo "This OS: $OS_VAL and ARCH: $ARCH is not supported please contact the developers for help :)"
Expand Down

0 comments on commit 29149e9

Please sign in to comment.