-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into report-log
- Loading branch information
Showing
8 changed files
with
162 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
# package information | ||
readonly PACKAGE_NAME="toglacier" | ||
readonly VENDOR="Rafael Dantas Justo" | ||
readonly MAINTAINER="Rafael Dantas Justo <[email protected]>" | ||
readonly URL="https://rafael.net.br" | ||
readonly LICENSE="MIT" | ||
readonly DESCRIPTION="Send data to Amazon Glacier service periodically." | ||
|
||
# install information | ||
readonly TMP_PATH="/tmp/toglacier/" | ||
readonly BIN_PATH="$TMP_PATH/usr/local/bin/" | ||
readonly CONF_PATH="$TMP_PATH/etc/" | ||
|
||
exit_error() { | ||
echo "$1. Abort" 1>&2 | ||
exit 1 | ||
} | ||
|
||
prepare() { | ||
rm -f toglacier*.deb 2>/dev/null | ||
|
||
mkdir -p $BIN_PATH || exit_error "Cannot create the temporary path" | ||
mkdir -p $CONF_PATH || exit_error "Cannot create the temporary path" | ||
} | ||
|
||
compile() { | ||
local project_path=`echo $GOPATH | cut -d: -f1` | ||
local program_path="" | ||
local current_path=`pwd` | ||
|
||
program_path=$project_path/src/github.com/rafaeljusto/toglacier/cmd/toglacier | ||
cd $program_path || exit_error "Cannot change directory" | ||
env GOOS=linux GOARCH=amd64 go build -ldflags "-X github.com/rafaeljusto/toglacier/internal/config.Version=$VERSION" || exit_error "Compile error" | ||
mv toglacier $BIN_PATH || exit_error "Error copying binary" | ||
cp toglacier.yml $CONF_PATH/toglacier.yml.sample || exit_error "Error copying configuration sample" | ||
|
||
program_path=$project_path/src/github.com/rafaeljusto/toglacier/cmd/toglacier-storage | ||
cd $program_path || exit_error "Cannot change directory" | ||
env GOOS=linux GOARCH=amd64 go build -ldflags "-X github.com/rafaeljusto/toglacier/internal/config.Version=$VERSION" || exit_error "Compile error" | ||
mv toglacier-storage $BIN_PATH || exit_error "Error copying binary" | ||
|
||
cd $current_path | ||
} | ||
|
||
build_deb() { | ||
local project_path=`echo $GOPATH | cut -d: -f1` | ||
project_path=$project_path/src/github.com/rafaeljusto/toglacier | ||
|
||
local version=`echo "$VERSION" | awk -F "-" '{ print $1 }'` | ||
local release=`echo "$VERSION" | awk -F "-" '{ print $2 }'` | ||
|
||
fpm -s dir -t deb --after-install $project_path/deploy/deb/toglacier.postinst \ | ||
--after-upgrade $project_path/deploy/deb/toglacier.postinst \ | ||
-n $PACKAGE_NAME -v "$version" --iteration "$release" --vendor "$VENDOR" \ | ||
--maintainer "$MAINTAINER" --url $URL --license "$LICENSE" --description "$DESCRIPTION" \ | ||
--deb-upstart $project_path/deploy/deb/toglacier.upstart \ | ||
--deb-systemd $project_path/deploy/deb/toglacier.service \ | ||
--deb-user root --deb-group root \ | ||
--prefix / -C $TMP_PATH usr/local/bin etc | ||
} | ||
|
||
cleanup() { | ||
rm -rf $TMP_PATH | ||
} | ||
|
||
VERSION=$1 | ||
|
||
usage() { | ||
echo "Usage: $1 <version>" | ||
} | ||
|
||
if [ -z "$VERSION" ]; then | ||
echo "Undefined VERSION!" | ||
usage $0 | ||
exit 1 | ||
fi | ||
|
||
prepare | ||
compile | ||
build_deb | ||
cleanup |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/bin/sh | ||
set -e | ||
|
||
user=toglacier | ||
group=toglacier | ||
|
||
# make sure the user exists | ||
if ! getent passwd $user > /dev/null; then | ||
adduser --system --quiet --no-create-home --shell /bin/bash \ | ||
--group --gecos "toglacier tool" $user | ||
fi | ||
|
||
# if the user was created manually, make sure the group is there as well | ||
if ! getent group $user > /dev/null; then | ||
addgroup --system --quiet $user | ||
fi | ||
|
||
# make sure the created user is in the created group | ||
if ! id -Gn $user | grep -qw $group; then | ||
adduser --quiet $user $group | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[Unit] | ||
Description=toglacier - Periodic send backups to the cloud | ||
Requires=network.target | ||
After=network.target | ||
|
||
[Service] | ||
Type=simple | ||
ExecStart=/usr/local/bin/toglacier -c /etc/toglacier.yml start | ||
Restart=on-failure | ||
RestartSec=10 | ||
StartLimitInterval=10m | ||
StartLimitBurst=5 | ||
User=toglacier | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Upstart job configuration file | ||
|
||
description "toglacier - Periodic send backups to the cloud" | ||
author "Rafael Dantas Justo" | ||
|
||
start on filesystem and (started networking) | ||
|
||
respawn | ||
respawn limit 3 10 | ||
|
||
exec start-stop-daemon \ | ||
--start \ | ||
-c toglacier \ | ||
--exec /usr/local/bin/toglacier \ | ||
-- -c /etc/toglacier.yml start |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/sh | ||
|
||
# PROVIDE: toglacier | ||
# REQUIRE: DAEMON ntpd | ||
# KEYWORD: shutdown | ||
|
||
. /etc/rc.subr | ||
|
||
name="toglacier" | ||
rcvar=`set_rcvar` | ||
command="/usr/local/bin/toglacier -c /etc/toglacier.yml start" | ||
pidfile="/var/run/toglacier.pid" | ||
|
||
: ${toglacier_enable:=no} | ||
|
||
load_rc_config $name | ||
run_rc_command "$1" |