parent
241fcde39a
commit
71b168efdf
@ -0,0 +1,4 @@ |
|||||||
|
/etc/harmony/harmony.conf |
||||||
|
/etc/harmony/rclone.conf |
||||||
|
/etc/sysctl.d/99-harmony.conf |
||||||
|
/etc/systemd/system/harmony.service |
@ -0,0 +1,13 @@ |
|||||||
|
{{VER=2.0.0}} |
||||||
|
Package: harmony |
||||||
|
Version: {{ VER }} |
||||||
|
License: MIT |
||||||
|
Vendor: Harmony blockchain |
||||||
|
Architecture: amd64 |
||||||
|
Source: https://github.com/harmony-one/harmony |
||||||
|
Maintainer: Leo Chen <leo@harmony.one> |
||||||
|
Section: net |
||||||
|
Priority: extra |
||||||
|
Homepage: https://harmony.one |
||||||
|
Description: Harmony is a sharded, fast finality, low fee, PoS public blockchain. This package contains the validator node program for harmony blockchain. |
||||||
|
Build-Dep: dh-systemd |
@ -0,0 +1 @@ |
|||||||
|
2.0 |
@ -0,0 +1,40 @@ |
|||||||
|
#!/bin/sh |
||||||
|
|
||||||
|
set -e |
||||||
|
|
||||||
|
after_install() { |
||||||
|
: |
||||||
|
} |
||||||
|
|
||||||
|
after_upgrade() { |
||||||
|
: |
||||||
|
# systemctl restart harmony |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
# Setup system users and groups |
||||||
|
addgroup --quiet --system harmony |
||||||
|
adduser --quiet --system --ingroup harmony --gecos "harmony validator account" harmony |
||||||
|
|
||||||
|
if [ "${1}" = "configure" -a -z "${2}" ] || \ |
||||||
|
[ "${1}" = "abort-remove" ] |
||||||
|
then |
||||||
|
# "after install" here |
||||||
|
# "abort-remove" happens when the pre-removal script failed. |
||||||
|
# In that case, this script, which should be idemptoent, is run |
||||||
|
# to ensure a clean roll-back of the removal. |
||||||
|
after_install |
||||||
|
elif [ "${1}" = "configure" -a -n "${2}" ] |
||||||
|
then |
||||||
|
upgradeFromVersion="${2}" |
||||||
|
# "after upgrade" here |
||||||
|
# NOTE: This slot is also used when deb packages are removed, |
||||||
|
# but their config files aren't, but a newer version of the |
||||||
|
# package is installed later, called "Config-Files" state. |
||||||
|
# basically, that still looks a _lot_ like an upgrade to me. |
||||||
|
after_upgrade "${2}" |
||||||
|
elif echo "${1}" | grep -E -q "(abort|fail)" |
||||||
|
then |
||||||
|
echo "Failed to install before the post-installation script was run." >&2 |
||||||
|
exit 1 |
||||||
|
fi |
@ -0,0 +1,44 @@ |
|||||||
|
#!/bin/sh |
||||||
|
after_remove() { |
||||||
|
: |
||||||
|
#rm -rf /data/harmony/latest |
||||||
|
#rm -rf /data/harmony/.dht* |
||||||
|
#rm -rf /data/harmony/transactions.rlp |
||||||
|
} |
||||||
|
|
||||||
|
after_purge() { |
||||||
|
: |
||||||
|
} |
||||||
|
|
||||||
|
dummy() { |
||||||
|
: |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
if [ "${1}" = "remove" -o "${1}" = "abort-install" ] |
||||||
|
then |
||||||
|
# "after remove" goes here |
||||||
|
# "abort-install" happens when the pre-installation script failed. |
||||||
|
# In that case, this script, which should be idemptoent, is run |
||||||
|
# to ensure a clean roll-back of the installation. |
||||||
|
after_remove |
||||||
|
elif [ "${1}" = "purge" -a -z "${2}" ] |
||||||
|
then |
||||||
|
# like "on remove", but executes after dpkg deletes config files |
||||||
|
# 'apt-get purge' runs 'on remove' section, then this section. |
||||||
|
# There is no equivalent in RPM or ARCH. |
||||||
|
after_purge |
||||||
|
elif [ "${1}" = "upgrade" ] |
||||||
|
then |
||||||
|
# This represents the case where the old package's postrm is called after |
||||||
|
# the 'preinst' script is called. |
||||||
|
# We should ignore this and just use 'preinst upgrade' and |
||||||
|
# 'postinst configure'. The newly installed package should do the |
||||||
|
# upgrade, not the uninstalled one, since it can't anticipate what new |
||||||
|
# things it will have to do to upgrade for the new version. |
||||||
|
dummy |
||||||
|
elif echo "${1}" | grep -E -q '(fail|abort)' |
||||||
|
then |
||||||
|
echo "Failed to install before the post-removal script was run." >&2 |
||||||
|
exit 1 |
||||||
|
fi |
@ -0,0 +1,32 @@ |
|||||||
|
#!/bin/sh |
||||||
|
|
||||||
|
set -e |
||||||
|
|
||||||
|
before_install() { |
||||||
|
: |
||||||
|
} |
||||||
|
|
||||||
|
before_upgrade() { |
||||||
|
: |
||||||
|
} |
||||||
|
|
||||||
|
if [ "${1}" = "install" -a -z "${2}" ] |
||||||
|
then |
||||||
|
before_install |
||||||
|
elif [ "${1}" = "upgrade" -a -n "${2}" ] |
||||||
|
then |
||||||
|
upgradeFromVersion="${2}" |
||||||
|
before_upgrade "${upgradeFromVersion}" |
||||||
|
elif [ "${1}" = "install" -a -n "${2}" ] |
||||||
|
then |
||||||
|
upgradeFromVersion="${2}" |
||||||
|
# Executed when a package is removed but its config files aren't, |
||||||
|
# and a new version is installed. |
||||||
|
# Looks a _lot_ like an upgrade case, I say we just execute the |
||||||
|
# same "before upgrade" script as in the previous case |
||||||
|
before_upgrade "${upgradeFromVersion}" |
||||||
|
elif echo "${1}" | grep -E -q '(fail|abort)' |
||||||
|
then |
||||||
|
echo "Failed to install before the pre-installation script was run." >&2 |
||||||
|
exit 1 |
||||||
|
fi |
@ -0,0 +1,29 @@ |
|||||||
|
#!/bin/sh |
||||||
|
|
||||||
|
set -e |
||||||
|
|
||||||
|
before_remove() { |
||||||
|
: |
||||||
|
} |
||||||
|
|
||||||
|
dummy() { |
||||||
|
: |
||||||
|
} |
||||||
|
|
||||||
|
if [ "${1}" = "remove" -a -z "${2}" ] |
||||||
|
then |
||||||
|
# "before remove" goes here |
||||||
|
before_remove |
||||||
|
elif [ "${1}" = "upgrade" ] |
||||||
|
then |
||||||
|
# Executed before the old version is removed |
||||||
|
# upon upgrade. |
||||||
|
# We should generally not do anything here. The newly installed package |
||||||
|
# should do the upgrade, not the uninstalled one, since it can't anticipate |
||||||
|
# what new things it will have to do to upgrade for the new version. |
||||||
|
dummy |
||||||
|
elif echo "${1}" | grep -E -q "(fail|abort)" |
||||||
|
then |
||||||
|
echo "Failed to install before the pre-removal script was run." >&2 |
||||||
|
exit 1 |
||||||
|
fi |
@ -0,0 +1,30 @@ |
|||||||
|
#!/bin/bash |
||||||
|
|
||||||
|
if [ $# != 1 ]; then |
||||||
|
echo "$0 version" |
||||||
|
exit |
||||||
|
fi |
||||||
|
|
||||||
|
VERSION=$1 |
||||||
|
|
||||||
|
fpm -s dir -t deb -n harmony -p harmony_VERSION_ARCH.deb -C harmony-${VERSION} \ |
||||||
|
-v "$VERSION" \ |
||||||
|
--license "MIT" \ |
||||||
|
--vendor "Harmony Blockchain" \ |
||||||
|
--category "net" \ |
||||||
|
--no-depends \ |
||||||
|
--no-auto-depends \ |
||||||
|
--directories /etc/harmony \ |
||||||
|
--directories /data/harmony \ |
||||||
|
--architecture x86_64 \ |
||||||
|
--maintainer "Leo Chen <leo@harmony.one>" \ |
||||||
|
--description "Harmony is a sharded, fast finality, low fee, PoS public blockchain.\nThis package contains the validator node program for harmony blockchain." \ |
||||||
|
--url "https://harmony.one" \ |
||||||
|
--before-install scripts/preinst \ |
||||||
|
--after-install scripts/postinst \ |
||||||
|
--before-remove scripts/prerm \ |
||||||
|
--after-remove scripts/postrm \ |
||||||
|
--before-upgrade scripts/preup \ |
||||||
|
--after-upgrade scripts/postup \ |
||||||
|
--deb-changelog scripts/changelog \ |
||||||
|
--deb-systemd-restart-after-upgrade |
@ -0,0 +1 @@ |
|||||||
|
1.0 init harmony debian package |
@ -0,0 +1,94 @@ |
|||||||
|
#!/usr/bin/env bash |
||||||
|
# Replaces all {{VAR}} by the $VAR value in a template file and outputs it |
||||||
|
# Use with -h to output all variables |
||||||
|
# curtesy of https://github.com/lavoiesl/bash-templater/blob/master/templater.sh |
||||||
|
|
||||||
|
if [[ ! -f "$1" ]]; then |
||||||
|
echo "Usage: VAR=value $0 template" >&2 |
||||||
|
exit 1 |
||||||
|
fi |
||||||
|
|
||||||
|
template="$1" |
||||||
|
vars=$(grep -oE '\{\{\s*[A-Za-z0-9_]+\s*\}\}' "$template" | sort | uniq | sed -e 's/^{{//' -e 's/}}$//') |
||||||
|
|
||||||
|
if [[ -z "$vars" ]]; then |
||||||
|
echo "Warning: No variable was found in $template, syntax is {{VAR}}" >&2 |
||||||
|
fi |
||||||
|
|
||||||
|
var_value() { |
||||||
|
var="${1}" |
||||||
|
eval echo \$"${var}" |
||||||
|
} |
||||||
|
|
||||||
|
## |
||||||
|
# Escape custom characters in a string |
||||||
|
# Example: escape "ab'\c" '\' "'" ===> ab\'\\c |
||||||
|
# |
||||||
|
function escape_chars() { |
||||||
|
local content="${1}" |
||||||
|
shift |
||||||
|
|
||||||
|
for char in "$@"; do |
||||||
|
content="${content//${char}/\\${char}}" |
||||||
|
done |
||||||
|
|
||||||
|
echo "${content}" |
||||||
|
} |
||||||
|
|
||||||
|
function echo_var() { |
||||||
|
local var="${1}" |
||||||
|
local content="${2}" |
||||||
|
local escaped="$(escape_chars "${content}" "\\" '"')" |
||||||
|
|
||||||
|
echo "${var}=\"${escaped}\"" |
||||||
|
} |
||||||
|
|
||||||
|
declare -a replaces |
||||||
|
replaces=() |
||||||
|
|
||||||
|
# Reads default values defined as {{VAR=value}} and delete those lines |
||||||
|
# There are evaluated, so you can do {{PATH=$HOME}} or {{PATH=`pwd`}} |
||||||
|
# You can even reference variables defined in the template before |
||||||
|
defaults=$(grep -oE '^\{\{[A-Za-z0-9_]+=.+\}\}$' "${template}" | sed -e 's/^{{//' -e 's/}}$//') |
||||||
|
IFS=$'\n' |
||||||
|
for default in $defaults; do |
||||||
|
var=$(echo "${default}" | grep -oE "^[A-Za-z0-9_]+") |
||||||
|
current="$(var_value "${var}")" |
||||||
|
|
||||||
|
# Replace only if var is not set |
||||||
|
if [[ -n "$current" ]]; then |
||||||
|
eval "$(echo_var "${var}" "${current}")" |
||||||
|
else |
||||||
|
eval "${default}" |
||||||
|
fi |
||||||
|
|
||||||
|
# remove define line |
||||||
|
replaces+=("-e") |
||||||
|
replaces+=("/^{{${var}=/d") |
||||||
|
vars="${vars} ${var}" |
||||||
|
done |
||||||
|
|
||||||
|
vars="$(echo "${vars}" | tr " " "\n" | sort | uniq)" |
||||||
|
|
||||||
|
if [[ "$2" = "-h" ]]; then |
||||||
|
for var in $vars; do |
||||||
|
value="$(var_value "${var}")" |
||||||
|
echo_var "${var}" "${value}" |
||||||
|
done |
||||||
|
exit 0 |
||||||
|
fi |
||||||
|
|
||||||
|
# Replace all {{VAR}} by $VAR value |
||||||
|
for var in $vars; do |
||||||
|
value="$(var_value "${var}")" |
||||||
|
if [[ -z "$value" ]]; then |
||||||
|
echo "Warning: $var is not defined and no default is set, replacing by empty" >&2 |
||||||
|
fi |
||||||
|
|
||||||
|
# Escape slashes |
||||||
|
value="$(escape_chars "${value}" "\\" '/' ' ')"; |
||||||
|
replaces+=("-e") |
||||||
|
replaces+=("s/{{\s*${var}\s*}}/${value}/g") |
||||||
|
done |
||||||
|
|
||||||
|
sed "${replaces[@]}" "${template}" |
Loading…
Reference in new issue