From 7d9044d479fc05155bc6fa30814800972cefa910 Mon Sep 17 00:00:00 2001 From: EnumDev Date: Thu, 8 May 2025 17:18:57 +0300 Subject: [PATCH] Initial Commit --- .compilation-options | 1 + pkg.info | 6 ++++ source-files/LICENSE | 21 ++++++++++++ source-files/java.profile | 2 ++ source-files/tide-java-utils | 66 ++++++++++++++++++++++++++++++++++++ source.sh | 12 +++++++ 6 files changed, 108 insertions(+) create mode 100644 .compilation-options create mode 100644 pkg.info create mode 100644 source-files/LICENSE create mode 100644 source-files/java.profile create mode 100644 source-files/tide-java-utils create mode 100644 source.sh diff --git a/.compilation-options b/.compilation-options new file mode 100644 index 0000000..9c7aafe --- /dev/null +++ b/.compilation-options @@ -0,0 +1 @@ +ARCH=any diff --git a/pkg.info b/pkg.info new file mode 100644 index 0000000..1a759dd --- /dev/null +++ b/pkg.info @@ -0,0 +1,6 @@ +name: tide-java-utils +description: Tide Linux utility for switching between java versions +version: 1.0 +license: MIT +architecture: any +type: source diff --git a/source-files/LICENSE b/source-files/LICENSE new file mode 100644 index 0000000..338bf97 --- /dev/null +++ b/source-files/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2025 EnumDev + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/source-files/java.profile b/source-files/java.profile new file mode 100644 index 0000000..101d081 --- /dev/null +++ b/source-files/java.profile @@ -0,0 +1,2 @@ +# Append default java version to PATH +append_path /usr/lib/java/default/bin diff --git a/source-files/tide-java-utils b/source-files/tide-java-utils new file mode 100644 index 0000000..08a34d7 --- /dev/null +++ b/source-files/tide-java-utils @@ -0,0 +1,66 @@ +#!/bin/bash + +function help() { + echo "Tide Linux Java Utilities" + echo + echo "Available commands:" + echo "- tide-java set-default | Sets the default java version" + echo "- tide-java get-default | Gets the default java version" + echo "- tide-java list | Lists available java versions" +} + +function get_installed_java_versions() { + for dir in $(find /usr/lib/java/ -mindepth 1 -maxdepth 1 -not -name 'default'); do + echo $(basename "$dir") + done +} + +function get_default_java_version() { + # Return 1 if directory isn't found + [ -d /usr/lib/java/default/bin ] || return 1 + + local LINK_PATH=$(readlink /usr/lib/java/default) + echo $(basename "$LINK_PATH") +} + +function set_default_java_version() { + # Return 1 if empty argument is given + [ -z "$1" ] && return 1 + + while read line; do + if [[ "$1" == "$line" ]]; then + ln -sf "$line" -T /usr/lib/java/default || return 1 + return 0 + fi + done < <(get_installed_java_versions) + return 1 +} + +case "$1" in + "set-default") + if [ $UID -ne 0 ]; then + echo "Root permissions are required to set default java version" + exit 1 + fi + + if set_default_java_version "$2"; then + echo "Default java version successfully set to $2" + else + echo "Could not set default java version to $2" + exit 1 + fi + ;; + "get-default") + echo -n "Current default java version: " + get_default_java_version || echo "None" + ;; + "list") + echo "Available java versions:" + while read line; do + echo "- $line" + done < <(get_installed_java_versions) + ;; + *) + help + ;; +esac diff --git a/source.sh b/source.sh new file mode 100644 index 0000000..09d0634 --- /dev/null +++ b/source.sh @@ -0,0 +1,12 @@ +# This is the source.sh script. It is executed by BPM in a temporary directory when compiling a source package +# BPM Expects the source code to be extracted into the automatically created 'source' directory which can be accessed using $BPM_SOURCE +# BPM Expects the output files to be present in the automatically created 'output' directory which can be accessed using $BPM_OUTPUT + +# The package function is executed in the source directory +# This function is used to move the compiled files into the output directory +package() { + install -Dm755 "$BPM_WORKDIR"/tide-java-utils "$BPM_OUTPUT"/usr/bin/tide-java-utils + install -Dm644 "$BPM_WORKDIR"/java.profile "$BPM_OUTPUT"/etc/profile.d/java.sh + + install -Dm644 "$BPM_WORKDIR"/LICENSE "$BPM_OUTPUT"/usr/share/licenses/tide-java/LICENSE +}