commit 5783d0ad370837d48c04de3e1f26686de6c078ea Author: alex Date: Fri Sep 30 23:58:33 2022 +0200 initial import diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..9af084e --- /dev/null +++ b/LICENSE @@ -0,0 +1,9 @@ +The MIT License (MIT) + +Copyright (c) 2022 alex@cloudware.io + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..010119b --- /dev/null +++ b/README.md @@ -0,0 +1,25 @@ +# system updates + +the plan is for this repo to contain all system updates, incremental in a form +of text/source code. a node periodically runs the `update.sh` script which pulls +the repo to receive updates executes `apply.sh`. the latter then makes changes +and updates the operating system. + +typical examples are: upgrade bitcoind, lnd and other services, update system +packages, improve configuration of components such as firewall. +the run sequence on the node is approximately as follows: + +1. fetch updates with a `git fetch`. +2. provide a git diff on the screen and confirm with the user. +3. pull in the changes with a `git pull --verify-signatures`. +4. run `apply.sh`. + +at the moment, an on-screen diff and confirmation aren't implemented yet. +`nd` and `ngui` is where it'll happen, +in the [ndg](https://git.qcode.ch/nakamochi/ndg) repo. + +when configuring a new node, clone this repo and set up a cron job to execute +the `update.sh` script once a day. The script requires `REPODIR` and `LOGFILE` +env variables set. + +TODO: add a list of supported platforms; the "native" is void linux. diff --git a/apply.sh b/apply.sh new file mode 100755 index 0000000..2f40dd2 --- /dev/null +++ b/apply.sh @@ -0,0 +1,6 @@ +#!/bin/sh +# the script executes updates to a nakamochi system. +# it must be run as root or a user with equivalent privileges. + +# nothing yet +exit 0 diff --git a/keys/x1ddos-540189B756BF5B12.asc b/keys/x1ddos-540189B756BF5B12.asc new file mode 100644 index 0000000..55514be --- /dev/null +++ b/keys/x1ddos-540189B756BF5B12.asc @@ -0,0 +1,50 @@ +-----BEGIN PGP PUBLIC KEY BLOCK----- + +mQINBFaShgcBEADkx5VXVGnX92AVnc13GGbVY7yNktVyOSJOOXw6QLhd7ZgwZWB3 +r5/J0CBlrOHMRLyLaF+R7qjq7F6VKuP9g+MALh1/tRnY8A8OxVSiouZ7L8258mEe +ishYvPB5AN8rdIx0GR83G760jVIxsHkPiVupzoR+UT8dREzUhdNTsLdQ7FjUIlSe +uF00Kp9ddCx6S8km0zqW8q2kQB/SIkxwUx54K0jIe7a39ET4nScWLGi26ASdmiFS ++cTE6HlrMxWN/36xJnwuS4nAYsazxxZwDua55kgl/Tso6OfblqYuAexOifttr0kd +vheu7gjzIsP1wM89sw2iOEIcBzDKCf5yYsEClOIQc/nm7zdTK2uZy6/Ei+2iH7il +SvKtDAiyKD6T+LdekerPB2i0RkZC+/hbaVvX/4zIDvzntb8KO/yJIPgRRSK5IwA8 +kK1WhbueUxllQvL2HOOzMlIT9qxemScpwtd5Z/5bnWXDy5q4pkNHCFvhEb5PE7TN +ZFDoENuFSYhNNKGmhpDnAjSEf5g/UNVxp8C/MsbcKJCxg/DUGxEc2Wrb1w7L92fT +z1E1ifiCEr5X4J4s6SVgYi8034431nhojSgAa9EgX4Q7QECP7nOJiew5v6WZKYYU +B70zXlPOhK8gwmTOG2fOnmBK8R1LzAGIEC3Rh3K4pm9N2V0Bxbuwi0HAgQARAQAB +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UVSA3vPWZb5U6j50bkYwiIgdg861WLbb8ZZg3H2SEzk25S4cbgM2LvLN +HJDvz+aRs1+BWHbyptsWKRELhj3/vJwrabzPUbUQigaB/pjmC4Yz8WG3+poD +=M/Xo +-----END PGP PUBLIC KEY BLOCK----- diff --git a/update.sh b/update.sh new file mode 100755 index 0000000..5634d1b --- /dev/null +++ b/update.sh @@ -0,0 +1,53 @@ +#!/bin/sh +# https://git.qcode.ch/nakamochi/sysupdates +# pull changes from a remote git repo and run the "apply" script. +# commits are expected to be signed by gpg keys with a sufficient +# trust level to satisfy git pull --verify-signatures. +# the script is expected to be run as root, to allow making changes to the +# operating system. +# in the future, the plan is to provide an on-screen git diff and apply updates +# after user confirmation. + +# git branch to pull from. defaults to master. +BRANCH="${1:-master}" +# output everything to a temp file and print its contents only in case of an error, +# so that when run via a cronjob, the output is empty on success which prevents +# needless emails, were any configured. +LOGFILE="${LOGFILE:-/var/log/sysupdate.log}" +# a local git repo dir where to pull the updates into. +REPODIR="${REPODIR:-/ssd/sysupdates}" + +# multiple running instances of the script would certainly result in race conditions. +# so, we serialize runs using a lock file, timing out with an error after 15min. +if [ -z "$NAKAMOCHI_SYSUPDATE_LOCK" ]; then + # use the script itself as the lock file + lockfile=$0 + exec env NAKAMOCHI_SYSUPDATE_LOCK=1 \ + flock --exclusive --timeout 900 "$lockfile" "$0" "$@" +fi + +# start of the sysupdate; trim prevously logged runs +date > $LOGFILE + +# fetch updates from remove +cd "$REPO_DIR" +{ +git fetch origin # in case the refspec is unknown locally yet +git reset --hard HEAD # remove local changes +git clean -fd # force-delete untracked files +git checkout "$BRANCH" +git pull --verify-signatures +} >> $LOGFILE 2>&1 +if [ $? -ne 0 ]; then + echo "ERROR: git pull failed" + cat $LOGFILE + exit 1 +fi + +# run repo's update script +./apply.sh >> $LOGFILE 2>&1 +if [ $? -ne 0 ]; then + echo "ERROR: apply failed" + cat $LOGFILE + exit 1 +fi