Skip to content

Commit 6b334ee

Browse files
committed
testing
1 parent 8e167ba commit 6b334ee

File tree

4 files changed

+200
-156
lines changed

4 files changed

+200
-156
lines changed

github-runner/node-runner.sh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
printf """
44
-----------------------------------
5-
Welcome to Bootstrap script!
6-
Please answer few questions
5+
▶️ Running Node runner setup script
6+
-----------------------------------
77
88
"""
99

@@ -49,6 +49,8 @@ while [[ $# -gt 0 ]]; do
4949
--labels) LABELS="$2"; shift 2 ;;
5050
--dir) RUNNER_DIR="$2"; shift 2 ;;
5151
--env) ENV="$2"; shift 2 ;;
52+
--runas-user) RUNAS_USER="$2"; shift 2 ;;
53+
--runas-group) RUNAS_GROUP="$2"; shift 2 ;;
5254
-h|--help) usage ;;
5355
*) echo "Unknown option: $1"; usage ;;
5456
esac
@@ -65,6 +67,10 @@ done
6567
# --- Add runner labels ---
6668
LABELS="self-hosted,linux,node,${ENV}"
6769

70+
# --- DETERMINE USER/GROUP TO RUN AS ---
71+
RUNAS_USER="${RUNAS_USER:-provision}"
72+
RUNAS_GROUP="${RUNAS_GROUP:-application}"
73+
6874
# --- DETERMINE REGISTRATION URL ---
6975
if [[ "$SCOPE" == "org" ]]; then
7076
REG_URL="https://api.github.com/orgs/${GITHUB_OWNER}/actions/runners/registration-token"
@@ -84,7 +90,7 @@ sudo apt-get install -y curl jq tar ansible
8490

8591
# --- CREATE RUNNER DIR ---
8692
sudo mkdir -p "${RUNNER_DIR}"
87-
sudo chown $(id -u):$(id -g) "${RUNNER_DIR}"
93+
sudo chown $RUNAS_USER:$RUNAS_GROUP "${RUNNER_DIR}"
8894
cd "${RUNNER_DIR}"
8995

9096
# --- DOWNLOAD RUNNER ---
@@ -119,7 +125,7 @@ REG_TOKEN=$(curl -s -X POST \
119125

120126
# --- CONFIGURE RUNNER ---
121127
echo "[+] Configuring runner..."
122-
./config.sh \
128+
sudo -u $RUNAS_USER ./config.sh \
123129
--unattended \
124130
--url "${RUNNER_SCOPE}" \
125131
--token "${REG_TOKEN}" \

opencrvs-bootstrap.sh

Lines changed: 0 additions & 152 deletions
This file was deleted.
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
#!/bin/bash
2+
printf """
3+
-----------------------------------
4+
▶️ Running User/Group setup script
5+
-----------------------------------
6+
7+
"""
8+
9+
# --- USAGE ---
10+
usage() {
11+
echo "Usage: $0 [OPTIONS]"
12+
echo ""
13+
echo "Options:"
14+
echo " --ssh-public-key ssh public key to add to the user"
15+
echo " -h, --help Show this help message"
16+
echo ""
17+
exit 1
18+
}
19+
20+
set -e
21+
22+
GROUP_ID=1000
23+
GROUP_NAME="application"
24+
USER_ID=1000
25+
USER_NAME="provision"
26+
27+
log() {
28+
echo -e "\n$1\n"
29+
}
30+
31+
while [[ $# -gt 0 ]]; do
32+
case "$1" in
33+
--ssh-public-key) SSH_PUBLIC_KEY="$2"; shift 2 ;;
34+
-h|--help) usage ;;
35+
*) echo "Unknown option: $1"; usage ;;
36+
esac
37+
done
38+
39+
# --- Group checks and creation ---
40+
group_info=$(getent group "$GROUP_ID")
41+
group_by_name=$(getent group "$GROUP_NAME")
42+
43+
if [[ -n "$group_info" ]]; then
44+
actual_group=$(echo "$group_info" | cut -d: -f1)
45+
if [[ "$actual_group" == "$GROUP_NAME" ]]; then
46+
log "✅ Group with GID $GROUP_ID and name $GROUP_NAME exists."
47+
else
48+
log "❌ FAIL: GID $GROUP_ID exists as group '$actual_group', not '$GROUP_NAME'."
49+
exit 1
50+
fi
51+
elif [[ -n "$group_by_name" ]]; then
52+
log "❌ FAIL: Group name '$GROUP_NAME' exists, but with different GID."
53+
exit 1
54+
else
55+
log "🚀 Creating group: $GROUP_NAME with GID: $GROUP_ID"
56+
sudo groupadd -g $GROUP_ID $GROUP_NAME
57+
fi
58+
59+
# --- User checks and creation ---
60+
user_info=$(getent passwd "$USER_ID")
61+
user_by_name=$(getent passwd "$USER_NAME")
62+
63+
if [[ -n "$user_info" ]]; then
64+
actual_user=$(echo "$user_info" | cut -d: -f1)
65+
if [[ "$actual_user" == "$USER_NAME" ]]; then
66+
log "✅ User with UID $USER_ID and name $USER_NAME exists."
67+
else
68+
log "❌ FAIL: UID $USER_ID exists as user '$actual_user', not '$USER_NAME'."
69+
exit 1
70+
fi
71+
elif [[ -n "$user_by_name" ]]; then
72+
log "❌ FAIL: User name '$USER_NAME' exists, but with different UID."
73+
exit 1
74+
else
75+
log "🚀 Creating user: $USER_NAME with UID: $USER_ID and group: $GROUP_NAME"
76+
sudo useradd -u $USER_ID -g $GROUP_NAME $USER_NAME
77+
fi
78+
79+
# --- Sudo access checks and grant ---
80+
# Check in /etc/sudoers and /etc/sudoers.d/
81+
sudo_access=$(sudo grep -E '^provision\s+ALL=\(ALL(:ALL)?\)\s+ALL' /etc/sudoers 2>/dev/null || true)
82+
if [[ -z "$sudo_access" ]]; then
83+
sudo_access=$(sudo grep -E '^provision\s+ALL=\(ALL(:ALL)?\)\s+ALL' /etc/sudoers.d/* 2>/dev/null || true)
84+
fi
85+
86+
if [[ -n "$sudo_access" ]]; then
87+
log "✅ User '$USER_NAME' already has full sudo access."
88+
else
89+
log "🚀 Granting full sudo access to user '$USER_NAME'..."
90+
log "${USER_NAME} ALL=(ALL:ALL) ALL" | sudo tee /etc/sudoers.d/$USER_NAME > /dev/null
91+
sudo chmod 0440 /etc/sudoers.d/$USER_NAME
92+
fi
93+
94+
if [[ -f /home/$USER_NAME/.ssh/id_ed25519 ]]; then
95+
log "✅ SSH key pair for user '$USER_NAME' already exists."
96+
else
97+
sudo -u $USER_NAME mkdir -p /home/$USER_NAME/.ssh
98+
sudo chmod 700 /home/$USER_NAME/.ssh
99+
if [[ -n "$SSH_PUBLIC_KEY" ]]; then
100+
log "🚀 Adding provided SSH public key to user '$USER_NAME'..."
101+
echo "$SSH_PUBLIC_KEY" | sudo -u $USER_NAME tee -a /home/$USER_NAME/.ssh/authorized_keys > /dev/null
102+
sudo chmod 600 /home/$USER_NAME/.ssh/authorized_keys
103+
else
104+
log "🚀 Generating SSH key pair for user '$USER_NAME'..."
105+
sudo -u $USER_NAME mkdir -p /home/$USER_NAME/.ssh
106+
sudo -u $USER_NAME ssh-keygen -t ed25519 -f /home/$USER_NAME/.ssh/id_ed25519 -N "" -C "${USER_NAME}@$(hostname)"
107+
fi
108+
fi
109+
log "⚙️ $USER_NAME SSH key pair public key (add on worker nodes if needed):"
110+
sudo cat /home/$USER_NAME/.ssh/id_ed25519.pub
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Configurable params
5+
PROVISION_UID=1000
6+
PROVISION_GID=1000
7+
PROVISION_USER="provision"
8+
PROVISION_GROUP="application"
9+
MIN_UBUNTU_VERSION="24.04"
10+
11+
# --- Helper Functions --- #
12+
abort() { echo "ERROR: $1"; exit 1; }
13+
14+
check_ubuntu_version() {
15+
echo "Checking Ubuntu version..."
16+
UBUNTU_VERSION=$(lsb_release -rs)
17+
if [ "$UBUNTU_VERSION" != "$MIN_UBUNTU_VERSION" ]; then
18+
abort "Ubuntu $MIN_UBUNTU_VERSION is required, found $UBUNTU_VERSION"
19+
fi
20+
echo "Ubuntu version OK."
21+
}
22+
23+
24+
check_internet() {
25+
echo "Testing internet connectivity (ping google.com)..."
26+
if ! ping -c 2 google.com >/dev/null 2>&1; then
27+
abort "Internet connectivity failed (cannot reach google.com)"
28+
fi
29+
echo "Internet connectivity OK."
30+
}
31+
32+
# ---- MAIN ---- #
33+
34+
echo ""
35+
echo "Initial OpenCRVS Node Bootstrap"
36+
echo ""
37+
echo "Select node type:"
38+
PS3="Enter the number of the node type: "
39+
NODE_TYPES=("single-node k8s cluster (dev/qa/staging)" "multi-node k8s cluster master" "multi-node k8s cluster worker" "backup server")
40+
select NODE_TYPE in "${NODE_TYPES[@]}"; do
41+
case $REPLY in
42+
1)
43+
echo "Selected: single-node k8s cluster"
44+
NODE_KIND="single"
45+
break
46+
;;
47+
2)
48+
echo "Selected: multi-node k8s cluster master"
49+
NODE_KIND="master"
50+
break
51+
;;
52+
3)
53+
echo "Selected: multi-node k8s cluster worker"
54+
NODE_KIND="worker"
55+
break
56+
;;
57+
4)
58+
echo "Selected: backup server"
59+
NODE_KIND="backup"
60+
break
61+
;;
62+
*)
63+
echo "Invalid selection."
64+
;;
65+
esac
66+
done
67+
68+
echo "Running basic checks..."
69+
check_ubuntu_version
70+
check_disk_space
71+
check_internet
72+
73+
if [ "$NODE_KIND" = "single" ] || [ "$NODE_KIND" = "master" ]; then
74+
echo "Provision user setup complete. Save the private key above for GitHub Actions."
75+
elif [ "$NODE_KIND" = "worker" ] || [ "$NODE_KIND" = "backup" ]; then
76+
echo "Worker provision user ready."
77+
fi
78+
79+
echo ""
80+
echo "Node bootstrap complete for $NODE_TYPE."

0 commit comments

Comments
 (0)