Skip to content

Commit e643434

Browse files
authored
Merge pull request #88 from OS2borgerPC/87-follow-up-error-like-messages-in-build-output-created-by-issue-81
issue #87 - add temporary install of os2borgerpc-client for applying …
2 parents a35d452 + 25d7763 commit e643434

File tree

3 files changed

+74
-58
lines changed

3 files changed

+74
-58
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/usr/bin/env bash
2+
3+
if [ "$(id -u)" != "0" ]; then
4+
echo "Critical error. Halting registration: This program must be run as root"
5+
exit 1
6+
fi
7+
8+
# default fallback os2borgerpc-client if no value is configured.
9+
DEFAULT_OS2BORGERPC_CLIENT=https://github.com/OS2borgerPC/os2borgerpc-client.git
10+
11+
# Install the configured os2borgerpc-client if it's not already installed
12+
if ! pip show os2borgerpc-client > /dev/null 2>&1; then
13+
echo "OS2borgerPC-client is not installed. Installing now..."
14+
15+
# Load values from the config file
16+
CONFIG_FILE="/etc/os2borgerpc/os2borgerpc.conf"
17+
PACKAGE_NAME=$(grep "^os2borgerpc_client_package:" "$CONFIG_FILE" | cut -d':' -f2- | xargs)
18+
19+
if [ -z "$PACKAGE_NAME" ]; then
20+
echo "No client package specified. Defaulting to $DEFAULT_OS2BORGERPC_CLIENT"
21+
PACKAGE_NAME="$DEFAULT_OS2BORGERPC_CLIENT"
22+
fi
23+
24+
# Check if PACKAGE_NAME is a GitHub URL or a PyPI package name
25+
if [[ "$PACKAGE_NAME" == https://github.com/* ]]; then
26+
# Parse GitHub username and repository name
27+
GITHUB_USER=$(echo "$PACKAGE_NAME" | awk -F'/' '{print $(NF-1)}')
28+
REPO_NAME=$(echo "$PACKAGE_NAME" | awk -F'/' '{print $NF}' | sed 's/.git$//')
29+
30+
# Fetch the latest tag from the GitHub API
31+
LATEST_TAG=$(curl -s "https://api.github.com/repos/$GITHUB_USER/$REPO_NAME/tags" | jq -r '.[0].name')
32+
33+
# Check if a tag was found and install from GitHub
34+
if [ -z "$LATEST_TAG" ]; then
35+
echo "No tags found for GitHub repository $GITHUB_USER/$REPO_NAME"
36+
exit 1
37+
else
38+
echo "Latest GitHub tag for $REPO_NAME: $LATEST_TAG"
39+
echo "Installing package from GitHub..."
40+
pip install "git+$PACKAGE_NAME@$LATEST_TAG" > /dev/null
41+
42+
# Set values in config file
43+
set_os2borgerpc_config os2borgerpc_client_package "$PACKAGE_NAME"
44+
fi
45+
else
46+
# Assume PACKAGE_NAME is a PyPI package name and fetch the latest version from PyPI
47+
LATEST_VERSION=$(curl -s "https://pypi.org/pypi/$PACKAGE_NAME/json" | jq -r '.info.version')
48+
echo "https://pypi.org/pypi/$PACKAGE_NAME/json | jq -r '.info.version'"
49+
50+
# Check if a version was found and install from PyPI
51+
if [ -z "$LATEST_VERSION" ]; then
52+
echo "No version found for PyPI package $PACKAGE_NAME"
53+
exit 1
54+
else
55+
echo "Latest PyPI version for $PACKAGE_NAME: $LATEST_VERSION"
56+
echo "Installing package from PyPI..."
57+
pip install "$PACKAGE_NAME==$LATEST_VERSION" > /dev/null
58+
59+
# Set values in config file
60+
set_os2borgerpc_config os2borgerpc_client_package "$PACKAGE_NAME"
61+
fi
62+
fi
63+
fi
64+

image/overwrites/usr/local/bin/update_client_and_register.sh

Lines changed: 3 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -5,63 +5,8 @@ if [ "$(id -u)" != "0" ]; then
55
exit 1
66
fi
77

8-
# default fallback os2borgerpc-client if no value is configured.
9-
DEFAULT_OS2BORGERPC_CLIENT=https://github.com/OS2borgerPC/os2borgerpc-client.git
10-
11-
# Install the configured os2borgerpc-client if it's not already installed
12-
if ! pip show os2borgerpc-client > /dev/null 2>&1; then
13-
echo "OS2borgerPC-client is not installed. Installing now..."
14-
15-
# Load values from the config file
16-
CONFIG_FILE="/etc/os2borgerpc/os2borgerpc.conf"
17-
PACKAGE_NAME=$(grep "^os2borgerpc_client_package:" "$CONFIG_FILE" | cut -d':' -f2- | xargs)
18-
19-
if [ -z "$PACKAGE_NAME" ]; then
20-
echo "No client package specified. Defaulting to $DEFAULT_OS2BORGERPC_CLIENT"
21-
PACKAGE_NAME="$DEFAULT_OS2BORGERPC_CLIENT"
22-
fi
23-
24-
# Check if PACKAGE_NAME is a GitHub URL or a PyPI package name
25-
if [[ "$PACKAGE_NAME" == https://github.com/* ]]; then
26-
# Parse GitHub username and repository name
27-
GITHUB_USER=$(echo "$PACKAGE_NAME" | awk -F'/' '{print $(NF-1)}')
28-
REPO_NAME=$(echo "$PACKAGE_NAME" | awk -F'/' '{print $NF}' | sed 's/.git$//')
29-
30-
# Fetch the latest tag from the GitHub API
31-
LATEST_TAG=$(curl -s "https://api.github.com/repos/$GITHUB_USER/$REPO_NAME/tags" | jq -r '.[0].name')
32-
33-
# Check if a tag was found and install from GitHub
34-
if [ -z "$LATEST_TAG" ]; then
35-
echo "No tags found for GitHub repository $GITHUB_USER/$REPO_NAME"
36-
exit 1
37-
else
38-
echo "Latest GitHub tag for $REPO_NAME: $LATEST_TAG"
39-
echo "Installing package from GitHub..."
40-
pip install "git+$PACKAGE_NAME@$LATEST_TAG" > /dev/null
41-
42-
# Set values in config file
43-
set_os2borgerpc_config os2borgerpc_client_package "$PACKAGE_NAME"
44-
set_os2borgerpc_config os2borgerpc_client_version "$LATEST_TAG"
45-
fi
46-
else
47-
# Assume PACKAGE_NAME is a PyPI package name and fetch the latest version from PyPI
48-
LATEST_VERSION=$(curl -s "https://pypi.org/pypi/$PACKAGE_NAME/json" | jq -r '.info.version')
49-
echo "https://pypi.org/pypi/$PACKAGE_NAME/json | jq -r '.info.version'"
50-
51-
# Check if a version was found and install from PyPI
52-
if [ -z "$LATEST_VERSION" ]; then
53-
echo "No version found for PyPI package $PACKAGE_NAME"
54-
exit 1
55-
else
56-
echo "Latest PyPI version for $PACKAGE_NAME: $LATEST_VERSION"
57-
echo "Installing package from PyPI..."
58-
pip install "$PACKAGE_NAME==$LATEST_VERSION" > /dev/null
59-
60-
# Set values in config file
61-
set_os2borgerpc_config os2borgerpc_client_package "$PACKAGE_NAME"
62-
set_os2borgerpc_config os2borgerpc_client_version "$LATEST_VERSION"
63-
fi
64-
fi
65-
fi
8+
# Update os2borgerpc-client
9+
/usr/local/bin/update_client.sh
6610

11+
# Register
6712
/usr/local/bin/register_new_os2borgerpc_client.sh

image/scripts/os2borgerpc_setup.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ cd -
107107

108108
figlet "=== About to run assorted OS2borgerPC scripts from the scripts repo ==="
109109

110+
# Temporary intall os2borgerpc-client, as it is a dependency for running the scripts below.
111+
# the script has been copied by do_overwrite.sh above.
112+
"./usr/local/bin/update_client.sh"
113+
110114
# Cloning script repository
111115
git clone --depth 1 https://github.com/OS2borgerPC/os2borgerpc-scripts.git
112116

@@ -206,4 +210,7 @@ fi
206210
# Remove cloned script repository
207211
rm --recursive "$SCRIPT_DIR"
208212

213+
# Uninstall temporary os2borgerpc-client install
214+
pip uninstall -y os2borgerpc-client
215+
209216
printf "\n\n%s\n\n" "=== Finished running assorted OS2borgerPC scripts ==="

0 commit comments

Comments
 (0)