Skip to content

Commit 5eb77cb

Browse files
committed
Merge branch 'release/v1.24.2'
2 parents 8ce5a35 + 5ab8486 commit 5eb77cb

File tree

9 files changed

+734
-550
lines changed

9 files changed

+734
-550
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22

33
Notable changes to Mailpit will be documented in this file.
44

5+
## [v1.24.2]
6+
7+
### Feature
8+
- Display unread count in app badge ([#485](https://github.com/axllent/mailpit/issues/485))
9+
10+
### Chore
11+
- Update caniemail database
12+
- Update node dependencies
13+
- Update Go dependencies
14+
- Install script improvements & better error handling ([#482](https://github.com/axllent/mailpit/issues/482))
15+
16+
517
## [v1.24.1]
618

719
### Feature

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,18 @@ Mailpit runs as a single binary and can be installed in different ways:
6868
- **FreeBSD**: `pkg install mailpit`
6969

7070

71-
### Install via bash script (Linux & Mac)
71+
### Install via script (Linux & Mac)
7272

7373
Linux & Mac users can install it directly to `/usr/local/bin/mailpit` with:
7474

75-
```bash
76-
sudo bash < <(curl -sL https://raw.githubusercontent.com/axllent/mailpit/develop/install.sh)
75+
```shell
76+
sudo sh < <(curl -sL https://raw.githubusercontent.com/axllent/mailpit/develop/install.sh)
77+
```
78+
79+
You can also change the install path to something else by setting the `INSTALL_PATH` environment, for example:
80+
81+
```shell
82+
INSTALL_PATH=/usr/bin sudo sh < <(curl -sL https://raw.githubusercontent.com/axllent/mailpit/develop/install.sh)
7783
```
7884

7985

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ require (
2121
github.com/sirupsen/logrus v1.9.3
2222
github.com/spf13/cobra v1.9.1
2323
github.com/spf13/pflag v1.0.6
24-
github.com/tg123/go-htpasswd v1.2.3
24+
github.com/tg123/go-htpasswd v1.2.4
2525
github.com/vanng822/go-premailer v1.24.0
2626
golang.org/x/net v0.39.0
2727
golang.org/x/text v0.24.0
@@ -57,7 +57,7 @@ require (
5757
golang.org/x/image v0.26.0 // indirect
5858
golang.org/x/sys v0.32.0 // indirect
5959
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
60-
modernc.org/libc v1.62.1 // indirect
60+
modernc.org/libc v1.65.0 // indirect
6161
modernc.org/mathutil v1.7.1 // indirect
62-
modernc.org/memory v1.9.1 // indirect
62+
modernc.org/memory v1.10.0 // indirect
6363
)

go.sum

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO
104104
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
105105
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
106106
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
107-
github.com/tg123/go-htpasswd v1.2.3 h1:ALR6ZBIc2m9u70m+eAWUFt5p43ISbIvAvRFYzZPTOY8=
108-
github.com/tg123/go-htpasswd v1.2.3/go.mod h1:FcIrK0J+6zptgVwK1JDlqyajW/1B4PtuJ/FLWl7nx8A=
107+
github.com/tg123/go-htpasswd v1.2.4 h1:HgH8KKCjdmo7jjXWN9k1nefPBd7Be3tFCTjc2jPraPU=
108+
github.com/tg123/go-htpasswd v1.2.4/go.mod h1:EKThQok9xHkun6NBMynNv6Jmu24A33XdZzzl4Q7H1+0=
109109
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
110110
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
111111
github.com/vanng822/css v1.0.1 h1:10yiXc4e8NI8ldU6mSrWmSWMuyWgPr9DZ63RSlsgDw8=
@@ -206,20 +206,20 @@ gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
206206
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
207207
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
208208
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
209-
modernc.org/cc/v4 v4.25.2 h1:T2oH7sZdGvTaie0BRNFbIYsabzCxUQg8nLqCdQ2i0ic=
210-
modernc.org/cc/v4 v4.25.2/go.mod h1:uVtb5OGqUKpoLWhqwNQo/8LwvoiEBLvZXIQ/SmO6mL0=
211-
modernc.org/ccgo/v4 v4.25.1 h1:TFSzPrAGmDsdnhT9X2UrcPMI3N/mJ9/X9ykKXwLhDsU=
212-
modernc.org/ccgo/v4 v4.25.1/go.mod h1:njjuAYiPflywOOrm3B7kCB444ONP5pAVr8PIEoE0uDw=
213-
modernc.org/fileutil v1.3.0 h1:gQ5SIzK3H9kdfai/5x41oQiKValumqNTDXMvKo62HvE=
214-
modernc.org/fileutil v1.3.0/go.mod h1:XatxS8fZi3pS8/hKG2GH/ArUogfxjpEKs3Ku3aK4JyQ=
209+
modernc.org/cc/v4 v4.26.0 h1:QMYvbVduUGH0rrO+5mqF/PSPPRZNpRtg2CLELy7vUpA=
210+
modernc.org/cc/v4 v4.26.0/go.mod h1:uVtb5OGqUKpoLWhqwNQo/8LwvoiEBLvZXIQ/SmO6mL0=
211+
modernc.org/ccgo/v4 v4.26.0 h1:gVzXaDzGeBYJ2uXTOpR8FR7OlksDOe9jxnjhIKCsiTc=
212+
modernc.org/ccgo/v4 v4.26.0/go.mod h1:Sem8f7TFUtVXkG2fiaChQtyyfkqhJBg/zjEJBkmuAVY=
213+
modernc.org/fileutil v1.3.1 h1:8vq5fe7jdtEvoCf3Zf9Nm0Q05sH6kGx0Op2CPx1wTC8=
214+
modernc.org/fileutil v1.3.1/go.mod h1:HxmghZSZVAz/LXcMNwZPA/DRrQZEVP9VX0V4LQGQFOc=
215215
modernc.org/gc/v2 v2.6.5 h1:nyqdV8q46KvTpZlsw66kWqwXRHdjIlJOhG6kxiV/9xI=
216216
modernc.org/gc/v2 v2.6.5/go.mod h1:YgIahr1ypgfe7chRuJi2gD7DBQiKSLMPgBQe9oIiito=
217-
modernc.org/libc v1.62.1 h1:s0+fv5E3FymN8eJVmnk0llBe6rOxCu/DEU+XygRbS8s=
218-
modernc.org/libc v1.62.1/go.mod h1:iXhATfJQLjG3NWy56a6WVU73lWOcdYVxsvwCgoPljuo=
217+
modernc.org/libc v1.65.0 h1:e183gLDnAp9VJh6gWKdTy0CThL9Pt7MfcR/0bgb7Y1Y=
218+
modernc.org/libc v1.65.0/go.mod h1:7m9VzGq7APssBTydds2zBcxGREwvIGpuUBaKTXdm2Qs=
219219
modernc.org/mathutil v1.7.1 h1:GCZVGXdaN8gTqB1Mf/usp1Y/hSqgI2vAGGP4jZMCxOU=
220220
modernc.org/mathutil v1.7.1/go.mod h1:4p5IwJITfppl0G4sUEDtCr4DthTaT47/N3aT6MhfgJg=
221-
modernc.org/memory v1.9.1 h1:V/Z1solwAVmMW1yttq3nDdZPJqV1rM05Ccq6KMSZ34g=
222-
modernc.org/memory v1.9.1/go.mod h1:/JP4VbVC+K5sU2wZi9bHoq2MAkCnrt2r98UGeSK7Mjw=
221+
modernc.org/memory v1.10.0 h1:fzumd51yQ1DxcOxSO+S6X7+QTuVU+n8/Aj7swYjFfC4=
222+
modernc.org/memory v1.10.0/go.mod h1:/JP4VbVC+K5sU2wZi9bHoq2MAkCnrt2r98UGeSK7Mjw=
223223
modernc.org/opt v0.1.4 h1:2kNGMRiUjrp4LcaPuLY2PzUfqM/w9N23quVwhKt5Qm8=
224224
modernc.org/opt v0.1.4/go.mod h1:03fq9lsNfvkYSfxrfUhZCWPk1lm4cq4N+Bh//bEtgns=
225225
modernc.org/sortutil v1.2.1 h1:+xyoGf15mM3NMlPDnFqrteY07klSFxLElE2PVuWIJ7w=

install.sh

Lines changed: 188 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,214 @@
1-
#!/usr/bin/env bash
1+
#!/bin/sh
22

3-
GH_REPO="axllent/mailpit"
4-
TIMEOUT=90
3+
# This script will install the latest release of Mailpit.
54

6-
set -e
5+
# Check dependencies is installed
6+
for cmd in curl tar; do
7+
if ! command -v "$cmd" >/dev/null 2>&1; then
8+
echo "Then $cmd command is required but not installed."
9+
echo "Please install $cmd and try again."
10+
exit 1
11+
fi
12+
done
713

8-
VERSION=$(curl --silent --location --max-time "${TIMEOUT}" "https://api.github.com/repos/${GH_REPO}/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
9-
if [ $? -ne 0 ]; then
10-
echo -ne "\nThere was an error trying to check what is the latest version of Mailpit.\nPlease try again later.\n"
11-
exit 1
12-
fi
13-
14-
# detect the platform
15-
OS="$(uname)"
16-
case $OS in
17-
Linux)
18-
OS='linux'
19-
;;
20-
FreeBSD)
21-
OS='freebsd'
22-
echo 'OS not supported'
23-
exit 2
24-
;;
25-
NetBSD)
26-
OS='netbsd'
27-
echo 'OS not supported'
28-
exit 2
29-
;;
30-
OpenBSD)
31-
OS='openbsd'
32-
echo 'OS not supported'
33-
exit 2
34-
;;
35-
Darwin)
36-
OS='darwin'
37-
;;
38-
SunOS)
39-
OS='solaris'
40-
echo 'OS not supported'
41-
exit 2
42-
;;
14+
# Check if the OS is supported.
15+
OS=
16+
case "$(uname -s)" in
17+
Linux) OS="linux" ;;
18+
Darwin) OS="Darwin" ;;
4319
*)
44-
echo 'OS not supported'
20+
echo "OS not supported."
4521
exit 2
4622
;;
4723
esac
4824

49-
# detect the arch
50-
OS_type="$(uname -m)"
51-
case "$OS_type" in
25+
# Detect the architecture of the OS.
26+
OS_ARCH=
27+
case "$(uname -m)" in
5228
x86_64 | amd64)
53-
OS_type='amd64'
29+
OS_ARCH="amd64"
5430
;;
5531
i?86 | x86)
56-
OS_type='386'
32+
OS_ARCH="386"
5733
;;
5834
aarch64 | arm64)
59-
OS_type='arm64'
35+
OS_ARCH="arm64"
6036
;;
6137
*)
62-
echo 'OS type not supported'
38+
echo "OS architecture not supported."
6339
exit 2
6440
;;
6541
esac
6642

67-
GH_REPO_BIN="mailpit-${OS}-${OS_type}.tar.gz"
43+
GH_REPO="axllent/mailpit"
44+
INSTALL_PATH="${INSTALL_PATH:-/usr/local/bin}"
45+
TIMEOUT=90
46+
# This is used to authenticate with the GitHub API. (Fix the public rate limiting issue)
47+
# Try the GITHUB_TOKEN environment variable is set globally.
48+
GITHUB_API_TOKEN="${GITHUB_TOKEN:-}"
6849

69-
#create tmp directory and move to it with macOS compatibility fallback
70-
tmp_dir=$(mktemp -d 2>/dev/null || mktemp -d -t 'mailpit-install.XXXXXXXXXX')
71-
cd "$tmp_dir"
50+
# Update the default values if the user has set.
51+
while [ $# -gt 0 ]; do
52+
case $1 in
53+
--install-path)
54+
shift
55+
case "$1" in
56+
*/*)
57+
# Remove trailing slashes from the path.
58+
INSTALL_PATH="$(echo "$1" | sed 's#/\+$##')"
59+
[ -z "$INSTALL_PATH" ] && INSTALL_PATH="/"
60+
;;
61+
esac
62+
;;
63+
--auth | --auth-token | --github-token | --token)
64+
shift
65+
case "$1" in
66+
gh*)
67+
GITHUB_API_TOKEN="$1"
68+
;;
69+
esac
70+
;;
71+
*) ;;
72+
esac
73+
shift
74+
done
7275

73-
echo "Downloading Mailpit $VERSION"
74-
LINK="https://github.com/${GH_REPO}/releases/download/${VERSION}/${GH_REPO_BIN}"
76+
# Description of the sort parameters for curl command.
77+
# -s: Silent mode.
78+
# -f: Fail silently on server errors.
79+
# -L: Follow redirects.
80+
# -m: Set maximum time allowed for the transfer.
7581

76-
curl --silent --location --max-time "${TIMEOUT}" "${LINK}" | tar zxf - || {
77-
echo "Error downloading"
78-
exit 2
79-
}
80-
81-
mkdir -p /usr/local/bin || exit 2
82-
cp mailpit /usr/local/bin/ || exit 2
83-
chmod 755 /usr/local/bin/mailpit || exit 2
84-
case "$OS" in
85-
'linux')
86-
chown root:root /usr/local/bin/mailpit || exit 2
87-
;;
88-
'freebsd' | 'openbsd' | 'netbsd' | 'darwin')
89-
chown root:wheel /usr/local/bin/mailpit || exit 2
90-
;;
82+
if [ -n "$GITHUB_API_TOKEN" ] && [ "${#GITHUB_API_TOKEN}" -gt 36 ]; then
83+
CURL_OUTPUT="$(curl -sfL -m $TIMEOUT -H "Authorization: Bearer $GITHUB_API_TOKEN" https://api.github.com/repos/${GH_REPO}/releases/latest)"
84+
EXIT_CODE=$?
85+
else
86+
CURL_OUTPUT="$(curl -sfL -m $TIMEOUT https://api.github.com/repos/${GH_REPO}/releases/latest)"
87+
EXIT_CODE=$?
88+
fi
89+
90+
VERSION=""
91+
if [ $EXIT_CODE -eq 0 ]; then
92+
# Extracts the latest version using jq, awk, or sed.
93+
if command -v jq >/dev/null 2>&1; then
94+
# Use jq -n because the output is not a valid JSON in sh.
95+
VERSION=$(jq -n "$CURL_OUTPUT" | jq -r '.tag_name')
96+
elif command -v awk >/dev/null 2>&1; then
97+
VERSION=$(echo "$CURL_OUTPUT" | awk -F: '$1 ~ /tag_name/ {gsub(/[^v0-9\.]+/, "", $2) ;print $2; exit}')
98+
elif command -v sed >/dev/null 2>&1; then
99+
VERSION=$(echo "$CURL_OUTPUT" | sed -n 's/.*"tag_name": *"\([^"]*\)".*/\1/p')
100+
else
101+
EXIT_CODE=3
102+
fi
103+
fi
104+
105+
# Validate the version.
106+
case "$VERSION" in
107+
v[0-9][0-9\.]*) ;;
91108
*)
92-
echo 'OS not supported'
93-
exit 2
109+
echo "There was an error trying to check what is the latest version of Mailpit."
110+
echo "Please try again later."
111+
exit $EXIT_CODE
94112
;;
95113
esac
96114

97-
rm -rf "$tmp_dir"
98-
echo "Installed successfully to /usr/local/bin/mailpit"
115+
TEMP_DIR="$(mktemp -qd)"
116+
EXIT_CODE=$?
117+
# Ensure the temporary directory exists and is a directory.
118+
if [ -z "$TEMP_DIR" ] || [ ! -d "$TEMP_DIR" ]; then
119+
echo "ERROR: Creating temporary directory."
120+
exit $EXIT_CODE
121+
fi
122+
123+
GH_REPO_BIN="mailpit-${OS}-${OS_ARCH}.tar.gz"
124+
if [ "$INSTALL_PATH" = "/" ]; then
125+
INSTALL_BIN_PATH="/mailpit"
126+
else
127+
INSTALL_BIN_PATH="${INSTALL_PATH}/mailpit"
128+
fi
129+
cd "$TEMP_DIR" || EXIT_CODE=$?
130+
if [ $EXIT_CODE -eq 0 ]; then
131+
# Download the latest release.
132+
#
133+
# Description of the sort parameters for curl command.
134+
# -s: Silent mode.
135+
# -f: Fail silently on server errors.
136+
# -L: Follow redirects.
137+
# -m: Set maximum time allowed for the transfer.
138+
# -o: Write output to a file instead of stdout.
139+
curl -sfL -m $TIMEOUT -o "${GH_REPO_BIN}" "https://github.com/${GH_REPO}/releases/download/${VERSION}/${GH_REPO_BIN}"
140+
EXIT_CODE=$?
141+
142+
# The following conditions check each step of the installation.
143+
# If there is an error in any of the steps, an error message is printed.
144+
145+
if [ $EXIT_CODE -eq 0 ]; then
146+
if ! [ -f "${GH_REPO_BIN}" ]; then
147+
EXIT_CODE=1
148+
echo "ERROR: Downloading latest release."
149+
fi
150+
fi
151+
152+
if [ $EXIT_CODE -eq 0 ]; then
153+
tar zxf "$GH_REPO_BIN"
154+
EXIT_CODE=$?
155+
if [ $EXIT_CODE -ne 0 ]; then
156+
echo "ERROR: Extracting \"${GH_REPO_BIN}\"."
157+
fi
158+
fi
159+
160+
if [ $EXIT_CODE -eq 0 ] && [ ! -d "$INSTALL_PATH" ]; then
161+
mkdir -p "${INSTALL_PATH}"
162+
EXIT_CODE=$?
163+
if [ $EXIT_CODE -ne 0 ]; then
164+
echo "ERROR: Creating \"${INSTALL_PATH}\" directory."
165+
fi
166+
fi
167+
168+
if [ $EXIT_CODE -eq 0 ]; then
169+
cp mailpit "$INSTALL_BIN_PATH"
170+
EXIT_CODE=$?
171+
if [ $EXIT_CODE -ne 0 ]; then
172+
echo "ERROR: Copying mailpit to \"${INSTALL_PATH}\" directory."
173+
fi
174+
fi
175+
176+
if [ $EXIT_CODE -eq 0 ]; then
177+
chmod 755 "$INSTALL_BIN_PATH"
178+
EXIT_CODE=$?
179+
if [ $EXIT_CODE -ne 0 ]; then
180+
echo "ERROR: Setting permissions for \"$INSTALL_BIN_PATH\" binary."
181+
fi
182+
fi
183+
184+
# Set the owner and group to root:root if the script is run as root.
185+
if [ $EXIT_CODE -eq 0 ] && [ "$(id -u)" -eq "0" ]; then
186+
OWNER="root"
187+
GROUP="root"
188+
# Set the OWNER, GROUP variable when the OS not use the default root:root.
189+
case "$OS" in
190+
darwin) GROUP="wheel" ;;
191+
*) ;;
192+
esac
193+
194+
chown "${OWNER}:${GROUP}" "$INSTALL_BIN_PATH"
195+
EXIT_CODE=$?
196+
if [ $EXIT_CODE -ne 0 ]; then
197+
echo "ERROR: Setting ownership for \"$INSTALL_BIN_PATH\" binary."
198+
fi
199+
fi
200+
else
201+
echo "ERROR: Changing to temporary directory."
202+
exit $EXIT_CODE
203+
fi
204+
205+
# Cleanup the temporary directory.
206+
rm -rf "$TEMP_DIR"
207+
# Check the EXIT_CODE variable, and print the success or error message.
208+
if [ $EXIT_CODE -ne 0 ]; then
209+
echo "There was an error installing Mailpit."
210+
exit $EXIT_CODE
211+
fi
212+
213+
echo "Installed successfully to \"$INSTALL_BIN_PATH\"."
214+
exit 0

0 commit comments

Comments
 (0)