Files
mistralrs-package/script/setup/nginx.sh
2026-04-24 09:10:36 +03:00

49 lines
2.0 KiB
Bash
Executable File

#!/usr/bin/env bash
script_dir="$(dirname "$0")"
nginx_conf_local_path="${script_dir}/../../asset/nginx/rpm.lair.cafe.conf"
nginx_conf_remote_path="/etc/nginx/sites-available/rpm.lair.cafe.conf"
nginx_host=oolon
if [ ! -s ~/.ssh/id_gitea_ci.pub ]; then
echo "gitea_ci ssh key not found in ~/.ssh/id_gitea_ci.pub"
exit 1
fi
gitea_ssh_key=$(cat ~/.ssh/id_gitea_ci.pub)
if rsync \
--archive \
--compress \
--verbose \
${nginx_conf_local_path} \
${nginx_host}:${nginx_conf_remote_path}; then
echo "sync'd ${nginx_conf_local_path} to ${nginx_host}:${nginx_conf_remote_path}"
else
echo "failed to sync ${nginx_conf_local_path} to ${nginx_host}:${nginx_conf_remote_path}"
exit 1
fi
if ssh ${nginx_host} "id gitea_ci &> /dev/null || sudo useradd --system --create-home --home-dir /var/lib/gitea_ci gitea_ci"; then
echo "gitea_ci user created or observed on ${nginx_host}"
if ssh ${nginx_host} "sudo --user gitea_ci install --directory --mode 0700 /var/lib/gitea_ci/.ssh && echo '${gitea_ssh_key}' | sudo --user gitea_ci install --mode 0600 /dev/stdin /var/lib/gitea_ci/.ssh/authorized_keys"; then
echo "gitea_ci ssh key installed on ${nginx_host}"
else
echo "failed to install gitea_ci ssh key on ${nginx_host}"
exit 1
fi
else
echo "failed to create or observe gitea_ci user on ${nginx_host}"
exit 1
fi
if ssh ${nginx_host} "sudo install --directory /var/www/rpm && sudo setfacl -R -m u:gitea_ci:rwx /var/www/rpm/ && sudo chcon -Rt httpd_sys_content_t /var/www/rpm/"; then
echo "rpm repo directory created and permissions set on ${nginx_host}"
else
echo "failed to create rpm repo directory on ${nginx_host}"
exit 1
fi
if ssh ${nginx_host} "sudo ln -sf ${nginx_conf_remote_path} ${nginx_conf_remote_path/available/enabled} && sudo nginx -t ${nginx_conf_remote_path} && sudo systemctl reload nginx"; then
echo "nginx config reload on ${nginx_host} successful"
else
echo "nginx config reload on ${nginx_host} failed"
exit 1
fi