From 4bd542fe0751726e8d7b34ed4c81e2fcea989037 Mon Sep 17 00:00:00 2001 From: TEC Date: Sun, 16 Oct 2022 16:19:34 +0800 Subject: [PATCH] Initial test --- Caddyfile | 3 +++ setup.org | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ setup.sh | 26 ++++++++++++++++++++++ 3 files changed, 95 insertions(+) create mode 100644 Caddyfile create mode 100644 setup.org create mode 100755 setup.sh diff --git a/Caddyfile b/Caddyfile new file mode 100644 index 0000000..fb8f13e --- /dev/null +++ b/Caddyfile @@ -0,0 +1,3 @@ +emacssurvey.tecosaur.net + +respond "Hello!" diff --git a/setup.org b/setup.org new file mode 100644 index 0000000..fdfc92e --- /dev/null +++ b/setup.org @@ -0,0 +1,66 @@ +#+title: Setup +#+property: header-args:sh :tangle yes :shebang "#!/usr/bin/env sh" :eval no :comments no + +We could do something fancy like a NixOS flake, but for the EmacsSurvey server I +think a simple Debian machine with a setup script should do the trick. Let's +just work out a setup script to get everything up and running. + +The idea is that this repository can be cloned/updated anywhere on the machine +and =sudo setup.sh= will do the rest. + +* Installing software +** Caddy web server + +#+begin_src sh +if ! rpm -q caddy > /dev/null; then + echo -e "\e[1;34mInstalling Caddy\e[m" + # Taken from + sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https + curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg + curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list + sudo apt update + sudo apt install caddy +fi +#+end_src + +** Julia + +First, we specify the Julia version we want and hope that the relevant paths +continue to be predictable. + +#+begin_src sh +JULIA_VERSION="1.8.2" +#+end_src + +If either the =julia= command does not exist, or =julia --version= does not match +the expected output, then we will install Julia in =/opt/julia= and symlink the +binary into =/usr/bin=. + +#+begin_src sh +if ! command -v julia > /dev/null || [ ! $(julia --version) = "julia version $JULIA_VERSION" ]; then + echo -e "\e[1;34mInstalling Julia\e[m" + pushd /tmp > /dev/null + # Following + wget "https://julialang-s3.julialang.org/bin/linux/x64/${JULIA_VERSION%.*}/julia-$JULIA_VERSION-linux-x86_64.tar.gz" + mkdir -p "/opt/julia/" + tar zxvf "julia-$JULIA_VERSION-linux-x86_64.tar.gz" --directory=/opt/julia + ln -sf "/opt/julia/julia-$JULIA_VERSION/bin/julia" /usr/bin/julia +fi +#+end_src + +* Copying over relevant files + +Before starting to do this, we will obtain the path to the folder of the script, +so we can grab files relative to the root of this repository. + +#+begin_src sh +SETUPDIR=$(dirname "$(readlink --canonicalize-existing "$0")") +#+end_src + +** Caddy Config + +#+begin_src sh +cp -f "$SETUPDIR/Caddyfile" "/etc/caddy/Caddyfile" +#+end_src + +* Ensuring services are running diff --git a/setup.sh b/setup.sh new file mode 100755 index 0000000..277a3c3 --- /dev/null +++ b/setup.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env sh +if ! rpm -q caddy > /dev/null; then + echo -e "\e[1;34mInstalling Caddy\e[m" + # Taken from + sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https + curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg + curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list + sudo apt update + sudo apt install caddy +fi + +JULIA_VERSION="1.8.2" + +if ! command -v julia > /dev/null || [ ! $(julia --version) = "julia version $JULIA_VERSION" ]; then + echo -e "\e[1;34mInstalling Julia\e[m" + pushd /tmp > /dev/null + # Following + wget "https://julialang-s3.julialang.org/bin/linux/x64/${JULIA_VERSION%.*}/julia-$JULIA_VERSION-linux-x86_64.tar.gz" + mkdir -p "/opt/julia/" + tar zxvf "julia-$JULIA_VERSION-linux-x86_64.tar.gz" --directory=/opt/julia + ln -sf "/opt/julia/julia-$JULIA_VERSION/bin/julia" /usr/bin/julia +fi + +SETUPDIR=$(dirname "$(readlink --canonicalize-existing "$0")") + +cp -f "$SETUPDIR/Caddyfile" "/etc/caddy/Caddyfile"