Skip to content

Commit

Permalink
Closes #10; fix: Fix installation from Debian packages by installing …
Browse files Browse the repository at this point in the history
…package that the meta-package refers to instead of just the meta-package, document the changes in the manual installation guide and update unit tests accordingly
  • Loading branch information
2b-t committed Dec 29, 2024
1 parent f7c9f4d commit 0ed43e2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 19 deletions.
4 changes: 2 additions & 2 deletions doc/PreemptRt.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ Afterwards you can reboot your system (be sure to select the correct kernel!) an

##### 1.2.2.2 Manual installation

Have a look at the search results resulting from [this query on package.debian.org](https://packages.debian.org/search?keywords=linux-image-rt-amd64) (potentially changing the architecture!) and see if you can find a kernel close to yours, e.g. [this one](https://packages.debian.org/bullseye/linux-image-rt-amd64). If you can find one click on the architecture `amd64` under `Download linux-image-rt-amd64` on the bottom and select a geographically suiting mirror and save the image in a location of your choice.
Have a look at the search results resulting from [this query on package.debian.org](https://packages.debian.org/search?keywords=linux-image-rt-amd64) and see if you can find a kernel close to yours, e.g. [this one](https://packages.debian.org/bullseye/linux-image-rt-amd64). If you can find one click on the dependency `dep` and then on the architecture `amd64` under `Download linux-image-*-rt-amd64` on the bottom and select a geographically suiting mirror and save the Debian package in a location of your choice.

Finally install it by opening a terminal in this folder and typing

```shell
$ sudo dpkg -i linux-image-rt-amd64_5.10.106-1_amd64.deb
$ sudo dpkg -i linux-image-5.10.0-33-rt-amd64_5.10.226-1_amd64.deb
$ sudo apt-get install -f
```

Expand Down
25 changes: 16 additions & 9 deletions src/lib_install_debian.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,27 @@ function get_debian_versions() {
echo $(cat /etc/debian_version | tr / " ")
}

function get_preemptrt_file() {
declare desc="Get the PREEMPT_RT filename for the given Debian distribution by crawling the website"
function get_architecture() {
declare desc="Get the computer architecture"
echo $(dpkg --print-architecture)
}

function get_preemptrt_debian_package() {
declare desc="Get the Debian package dependency referred to by the meta-package"
local DEBIAN_VERSION=$1
local ARCHITECTURE=$(dpkg --print-architecture)
echo $(curl -Ls https://packages.debian.org/${DEBIAN_VERSION}/${ARCHITECTURE}/linux-image-rt-${ARCHITECTURE}/download | grep -o -P '(?<=<h2>Download Page for <kbd>)(linux-image-rt.*)(?=<\/kbd>)')
local ARCHITECTURE=$2
echo $(curl -Ls https://packages.debian.org/${DEBIAN_VERSION}/linux-image-rt-${ARCHITECTURE} | grep -o -P "(?<=<a href=\"\/${DEBIAN_VERSION}\/)(linux-image-.*-rt-${ARCHITECTURE})(?=\")")
}

function select_debian_version() {
declare desc="Select the Debian version from a list of given Debian versions"
local POSSIBLE_DEBIAN_VERSIONS=$(get_debian_versions)
local ARCHITECTURE=$(get_architecture)
local DIALOG_POSSIBLE_DEBIAN_VERSIONS=""
for VER in ${POSSIBLE_DEBIAN_VERSIONS}; do
local PREEMPTRT_FILE=$(get_preemptrt_file "$VER")
if [ ! -z "${PREEMPTRT_FILE}" ]; then
DIALOG_POSSIBLE_DEBIAN_VERSIONS="${DIALOG_POSSIBLE_DEBIAN_VERSIONS} ${VER} ${PREEMPTRT_FILE}"
local PREEMPTRT_DEBIAN_PACKAGE=$(get_preemptrt_debian_package "${VER}" "${ARCHITECTURE}")
if [ ! -z "${PREEMPTRT_DEBIAN_PACKAGE}" ]; then
DIALOG_POSSIBLE_DEBIAN_VERSIONS="${DIALOG_POSSIBLE_DEBIAN_VERSIONS} ${VER} ${PREEMPTRT_DEBIAN_PACKAGE}"
fi
done
echo $(dialog --keep-tite --stdout --menu "Select the desired PREEMPT_RT kernel version:" 0 0 4 ${DIALOG_POSSIBLE_DEBIAN_VERSIONS})
Expand All @@ -37,8 +43,9 @@ function select_debian_version() {
function get_download_locations() {
declare desc="Get a list of available download servers for the PREEMPT_RT Debian package given the Debian version by crawling the website"
local DEBIAN_VERSION=$1
local ARCHITECTURE=$(dpkg --print-architecture)
echo $(curl -Ls https://packages.debian.org/${DEBIAN_VERSION}/${ARCHITECTURE}/linux-image-rt-${ARCHITECTURE}/download | grep -o -P '(?<=<li><a href=\")(.*\.deb)(?=\">)')
local ARCHITECTURE=$(get_architecture)
local DEBIAN_PACKAGE=$(get_preemptrt_debian_package "${DEBIAN_VERSION}" "${ARCHITECTURE}")
echo $(curl -Ls https://packages.debian.org/${DEBIAN_VERSION}/${ARCHITECTURE}/${DEBIAN_PACKAGE}/download | grep -o -P '(?<=<li><a href=\")(.*\.deb)(?=\">)')
}

function select_download_location() {
Expand Down
17 changes: 9 additions & 8 deletions test/test_lib_install_debian.bats
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ function setup() {
assert_regex "${DEBIAN_VERSIONS}" "^([a-z]( )?)+$"
}

@test "Test get_preemptrt_file" {
@test "Test get_preemptrt_debian_package" {
declare desc="Test if a valid Debian file is returned for the given Debian version"
local DEBIAN_VERSION="bullseye"
local PREEMPTRT_FILE=$(get_preemptrt_file "${DEBIAN_VERSION}")
assert_regex "${PREEMPTRT_FILE}" "^(linux-image-rt-).+(\.deb)$"
local DEBIAN_VERSION="trixie"
local ARCHITECTURE=$(get_architecture)
local PREEMPTRT_FILE=$(get_preemptrt_debian_package "${DEBIAN_VERSION}" "${ARCHITECTURE}")
assert_regex "${PREEMPTRT_FILE}" "^(linux-image-).+(-rt-${ARCHITECTURE})$"
}

@test "Test select_debian_version" {
Expand All @@ -49,14 +50,14 @@ function setup() {

@test "Test get_download_locations" {
declare desc="Test if a valid hyperlink is returned for the given Debian version"
local DEBIAN_VERSION="bullseye"
local DEBIAN_VERSION="trixie"
local DOWNLOAD_LOCATION=$(get_download_locations "${DEBIAN_VERSION}")
assert_regex "${DOWNLOAD_LOCATION}" "^(http://).+(\.deb)$"
}

@test "Test select_download_location" {
declare desc="Test if select download location dialog returns a single option only"
local DEBIAN_VERSION="bullseye"
local DEBIAN_VERSION="trixie"
tmux new -d -A -s "bats_test_session"
local TEST_FILE=$(test_file)
tmux send-keys -t "bats_test_session" "source ${TEST_FILE}" Enter
Expand All @@ -70,8 +71,8 @@ function setup() {

@test "Test extract_filename" {
declare desc="Test if filename is extracted correctly from hyperlink"
local DOWNLOAD_LOCATION="http://ftp.us.debian.org/debian/pool/main/l/linux-signed-amd64/linux-image-rt-amd64_5.10.127-1_amd64.deb"
local DOWNLOAD_LOCATION="http://ftp.us.debian.org/debian/pool/main/l/linux-signed-amd64/linux-image-6.12.6-rt-amd64_6.12.6-1_amd64.deb"
local DOWNLOADED_FILE=$(extract_filename "${DOWNLOAD_LOCATION}")
assert_regex "${DOWNLOADED_FILE}" "^(linux-image-rt-).+(\.deb)$"
assert_regex "${DOWNLOADED_FILE}" "^(linux-image-).+(\.deb)$"
}

0 comments on commit 0ed43e2

Please sign in to comment.