#!/bin/bash # # Author: Georg Voell - georg.voell@standby.cloud # Version: @(#)classic 3.2.0 13.09.2024 (c)2024 Standby.cloud # Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/ # # This script can be used free of charge. Use it as is or customize as needed. It is not guaranteed to be # error free and you will not be reimbursed for any damage it may cause. # #@ Wrapper script for cli psm. #@ #@Usage: classic [options] [service] #@ Options: -h, --help : Displays helptext. #@ -v, --version: Displays the version of the script. #@ Service: : Service to select. #@ #@Examples: #@ classic #@ List all classic services available. # # Exit codes: # 01: Unknown parameter or first parameter was empty or not a directory. # 02: psm not available or not initialized. # 03: Error downloading service list. # 99: User interrupt. # # See also: # **install-scripts**(1) # # ToDo: # # - More objects. # # Update history: # # V 3.0.0 05.09.2022 First version # V 3.1.0 05.06.2023 New copyright # V 3.2.0 13.09.2024 New minor version # # Find executable bash library and source it lib=`which lib.bash 2>/dev/null | sed 's|^no 'lib.bash' in .*||'` if [ "$lib" != "" ]; then source "$lib" else progdir=`dirname "$0"` if [ -r "${progdir}/lib.bash" ]; then source "${progdir}/lib.bash" else echo "Unexpected error: Unable to locate bash library 'lib.bash'." exit 1 fi fi # Preset param="" # Check parameters: Loop until all parameters are used up while [ $# -gt 0 ]; do pname=${1} case "$pname" in -v | --version) shift showversion=true ;; -h | --help) shift showhelp=true ;; *) shift paramck=`echo "$pname" | grep '^-'` # Keys don't begin with '-' if [ "$paramck" != "" ]; then errstr="Unknown option '$pname'." else if [ "$param" = "" ]; then param="$pname" else errstr="Service was already specified '$param'. Unknown additional parameter: '$pname'." fi fi esac done # Plausibility check #if [ "$param" = "" ]; then # errstr="No service specified in first parameter." #else # if [ ! -d "$param" ]; then # errstr="Folder '$param' not found." # fi #fi # Display help or error message DisplayHelp # Define default variables baseurl="https://standby.cloud/download" # Download a filelist with tools to install function DownloadServieList() { servicelist=${1} transfer --quiet ${baseurl}/lists/classic.txt > $servicelist status=$? if [ $status -ne 0 ]; then exitcode=3 errormsg $exitcode "($progstr) Could not download filelist '$servicelist'." "CURL could not establish a connection to server" filecheck -rm $servicelist return $exitcode else cmd="`cat $servicelist | head -n 1 | cut -d$'\t' -f1`" if [ "$cmd" != "service" ]; then exitcode=3 errormsg $exitcode "($progstr) Corrupt filelist '$filelist'." "Download not successful" filecheck -rm $servicelist return $exitcode fi fi } # Main # Check if he have psm available psm=`filecheck -x psm` if [ "$psm" = "" ]; then exitcode=2 errormsg $exitcode "($progstr) No 'psm' in '$PATH'." "Please install it first" exit $exitcode else # Check if psm is initialized and we have the latest version result=`$psm update 2>&1` exitcode=$? if [ $exitcode -ne 0 ]; then result=`echo $result | cut -d'.' -f1` if [ "$result" = "Update failed" ]; then result="Please check connection to internet" fi errormsg $exitcode "($progstr) CLI 'psm update' failed." "$result" exit $exitcode else # Download classic services list DownloadServieList $scratchfile exitcode=$? if [ $status -eq 0 ]; then while IFS=$'\t' read -r service description; do printf "\nService: %s (%s): " "$service" "$description" exec="services" if [ $service = "accs" ]; then exec="apps" else if [ $service = "stack" ]; then exec="list" fi fi $psm $service $exec >/dev/null 2>&1 status=$? if [ $status -eq 0 ]; then printf "${green}Usable.${normal}\n\n" $psm $service $exec else printf "${yellow}Status: %d - Forbidden or unused.${normal}\n" $status fi done < <(cat $scratchfile | tailfromline2 | stripcomment) fi fi fi # Cleanup and exit Cleanup exit $exitcode