Skip to content

Commit 728c401

Browse files
committed
Remove mounted values as source for admin site URL
It has been decided that this functionality will not be used by users. Also fix path handling with regard to the "repo_tmp" directory.
1 parent 02353cd commit 728c401

File tree

1 file changed

+42
-60
lines changed

1 file changed

+42
-60
lines changed

bin/register_new_os2borgerpc_client.sh

Lines changed: 42 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -95,75 +95,57 @@ while true; do
9595

9696
unset ADMIN_URL
9797

98-
# Search for AdminSiteUrl.txt in the root of connected volumes
99-
echo "Searching for AdminSiteUrl.txt in /media, /mnt and /Volumes"
100-
for volume in /media/* /mnt/* /Volumes/*; do
101-
filepath=$(find "$volume" -maxdepth 2 -type f -name "AdminSiteUrl.txt" 2>/dev/null)
102-
if [[ -n "$filepath" && -r "$filepath" ]]; then
103-
ADMIN_URL=$(<"$filepath")
104-
echo "AdminSiteUrl.txt found at $filepath containing '$ADMIN_URL'"
105-
echo "Trying to connect to admin site using URL '$ADMIN_URL'."
106-
break
107-
fi
108-
done
109-
110-
# If AdminSiteUrl.txt was not found
111-
if [[ -z "$ADMIN_URL" ]]; then
112-
echo "AdminSiteUrl.txt not found. Getting AdminSiteUrls.yaml from OS2 repo."
113-
# Clone the git repository
114-
if ! command -v git &> /dev/null
115-
then
116-
apt install -qq git -y
117-
fi
118-
119-
if [ ! -d "repo_tmp" ]; then
120-
REPO_URL="https://github.com/OS2borgerPC/os2borgerpc-admin-site-urls.git"
121-
GIT_ASKPASS=true git clone --depth 1 "$REPO_URL" repo_tmp
122-
fi
98+
# Clone the git repository
99+
if ! command -v git &> /dev/null
100+
then
101+
apt install -qq git -y
102+
fi
123103

124-
cd repo_tmp || true # Do nothing if 'cd' fails
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
125108

126-
# Read key/value pairs from AdminSiteUrls.yaml
127-
if [[ ! -f "AdminSiteUrls.yaml" ]]; then
128-
echo "Error: AdminSiteUrls.yaml not found after trying to download it."
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")
121+
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."
129127
read -rp "Type URL for admin site: " ADMIN_URL
130128
else
131-
# Parse the YAML file and present the options to the user
132-
OPTIONS=()
133-
while IFS= read -r line; do
134-
if [[ $line =~ ^([a-zA-Z0-9_-]+):[[:space:]]*(https?://[^[:space:]]+)$ ]]; then
135-
NAME="${BASH_REMATCH[1]}"
136-
URL="${BASH_REMATCH[2]}"
137-
OPTIONS+=("$NAME|$URL")
138-
fi
139-
done < AdminSiteUrls.yaml
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
140136

141-
# Present URLs to the user
142-
if [[ ${#OPTIONS[@]} -eq 0 ]]; then
143-
echo "Error: No valid URLs found in AdminSiteUrls.yaml."
144-
read -rp "Type URL for admin site: " ADMIN_URL
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))]#*|}"
145141
else
146-
echo ""
147-
echo "Found admin site URLs:"
148-
for i in "${!OPTIONS[@]}"; do
149-
NAME="${OPTIONS[$i]%%|*}"
150-
URL="${OPTIONS[$i]#*|}"
151-
echo "$((i+1)). $NAME: $URL"
152-
done
153-
154-
# Get user's choice
155-
read -rp "Enter the number of the admin site you want to use, or type a URL to be used instead: " CHOICE
156-
if [[ "$CHOICE" =~ ^[0-9]+$ ]] && (( CHOICE > 0 && CHOICE <= ${#OPTIONS[@]} )); then
157-
ADMIN_URL="${OPTIONS[$((CHOICE-1))]#*|}"
158-
else
159-
$ADMIN_URL="$CHOICE"
160-
fi
142+
$ADMIN_URL="$CHOICE"
161143
fi
162144
fi
163-
# Clean up temporary repository
164-
rm -rf repo_tmp
165-
cd ..
166145
fi
146+
# Clean up temporary repository
147+
rm -rf repo_tmp || true # do nothing if 'rm' fails
148+
167149

168150
set_os2borgerpc_config admin_url "$ADMIN_URL"
169151

0 commit comments

Comments
 (0)