diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 4baebc232..eda89aa62 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -18,3 +18,13 @@ nfpms: formats: - deb - rpm + contents: + - src: release_files/wiretrustee.service + dst: /lib/systemd/system/wiretrustee.service + + - src: release_files/wiretrustee.json + dst: /etc/wiretrustee/wiretrustee.json + type: "config|noreplace" + + scripts: + postinstall: "release_files/post_install.sh" diff --git a/release_files/post_install.sh b/release_files/post_install.sh new file mode 100644 index 000000000..5471a7abc --- /dev/null +++ b/release_files/post_install.sh @@ -0,0 +1,61 @@ +#!/bin/sh + +# Step 1, decide if we should use systemd or init/upstart +use_systemctl="True" +systemd_version=0 +if ! command -V systemctl >/dev/null 2>&1; then + use_systemctl="False" +else + systemd_version=$(systemctl --version | head -1 | sed 's/systemd //g') +fi + +cleanInstall() { + printf "\033[32m Post Install of an clean install\033[0m\n" + # Step 3 (clean install), enable the service in the proper way for this platform + if [ "${use_systemctl}" = "True" ]; then + printf "\033[32m Reload the service unit from disk\033[0m\n" + systemctl daemon-reload ||: + printf "\033[32m Unmask the service\033[0m\n" + systemctl unmask wiretrustee ||: + printf "\033[32m Set the preset flag for the service unit\033[0m\n" + systemctl preset wiretrustee ||: + printf "\033[32m Set the enabled flag for the service unit\033[0m\n" + systemctl enable wiretrustee ||: + systemctl restart wiretrustee ||: + fi +} + +upgrade() { + printf "\033[32m Post Install of an upgrade\033[0m\n" + if [ "${use_systemctl}" = "True" ]; then + printf "\033[32m Reload the service unit from disk\033[0m\n" + systemctl daemon-reload ||: + printf "\033[32m Restarting the service\033[0m\n" + systemctl restart wiretrustee ||: + fi +} + +# Step 2, check if this is a clean install or an upgrade +action="$1" +if [ "$1" = "configure" ] && [ -z "$2" ]; then + # Alpine linux does not pass args, and deb passes $1=configure + action="install" +elif [ "$1" = "configure" ] && [ -n "$2" ]; then + # deb passes $1=configure $2= + action="upgrade" +fi + +case "$action" in + "1" | "install") + cleanInstall + ;; + "2" | "upgrade") + printf "\033[32m Post Install of an upgrade\033[0m\n" + upgrade + ;; + *) + # $1 == version being installed + printf "\033[32m install\033[0m" + cleanInstall + ;; +esac \ No newline at end of file diff --git a/release_files/wiretrustee.json b/release_files/wiretrustee.json new file mode 100644 index 000000000..d64d7ee38 --- /dev/null +++ b/release_files/wiretrustee.json @@ -0,0 +1,30 @@ +{ + "PrivateKey": "", + "Peers": [ + { + "WgPubKey": "", + "WgAllowedIps": "" + } + ], + "StunTurnURLs": [ + { + "Scheme": 1, + "Host": "", + "Port": 3468, + "Username": "", + "Password": "", + "Proto": 1 + }, + { + "Scheme": 3, + "Host": "", + "Port": 3468, + "Username": "", + "Password": "", + "Proto": 1 + } + ], + "SignalAddr": "", + "WgAddr": "", + "WgIface": "" +} diff --git a/release_files/wiretrustee.service b/release_files/wiretrustee.service new file mode 100644 index 000000000..93ed6fdda --- /dev/null +++ b/release_files/wiretrustee.service @@ -0,0 +1,10 @@ +[Unit] +Description=Wiretrustee Service +After=multi-user.target network-online.target +Wants=network-online.target + +[Service] +Type=simple +ExecStart=/usr/local/bin/wiretrustee up --config /etc/wiretrustee/wiretrustee.json --log-level debug +[Install] +WantedBy=multi-user.target \ No newline at end of file