You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							69 lines
						
					
					
						
							1.6 KiB
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							69 lines
						
					
					
						
							1.6 KiB
						
					
					
				
								#!/bin/sh -e
							 | 
						|
								# Helper functions for programs that work with satellite files.
							 | 
						|
								
							 | 
						|
								show_help() {
							 | 
						|
								echo "Script with helper functions for working with satellite files.
							 | 
						|
								Usage: $0 <satellite file> <function> [arguments]
							 | 
						|
								
							 | 
						|
								Functions:
							 | 
						|
								variable <name>     | Get variable set in the header
							 | 
						|
								downloads           | Get all download urls
							 | 
						|
								options             | List all available options and their descriptions"
							 | 
						|
								}
							 | 
						|
								
							 | 
						|
								if [ $# -lt 2 ]; then
							 | 
						|
								    show_help
							 | 
						|
								    exit 1
							 | 
						|
								fi
							 | 
						|
								
							 | 
						|
								satellite="$(realpath "$1")"
							 | 
						|
								function="$2"
							 | 
						|
								
							 | 
						|
								# Functions reused in different wrappers
							 | 
						|
								func_import=$(printf '
							 | 
						|
								    import() {
							 | 
						|
								        . "%s/functions/$1.sh"
							 | 
						|
								    }
							 | 
						|
								' "$(dirname "$satellite")")
							 | 
						|
								
							 | 
						|
								if [ "$function" = "variable" ]; then
							 | 
						|
								    name="$3"
							 | 
						|
								    if [ ! "$name" ]; then
							 | 
						|
								        show_help
							 | 
						|
								        exit 1
							 | 
						|
								    fi
							 | 
						|
								
							 | 
						|
								    printf "$func_import"'
							 | 
						|
								        header_end() {
							 | 
						|
								            variable="$%s"
							 | 
						|
								            [ "$variable" ] && echo "$variable"
							 | 
						|
								            exit $?
							 | 
						|
								        }
							 | 
						|
								        . %s
							 | 
						|
								    ' "$name" "$satellite" | PATH= /bin/sh 2> /dev/null
							 | 
						|
								elif [ "$function" = "downloads" ]; then
							 | 
						|
								    printf "$func_import"'
							 | 
						|
								        download() {
							 | 
						|
								            [ "$1" ] && echo "$1"
							 | 
						|
								        }
							 | 
						|
								        dlextract() {
							 | 
						|
								            [ "$1" ] && echo "$1"
							 | 
						|
								        }
							 | 
						|
								        dlfile() {
							 | 
						|
								            [ "$1" ] && echo "$1"
							 | 
						|
								        }
							 | 
						|
								        header_end() { exit 0; }
							 | 
						|
								        . %s
							 | 
						|
								    ' "$satellite" | PATH= /bin/sh 2> /dev/null
							 | 
						|
								elif [ "$function" = "options" ]; then
							 | 
						|
								    printf "$func_import"'
							 | 
						|
								        define_option() {
							 | 
						|
								            echo "$1"
							 | 
						|
								        }
							 | 
						|
								        header_end() { exit 0; }
							 | 
						|
								        . %s
							 | 
						|
								    ' "$satellite" | PATH= /bin/sh 2> /dev/null
							 | 
						|
								else
							 | 
						|
								    show_help
							 | 
						|
								    exit 1
							 | 
						|
								fi
							 | 
						|
								
							 |