51 lines
2.1 KiB
Bash
Executable File
51 lines
2.1 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 \
|
|
--rsync-path 'sudo rsync' \
|
|
--chown root:root \
|
|
${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 install --directory --owner gitea_ci --group gitea_ci --mode 0700 /var/lib/gitea_ci/.ssh && echo '${gitea_ssh_key}' | sudo sh -c 'install --owner gitea_ci --group gitea_ci --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 --mode 0755 /var/www/rpm/fedora/43/x86_64 && 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 && 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
|