Skip to content

Commit

Permalink
add install script (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattbr0wn authored Sep 6, 2024
1 parent 4341cf8 commit 9f4f7e8
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 7 deletions.
2 changes: 2 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,7 @@ dist:
aws s3 cp ./mailsherpa-linux-arm64.tar.gz $CLOUDFLARE_R2_BUCKET/mailsherpa-linux-arm64.tar.gz --endpoint-url $CLOUDFLARE_R2_ENDPOINT
just clean

aws s3 cp ./install.py $CLOUDFLARE_R2_BUCKET/install.py --endpoint-url $CLOUDFLARE_R2_ENDPOINT

test:
go test ./...
24 changes: 17 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,44 @@ This is open-source, but we also offer a hosted API that's simple to use. If you

<br />

## Quickstart
## Installation

1. Download the appropriate CLI tarball for your OS:
If you want to use our install script, you can run the following command:

```
curl -sSL https://mailsherpa.sh/install.py | python3
```
otherwise, follow the diretions below:

Download the appropriate CLI tarball for your OS:

```
wget mailsherpa.sh/mailsherpa-linux-arm64.tar.gz
wget mailsherpa.sh/mailsherpa-linux-amd64.tar.gz
wget mailsherpa.sh/mailsherpa-macos.tar.gz
```

2. Extract the binary:
Extract the binary:

```
tar -xzf filename.tar.gz
```

3. Set the `MAIL_SERVER_DOMAIN` environment variable. See the `Mail Server setup guide` section below for more details:
4. Test to make sure everything is working

```
export MAIL_SERVER_DOMAIN=example.com
./mailsherpa version
```

4. Test to make sure everything is working
## Set env variables

Set the `MAIL_SERVER_DOMAIN` environment variable. See the `Mail Server setup guide` section below for more details:

```
./mailsherpa version
export MAIL_SERVER_DOMAIN=example.com
```


## Mail Server setup guide

You might be asking why you need to setup a mail server...
61 changes: 61 additions & 0 deletions install.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import os
import platform
import subprocess
import tarfile


def get_platform():
system = platform.system().lower()
machine = platform.machine().lower()

if system == 'darwin':
return 'macos'
elif system == 'linux':
if 'arm' in machine or 'aarch64' in machine:
return 'linux-arm64'
elif 'x86_64' in machine:
return 'linux-amd64'

raise ValueError(f"Unsupported platform: {system} {machine}")

def download_file(url):
subprocess.run(['wget', url], check=True)

def extract_tar(filename):
with tarfile.open(filename, 'r:gz') as tar:
tar.extractall()

def main():
try:
# 1. Detect OS platform
platform = get_platform()

# 2. Download the correct file
base_url = "https://mailsherpa.sh"
filename = f"mailsherpa-{platform}.tar.gz"
url = f"{base_url}/{filename}"

print(f"Downloading {url}")
download_file(url)

# 3. Extract the binary
print(f"Extracting {filename}")
extract_tar(filename)

# 4. Rename the binary
original_name = f"mailsherpa-{platform}"
new_name = "mailsherpa"
print(f"Renaming {original_name} to {new_name}")
os.rename(original_name, new_name)

# 5. Remove the tarball
print(f"Removing {filename}")
os.remove(filename)

print("Operation completed successfully")

except Exception as e:
print(f"An error occurred: {e}")

if __name__ == "__main__":
main()

0 comments on commit 9f4f7e8

Please sign in to comment.