diff --git a/script/setup/nvm.sh b/script/setup/nvm.sh new file mode 100755 index 0000000..4b8717e --- /dev/null +++ b/script/setup/nvm.sh @@ -0,0 +1,54 @@ +#!/usr/bin/env bash +# Set up nvm and a stable default Node.js for a gitea_runner user on a CI runner. +# +# Usage: ./script/setup/nvm.sh +# +# This script: +# 1. Installs nvm for the gitea_runner user (if not already present) +# 2. Installs the current Node.js LTS version +# 3. Creates a stable symlink at ~/.nvm/default_bin pointing to the +# default node binary directory +# 4. Prints the systemd Environment line needed for the runner unit +# +# After running, add the following to the runner's systemd unit +# (/etc/systemd/system/gitea-action-runner.service): +# +# Environment=PATH=/var/lib/gitea_runner/.nvm/default_bin:/usr/local/sbin:/usr/local/bin:/usr/bin +# +# Then: sudo systemctl daemon-reload && sudo systemctl restart gitea-action-runner + +set -euo pipefail + +runner_host="${1:?usage: $0 }" +runner_user="gitea_runner" + +echo "installing nvm on ${runner_host} for ${runner_user}..." +ssh "${runner_host}" "sudo -u ${runner_user} bash -c ' + export NVM_DIR=\"\${HOME}/.nvm\" + if [ -s \"\${NVM_DIR}/nvm.sh\" ]; then + echo \"nvm already installed at \${NVM_DIR}\" + else + curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash + fi +'" + +echo "installing Node.js LTS and creating stable symlink..." +ssh "${runner_host}" "sudo -u ${runner_user} bash -c ' + export NVM_DIR=\"\${HOME}/.nvm\" + . \"\${NVM_DIR}/nvm.sh\" + nvm install --lts + nvm alias default lts/* + ln -sfn \"\$(dirname \"\$(nvm which default)\")\" \"\${NVM_DIR}/default_bin\" + echo \"node: \$(node --version)\" + echo \"symlink: \$(readlink -f \"\${NVM_DIR}/default_bin\")\" +'" + +echo "" +echo "add the following to /etc/systemd/system/gitea-action-runner.service on ${runner_host}:" +echo "" +echo " Environment=PATH=/var/lib/${runner_user}/.nvm/default_bin:/usr/local/sbin:/usr/local/bin:/usr/bin" +echo "" +echo "then run:" +echo " ssh ${runner_host} 'sudo systemctl daemon-reload && sudo systemctl restart gitea-action-runner'" +echo "" +echo "also add 'nvm' to the runner's labels in /etc/act_runner/config.yml"