Skip to content

Commit

Permalink
Updating readme and update installation script generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Alessandro OSIAS committed Oct 6, 2023
1 parent 812b164 commit a9e39a4
Show file tree
Hide file tree
Showing 17 changed files with 329 additions and 67 deletions.
2 changes: 1 addition & 1 deletion .github/scripts/run_rport_server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ trap 'echo "exit $? due to $previous_command"' EXIT
# Run a local instance of the RPort server to test if the pairing scripts successfully connects to this server.
#
cd /tmp
curl -Ls "https://download.rport.io/rportd/stable/?arch=Linux_x86_64" -o rportd.tar.gz
curl -Ls "https://download.openrport.io/rportd/stable/?arch=Linux_x86_64" -o rportd.tar.gz
tar xvzf rportd.tar.gz rportd
mkdir /tmp/rport-data
cat<<EOF>rportd.conf
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
A service to install and connect rport clients easily.

> 📣 This repository holds the sources used to run the public pairing service on https://pairing.rport.io.
> 📣 This repository holds the sources used to run the public pairing service on https://pairing.openrport.io.
## 👫 Use the pairing service
Below you will get detailed information how the pairing works. The explained requests are executed by the RPort user interface when you click on the "Install Client" button.
Expand Down Expand Up @@ -80,7 +80,7 @@ sudo sh rport-update.sh
```

## 🚚 Install and run a pairing service
Because the service does not store any data, there is nothing to stop you using the public and free service on https://pairing.rport.io.
Because the service does not store any data, there is nothing to stop you using the public and free service on https://pairing.openrport.io.
This public service is also the predefined default on all RPort server installations.

To run the service on your server proceed as follows.
Expand Down
10 changes: 5 additions & 5 deletions cmd/rport-pairing.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package main
import (
"flag"
"fmt"
"github.com/cloudradar-monitoring/rport-pairing/cors"
"github.com/cloudradar-monitoring/rport-pairing/deposit"
"github.com/cloudradar-monitoring/rport-pairing/internal/cache"
"github.com/cloudradar-monitoring/rport-pairing/internal/config"
"github.com/cloudradar-monitoring/rport-pairing/retrieve"
"github.com/gorilla/mux"
"github.com/openrport/rport-pairing/cors"
"github.com/openrport/rport-pairing/deposit"
"github.com/openrport/rport-pairing/internal/cache"
"github.com/openrport/rport-pairing/internal/config"
"github.com/openrport/rport-pairing/retrieve"
"log"
"net/http"
"os"
Expand Down
2 changes: 1 addition & 1 deletion cors/corsHandler_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cors_test

import (
"github.com/cloudradar-monitoring/rport-pairing/cors"
"github.com/openrport/rport-pairing/cors"
"github.com/stretchr/testify/assert"
"net/http"
"net/http/httptest"
Expand Down
4 changes: 2 additions & 2 deletions deposit/depositHandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package deposit_test
import (
"bytes"
"encoding/json"
"github.com/cloudradar-monitoring/rport-pairing/deposit"
"github.com/cloudradar-monitoring/rport-pairing/internal/cache"
"github.com/openrport/rport-pairing/deposit"
"github.com/openrport/rport-pairing/internal/cache"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"io"
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/cloudradar-monitoring/rport-pairing
module github.com/openrport/rport-pairing

go 1.18

Expand Down
2 changes: 1 addition & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package config

import (
"fmt"
"github.com/cloudradar-monitoring/rport-pairing/deposit"
"github.com/openrport/rport-pairing/deposit"
"github.com/spf13/viper"
"log"
)
Expand Down
2 changes: 1 addition & 1 deletion internal/config/config_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package config_test

import (
"github.com/cloudradar-monitoring/rport-pairing/internal/config"
"github.com/openrport/rport-pairing/internal/config"
"github.com/stretchr/testify/assert"
"testing"
)
Expand Down
2 changes: 1 addition & 1 deletion retrieve/installerHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package retrieve

import (
"fmt"
"github.com/cloudradar-monitoring/rport-pairing/deposit"
"github.com/gorilla/mux"
"github.com/openrport/rport-pairing/deposit"
"github.com/patrickmn/go-cache"
"net/http"
)
Expand Down
6 changes: 3 additions & 3 deletions retrieve/installerHandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package retrieve_test

import (
"fmt"
"github.com/cloudradar-monitoring/rport-pairing/deposit"
"github.com/cloudradar-monitoring/rport-pairing/internal/cache"
"github.com/cloudradar-monitoring/rport-pairing/retrieve"
"github.com/gorilla/mux"
"github.com/openrport/rport-pairing/deposit"
"github.com/openrport/rport-pairing/internal/cache"
"github.com/openrport/rport-pairing/retrieve"
"github.com/stretchr/testify/assert"
"net/http"
"net/http/httptest"
Expand Down
5 changes: 3 additions & 2 deletions retrieve/templates/header.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
## The scripts creates a initial configuration and connects the client to your server.
##
## For any inquiries use our GitHub forum on
## https://github.com/cloudradar-monitoring/rport-pairing/discussions/
## https://github.com/openrport/rport-pairing/discussions/
##
## Copyright cloudradar GmbH, Potsdam Germany, 2022
## Maintainer openrport, Lille, France, 2023
## Released under the MIT open-source license.
## https://github.com/cloudradar-monitoring/rport-pairing/blob/main/LICENSE
## https://github.com/openrport/rport-pairing/blob/main/LICENSE
##
191 changes: 190 additions & 1 deletion retrieve/templates/linux/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ uninstall() {
/usr/local/bin/tacoscript
/etc/init.d/rport
/var/run/rport.pid
/etc/runlevels/default/rport"
/etc/runlevels/default/rport
/etc/apt/sources.list.d/rport.list"
for FILE in $FILES; do
if [ -e "$FILE" ]; then
rm -f "$FILE" && echo " [ DELETED ] File $FILE"
Expand All @@ -60,6 +61,9 @@ uninstall() {
rm -rf "$FOLDER" && echo " [ DELETED ] Folder $FOLDER"
fi
done
if dpkg -l 2>&1 | grep -q "rport.*Remote access"; then
apt-get -y remove --purge rport
fi
echo "RPort client successfully uninstalled."
}

Expand Down Expand Up @@ -418,6 +422,11 @@ start_rport() {
elif is_available service; then
service rport start
fi
if pidof rport >/dev/null 2>&1; then
return 0
else
return 1
fi
}

stop_rport() {
Expand All @@ -430,3 +439,183 @@ stop_rport() {
service rport stop
fi
}

backup_config() {
if [ -z "$CONFIG_FILE" ]; then
throw_fatal "backup_config() \$CONFIG_FILE undefined."
fi
CONFIG_BACKUP="/tmp/.rport-conf.$(date +%s)"
cp "$CONFIG_FILE" "$CONFIG_BACKUP"
throw_debug "Configuration file copied to $CONFIG_BACKUP"
}

clean_up_legacy_installation() {
# If this is a migration from the old none deb-based installation, clean up
if [ -e /etc/systemd/system/rport.service ]; then
throw_info "Removing old systemd service /etc/systemd/system/rport.service"
rm -f /etc/systemd/system/rport.service
systemctl daemon-reload
fi
if [ -e /usr/local/bin/rport ]; then
throw_info "Removing old version /usr/local/bin/rport"
rm -f /usr/local/bin/rport
fi
}

install_via_deb_repo() {
if [ -z "$RELEASE" ]; then
throw_fatal "install_via_deb_repo() \$RELEASE undefined"
fi
validate_custom_user
if [ -e /etc/apt/trusted.gpg.d/rport.gpg ] && dpkg -l | grep -q rport; then
throw_info "System is already using the rport deb repo."
else
throw_info "RPort will use Debian package ..."
# shellcheck source=/dev/null
. /etc/os-release
if [ -n "$UBUNTU_CODENAME" ]; then
CODENAME=$UBUNTU_CODENAME
else
CODENAME=$VERSION_CODENAME
fi
curl -sf http://repo.openrport.io/dearmor.gpg >/etc/apt/trusted.gpg.d/rport.gpg
echo "deb [signed-by=/etc/apt/trusted.gpg.d/rport.gpg] http://repo.openrport.io/deb ${CODENAME} ${RELEASE}" >/etc/apt/sources.list.d/rport.list
fi
apt-get update
if dpkg -s rport >/dev/null 2>&1 && ! [ -e /etc/rport/rport.conf ]; then
throw_warning "Broken DEB package installation found."
throw_debug "Will remove old package first."
apt-get -y --purge remove rport
fi
DEBIAN_FRONTEND=noninteractive apt-get --yes -o Dpkg::Options::="--force-confold" install rport
TARGET_VERSION=$(rport --version | cut -d" " -f2)
clean_up_legacy_installation
}

install_via_rpm_repo() {
if [ -z "$RELEASE" ]; then
throw_fatal "install_via_rpm_repo() \$RELEASE undefined"
fi
validate_custom_user
if [ -e /etc/yum.repos.d/rport.repo ] && rpm -qa | grep -q rport; then
throw_info "System is already using the rport yum repo."
else
throw_info "RPort will use RPM package ..."
rpm --import https://repo.rport.io/key.gpg
cat <<EOF >/etc/yum.repos.d/rport.repo
[rport-stable]
name=RPort $RELEASE
baseurl=http://repo.openrport.io/rpm/$RELEASE/
enabled=1
gpgcheck=1
gpgkey=https://repo.openrport.io/key.gpg
EOF
fi
dnf -y install rport --refresh
TARGET_VERSION=$(rport --version | cut -d" " -f2)
clean_up_legacy_installation
}

validate_custom_user() {
if [ "$USER" != "rport" ]; then
throw_fatal "RPM/DEB packages cannot be used with a custom user. Try '-p'"
fi
}

# Check if it's a supported debian system
is_debian() {
if [ "$NO_REPO" -eq 1 ]; then
return 1
fi
if which apt-get >/dev/null 2>&1 && test -e /etc/apt/sources.list.d/; then
true
else
return 1
fi
DIST_SUPPORTED="jammy focal bionic bullseye buster bookworm"
for DIST in $DIST_SUPPORTED; do
if grep -qi "CODENAME.*$DIST" /etc/os-release; then
return 0
fi
done
return 1
}

is_rhel() {
if [ "$NO_REPO" -eq 1 ]; then
return 1
fi
if grep -q "VERSION=.[6-7]" /etc/os-release; then
throw_info "RHEL/CentOS too old for RPM installation. Switching to tar.gz package."
return 1
fi

if which rpm >/dev/null 2>&1 && test -e /etc/yum.repos.d; then
return 0
fi
return 1
}

validate_pkg_url() {
if echo "${PKG_URL}" | grep -q -E "https*:\/\/.*_linux_$(uname -m)\.(tar\.gz|deb|rpm)$"; then
true
else
throw_fatal "Invalid PKG_URL '$PKG_URL'."
fi
}

download_pkg_url() {
DL_AUTH=""
if [ -n "$RPORT_INSTALLER_DL_USERNAME" ] && [ -n "$RPORT_INSTALLER_DL_PASSWORD" ]; then
DL_AUTH="-u ${RPORT_INSTALLER_DL_USERNAME}:${RPORT_INSTALLER_DL_PASSWORD}"
throw_info "Download will use HTTP basic authentication"
fi
throw_info "Downloading from ${PKG_URL} ..."
PKG_DOWNLOAD=$(mktemp)
# shellcheck disable=SC2086
curl -LSs "${PKG_URL}" ${DL_AUTH} >${PKG_DOWNLOAD}
if [ -n "$(find "${PKG_DOWNLOAD}" -empty)" ]; then
rm -f "${PKG_DOWNLOAD}"
throw_fatal "Download to ${PKG_DOWNLOAD} failed"
fi
throw_info "Download to ${PKG_DOWNLOAD} completed"
}

install_from_deb_download() {
validate_pkg_url
if echo "${PKG_URL}" | grep -q "deb$"; then
true
else
throw_fatal "URL not pointing to a debian package"
fi
download_pkg_url
mv "${PKG_DOWNLOAD}" "${PKG_DOWNLOAD}".deb
PKG_DOWNLOAD=${PKG_DOWNLOAD}.deb
chmod 0644 "${PKG_DOWNLOAD}"
throw_info "Installing debian package ${PKG_DOWNLOAD}"
DEBIAN_FRONTEND=noninteractive apt-get --yes -o Dpkg::Options::="--force-confold" install "${PKG_DOWNLOAD}"
rm -f "${PKG_DOWNLOAD}"
clean_up_legacy_installation
}

install_from_rpm_download() {
validate_pkg_url
if echo "${PKG_URL}" | grep -q "rpm$"; then
true
else
throw_fatal "URL not pointing to an rpm package"
fi
download_pkg_url
throw_info "Installing rpm package"
rpm -U "${PKG_DOWNLOAD}"
rm -f "${PKG_DOWNLOAD}"
clean_up_legacy_installation
}

abort_on_rport_subprocess() {
if is_rport_subprocess; then
throw_hint "Execute the rport update in a process decoupled from its parent, e.g."
throw_hint ' nohup sh -c "curl -s https://pairing.openrport.io/update|sh" >/tmp/rport-update.log 2>&1 &'
throw_fatal "You cannot update rport from an rport subprocess."
fi
}
Loading

0 comments on commit a9e39a4

Please sign in to comment.