Skip to content

Commit 440cf46

Browse files
committed
add release script for .rpm and .deb pkgs
1 parent aaac0bc commit 440cf46

File tree

8 files changed

+220
-0
lines changed

8 files changed

+220
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist/pkg

dist/bashrpc.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
3+
port: 8675
4+
5+
whitelisted_clients:
6+
- 127.0.0.1
7+
8+
# REQUIRED:
9+
# This secret is passed by clients as an Authorization header. TODO: accept environment variable overrides.
10+
# secret: supersecret
11+
12+
routes:
13+
- path: /
14+
cmd: |
15+
echo "bashRPC server is running."
16+
echo "Configure more routes in bashrpc.yml file."

dist/init/systemd/bashrpc.service

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[Unit]
2+
Description=bashrpc
3+
4+
[Service]
5+
Type=simple
6+
Restart=always
7+
RestartSec=5s
8+
ExecStart=/usr/local/bin/bashrpc
9+
10+
[Install]
11+
WantedBy=multi-user.target

dist/init/sysvinit/bashrpc

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/bin/sh
2+
### BEGIN INIT INFO
3+
# Provides: bashrpc
4+
# Required-Start: $local_fs $network $named $time $syslog
5+
# Required-Stop: $local_fs $network $named $time $syslog
6+
# Default-Start: 2 3 4 5
7+
# Default-Stop: 0 1 6
8+
# Short-Description: starts bashrpc
9+
# Description: starts bashrpc
10+
### END INIT INFO
11+
12+
DESC="bashRPC"
13+
NAME=bashrpc
14+
DAEMON=/usr/local/bin/bashrpc
15+
16+
17+
LOGFILE=/var/log/$NAME.log
18+
CONFIGFILE=/etc/bashrpc/bashrpc.yml
19+
20+
test -x $DAEMON || exit 0
21+
22+
start() {
23+
touch $LOGFILE
24+
nohup "$DAEMON" -c "$CONFIGFILE" &
25+
}
26+
27+
stop() {
28+
pkill -f "$DAEMON"
29+
}
30+
31+
reload() {
32+
echo "Reload not supported. Restarting instead"
33+
start
34+
stop
35+
}
36+
37+
status() {
38+
if pgrep -f "$DAEMON" > /dev/null; then
39+
echo "$NAME is running"
40+
else
41+
echo "$NAME is not running"
42+
fi
43+
}
44+
45+
case "$1" in
46+
start)
47+
echo "Starting $NAME"
48+
start
49+
;;
50+
stop)
51+
echo "Stopping $NAME"
52+
stop
53+
;;
54+
restart)
55+
echo "Restarting $NAME"
56+
stop
57+
start
58+
;;
59+
reload)
60+
echo "Reloading $NAME"
61+
reload
62+
;;
63+
status)
64+
status
65+
;;
66+
*)
67+
echo "Usage: $0 {start|stop|restart|reload|status}"
68+
exit 2
69+
;;
70+
esac
71+
72+
exit 0

dist/scripts/postinstall.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env bash
2+
3+
service_manager=$(ps --no-headers -o comm 1)
4+
5+
banner() {
6+
echo "##################################"
7+
}
8+
9+
common_instructions() {
10+
echo "REQUIRED: add secret to /etc/bashrpc/bashrpc.yml"
11+
}
12+
13+
if [ "$service_manager" = init ]; then
14+
echo "+ setting up init script"
15+
mv /etc/bashrpc/init/sysvinit/bashrpc /etc/init.d/bashrpc
16+
banner
17+
echo "run the following to get started:"
18+
common_instructions
19+
echo "$ chkconfig --add bashrpc"
20+
echo "$ service bashrpc start"
21+
banner
22+
else
23+
echo "+ setting up systemd service"
24+
mv /etc/bashrpc/init/systemd/bashrpc.service /etc/systemd/system/bashrpc.service
25+
banner
26+
echo "run the following to get started:"
27+
common_instructions
28+
echo "$ systemctl daemon-reload"
29+
echo "$ systemctl enable bashrpc"
30+
echo "$ systemctl start bashrpc"
31+
banner
32+
fi
33+
34+
echo "+ DONE"

dist/scripts/postremove.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env bash
2+
3+
service_manager=$(ps --no-headers -o comm 1)
4+
5+
if [ "$service_manager" = init ]; then
6+
echo "+ removing init script"
7+
rm -f /etc/init.d/bashrpc
8+
else
9+
echo "+ removing systemd service"
10+
rm -f /etc/systemd/system/bashrpc.service
11+
fi
12+
13+
echo "+ DONE"

nfpm.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: "bashRPC"
2+
arch: "amd64"
3+
platform: "linux"
4+
version: "${BASHRPC_VERSION}"
5+
section: "default"
6+
priority: "extra"
7+
replaces:
8+
- bashrpc
9+
provides:
10+
- bashrpc
11+
maintainer: "John Mason <john@johnmason.io>"
12+
homepage: "http://github.com/binarymason/bashRPC"
13+
license: "MIT"
14+
bindir: "/usr/local/bin"
15+
files:
16+
./dist/pkg/bashrpc: "/usr/local/bin/bashrpc"
17+
./dist/init/systemd/bashrpc.service: "/etc/bashrpc/init/systemd/bashrpc.service"
18+
./dist/init/sysvinit/bashrpc: "/etc/bashrpc/init/sysvinit/bashrpc"
19+
config_files:
20+
./dist/bashrpc.yml: "/etc/bashrpc/bashrpc.yml"
21+
overrides:
22+
rpm:
23+
scripts:
24+
postinstall: ./dist/scripts/postinstall.sh
25+
postremove: ./dist/scripts/postremove.sh
26+
deb:
27+
scripts:
28+
postinstall: ./dist/scripts/postinstall.sh
29+
postremove: ./dist/scripts/postremove.sh

script/release

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
branch=$(git rev-parse --abbrev-ref HEAD)
6+
7+
if [ "$branch" != master ]; then
8+
echo "! ERROR: not on master branch"
9+
echo "! exiting..."
10+
exit 1
11+
fi
12+
13+
# User calendar versioning instead of semantic.
14+
ts=$(TZ=America/New_York date '+%y.%m.%d-%H%M')
15+
tag="v$ts"
16+
pkg_path=./dist/pkg
17+
18+
echo "* cleaning any pre-existing build artifacts"
19+
rm -rf "$pkg_path"
20+
mkdir "$pkg_path"
21+
22+
echo "* building go binary"
23+
go build -o "$pkg_path/bashrpc"
24+
25+
echo "* building rpm package"
26+
BASHRPC_VERSION="$tag" nfpm pkg --target "$pkg_path/bashrpc-$tag.rpm"
27+
28+
echo "* building rpm package"
29+
BASHRPC_VERSION="$tag" nfpm pkg --target "$pkg_path/bashrpc-$tag.deb"
30+
31+
echo "* creating tag: $tag"
32+
echo "skip"
33+
git tag "$tag"
34+
35+
echo "* pushing tag: $tag"
36+
git push origin "$tag"
37+
38+
echo "* packages placed in $pkg_path"
39+
for f in $pkg_path/*; do
40+
echo -e "\t- $f"
41+
done
42+
43+
echo "* you are ready to make a release on GitHub."
44+
echo "* OK"

0 commit comments

Comments
 (0)