Skip to content

Commit 21374ea

Browse files
Merge pull request #7 from OS2borgerPC/5-hent-url-til-admin-site-fra-nettetlokal-fil-når-en-ny-borger-pc-installeres
5 hent url til admin site fra nettetlokal fil når en ny borger pc installeres
2 parents 74eb01d + 728c401 commit 21374ea

File tree

1 file changed

+51
-12
lines changed

1 file changed

+51
-12
lines changed

bin/register_new_os2borgerpc_client.sh

Lines changed: 51 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -93,20 +93,60 @@ while true; do
9393

9494
echo ""
9595

96-
97-
# - admin_url
9896
unset ADMIN_URL
99-
if [[ -z "$ADMIN_URL" ]]
97+
98+
# Clone the git repository
99+
if ! command -v git &> /dev/null
100100
then
101-
ADMIN_URL="https://os2borgerpc-admin.magenta.dk"
102-
echo "Press <ENTER> to register with the following admin portal: $ADMIN_URL."
103-
echo "Alternatively, type in your URL to another instance of the admin portal here:"
104-
read -r NEW_ADMIN_URL
105-
if [[ -n "$NEW_ADMIN_URL" ]]
106-
then
107-
ADMIN_URL="$NEW_ADMIN_URL"
101+
apt install -qq git -y
102+
fi
103+
104+
if [ ! -d "repo_tmp" ]; then
105+
REPO_URL="https://github.com/OS2borgerPC/os2borgerpc-admin-site-urls.git"
106+
GIT_ASKPASS=true git clone --depth 1 "$REPO_URL" repo_tmp
107+
fi
108+
109+
# Read key/value pairs from AdminSiteUrls.yaml
110+
if [[ ! -f "repo_tmp/AdminSiteUrls.yaml" ]]; then
111+
echo "Error: AdminSiteUrls.yaml not found after trying to download it."
112+
read -rp "Type URL for admin site: " ADMIN_URL
113+
else
114+
# Parse the YAML file and present the options to the user
115+
OPTIONS=()
116+
while IFS= read -r line; do
117+
if [[ $line =~ ^([a-zA-Z0-9_-]+):[[:space:]]*(https?://[^[:space:]]+)$ ]]; then
118+
NAME="${BASH_REMATCH[1]}"
119+
URL="${BASH_REMATCH[2]}"
120+
OPTIONS+=("$NAME|$URL")
108121
fi
122+
done < repo_tmp/AdminSiteUrls.yaml
123+
124+
# Present URLs to the user
125+
if [[ ${#OPTIONS[@]} -eq 0 ]]; then
126+
echo "Error: No valid URLs found in AdminSiteUrls.yaml."
127+
read -rp "Type URL for admin site: " ADMIN_URL
128+
else
129+
echo ""
130+
echo "Found admin site URLs:"
131+
for i in "${!OPTIONS[@]}"; do
132+
NAME="${OPTIONS[$i]%%|*}"
133+
URL="${OPTIONS[$i]#*|}"
134+
echo "$((i+1)). $NAME: $URL"
135+
done
136+
137+
# Get user's choice
138+
read -rp "Enter the number of the admin site you want to use, or type a URL to be used instead: " CHOICE
139+
if [[ "$CHOICE" =~ ^[0-9]+$ ]] && (( CHOICE > 0 && CHOICE <= ${#OPTIONS[@]} )); then
140+
ADMIN_URL="${OPTIONS[$((CHOICE-1))]#*|}"
141+
else
142+
$ADMIN_URL="$CHOICE"
143+
fi
144+
fi
109145
fi
146+
# Clean up temporary repository
147+
rm -rf repo_tmp || true # do nothing if 'rm' fails
148+
149+
110150
set_os2borgerpc_config admin_url "$ADMIN_URL"
111151

112152
# - set additional config values
@@ -146,6 +186,5 @@ while true; do
146186
# Randomize cron job to avoid everybody hitting the server the same minute
147187
"$DIR/randomize_jobmanager.sh" 5 > /dev/null
148188
fi
149-
150189
break
151-
done
190+
done

0 commit comments

Comments
 (0)