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.
		
		
		
		
		
			
		
			
				
					
					
						
							215 lines
						
					
					
						
							5.3 KiB
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							215 lines
						
					
					
						
							5.3 KiB
						
					
					
				
								#!/bin/sh -e
							 | 
						|
								
							 | 
						|
								# Configuration
							 | 
						|
								dir_build="$PWD/build"  # Temporary directory to build packages
							 | 
						|
								dir_source="$PWD/source"  # Directory where the package sources will be placed
							 | 
						|
								dir_install="$PWD/install"  # Directory where the package will be installed
							 | 
						|
								dir_sysroot=""  # The root dir (Used for dirs like etc and var)
							 | 
						|
								dir_prefix="$dir_sysroot/usr"  # Prefix directory
							 | 
						|
								cmd_download="curl -# -L -o {dst} {src}"  # Command to execute to download files
							 | 
						|
								cmd_extract="tar -x -C {dst} -f {src}"  # Command to execute to extract files
							 | 
						|
								enable_check=true  # Run the test suite of packages
							 | 
						|
								unset dir_satellites  # Directory where the satellite files are placed.
							 | 
						|
								[ -f /etc/astronaut.conf ] && . /etc/astronaut.conf
							 | 
						|
								[ -f "$HOME/.astronaut.conf" ] && . "$HOME/.astronaut.conf"
							 | 
						|
								
							 | 
						|
								# Options not in the configuration
							 | 
						|
								_download_only=false
							 | 
						|
								unset _header_end_hooks
							 | 
						|
								_vcs_only=false
							 | 
						|
								vcs_compile=false
							 | 
						|
								#_nuke_dir_install (This can be set from wrappers)
							 | 
						|
								
							 | 
						|
								# Some printing functions
							 | 
						|
								_show_help() {
							 | 
						|
								echo "This astronaut will help you build some satellites.
							 | 
						|
								Just describe what he's got to do in a satellite file.
							 | 
						|
								Usage: $0 [-sbip <dir>] [-IcCd] <satellite>
							 | 
						|
								
							 | 
						|
								-h/? Show this message
							 | 
						|
								-b   Set build directory [WARNING: Will be deleted before build]
							 | 
						|
								-s   Set source directory
							 | 
						|
								-i   Set install directory
							 | 
						|
								-p   Set prefix directory
							 | 
						|
								-r   Set root directory
							 | 
						|
								-I   Nuke install directory before build
							 | 
						|
								-c/C Enable/Disable package checking
							 | 
						|
								-d   Only download package files
							 | 
						|
								-v   Only build vcs package if any updates have been made to it"
							 | 
						|
								}
							 | 
						|
								
							 | 
						|
								_msg() {
							 | 
						|
								    echo "=> $@"
							 | 
						|
								}
							 | 
						|
								
							 | 
						|
								_exiterr() {
							 | 
						|
								    echo "===> Houston, we've got a problem: $@" 1>&2
							 | 
						|
								    exit 1
							 | 
						|
								}
							 | 
						|
								
							 | 
						|
								# Gather info
							 | 
						|
								while getopts "h?s:b:i:p:IcCdv" opt; do
							 | 
						|
								    case "$opt" in
							 | 
						|
								        h|\?)
							 | 
						|
								            _show_help
							 | 
						|
								            exit 0
							 | 
						|
								            ;;
							 | 
						|
								        s)
							 | 
						|
								            dir_source="$(realpath "$OPTARG")"
							 | 
						|
								            ;;
							 | 
						|
								        b)
							 | 
						|
								            dir_build="$(realpath "$OPTARG")"
							 | 
						|
								            ;;
							 | 
						|
								        i)
							 | 
						|
								            dir_install="$(realpath "$OPTARG")"
							 | 
						|
								            ;;
							 | 
						|
								        p)
							 | 
						|
								            dir_prefix="$(realpath "$OPTARG")"
							 | 
						|
								            ;;
							 | 
						|
								        r)
							 | 
						|
								            dir_sysroot="$(realpath "$OPTARG")"
							 | 
						|
								            ;;
							 | 
						|
								        I)
							 | 
						|
								            _nuke_dir_install=true
							 | 
						|
								            ;;
							 | 
						|
								        c)
							 | 
						|
								            enable_check=true
							 | 
						|
								            ;;
							 | 
						|
								        C)
							 | 
						|
								            enable_check=false
							 | 
						|
								            ;;
							 | 
						|
								        d)
							 | 
						|
								            _download_only=true
							 | 
						|
								            ;;
							 | 
						|
								        v)
							 | 
						|
								            _vcs_only=true
							 | 
						|
								            ;;
							 | 
						|
								    esac
							 | 
						|
								done
							 | 
						|
								
							 | 
						|
								shift $((OPTIND-1))
							 | 
						|
								[ "$1" = "--" ] && shift
							 | 
						|
								
							 | 
						|
								if [ ! "$1" ]; then
							 | 
						|
								    _show_help
							 | 
						|
								    exit 1
							 | 
						|
								fi
							 | 
						|
								
							 | 
						|
								# Tools for the astronaut
							 | 
						|
								_mksum() {
							 | 
						|
								    echo "$(md5sum "$@" 2> /dev/null | cut -d' ' -f1)"
							 | 
						|
								}
							 | 
						|
								
							 | 
						|
								download() {
							 | 
						|
								    mkdir -p "$dir_source/$name"
							 | 
						|
								
							 | 
						|
								    local filename="$(basename "$1" | cut -d? -f1)"
							 | 
						|
								    local path="$dir_source/$name/$filename"
							 | 
						|
								
							 | 
						|
								    [ "$2" -a -f "$path" ] && local checksum="$(_mksum "$path")"
							 | 
						|
								
							 | 
						|
								    if [ ! -e "$path" -o "$checksum" != "$2" ]; then
							 | 
						|
								        _msg "Downloading $filename"
							 | 
						|
								
							 | 
						|
								        [ "$3" ] && local cmd="$3" || local cmd="$cmd_download"
							 | 
						|
								        eval $(echo "$cmd" | sed -e "s@{dst}@'$path'@g" -e "s@{src}@'$1'@g")
							 | 
						|
								
							 | 
						|
								        checksum="$(_mksum "$path")"
							 | 
						|
								        if [ "$2" -a "$checksum" != "$2" ]; then
							 | 
						|
								            _msg "Checksum: $checksum"
							 | 
						|
								            _exiterr "Checksum failed"
							 | 
						|
								        fi
							 | 
						|
								    fi
							 | 
						|
								}
							 | 
						|
								
							 | 
						|
								extract() {
							 | 
						|
								    _msg "Extracting $1"
							 | 
						|
								    [ "$2" ] && local dest="$2" || local dest="."
							 | 
						|
								    [ "$3" ] && local cmd="$3" || local cmd="$cmd_extract"
							 | 
						|
								    eval $(echo "$cmd" | sed -e "s@{src}@'$dir_source/$name/$1'@g" -e "s@{dst}@'$dest'@g")
							 | 
						|
								}
							 | 
						|
								
							 | 
						|
								getfile() {
							 | 
						|
								    cp -r "$dir_source/$name/$1" "$dir_build/$1"
							 | 
						|
								}
							 | 
						|
								
							 | 
						|
								extrafile() {
							 | 
						|
								    cp "$(dirname "$_satellite")/extrafiles/$_satname/$1" "$dir_build/$1"
							 | 
						|
								}
							 | 
						|
								
							 | 
						|
								dlextract() {
							 | 
						|
								    download "$1" "$2"
							 | 
						|
								    extract "$(basename "$1" | cut -d? -f1)"
							 | 
						|
								}
							 | 
						|
								
							 | 
						|
								dlfile() {
							 | 
						|
								    download "$1" "$2"
							 | 
						|
								    getfile "$(basename "$1" | cut -d? -f1)"
							 | 
						|
								}
							 | 
						|
								
							 | 
						|
								do_check() {
							 | 
						|
								    if [ "$1" ]; then
							 | 
						|
								        [ "$enable_check" = true ] && $@
							 | 
						|
								    else
							 | 
						|
								        [ "$enable_check" = true ]
							 | 
						|
								        return $?
							 | 
						|
								    fi
							 | 
						|
								}
							 | 
						|
								
							 | 
						|
								import() {
							 | 
						|
								    . "$(dirname "$_satellite")/functions/$1.sh"
							 | 
						|
								}
							 | 
						|
								
							 | 
						|
								# Set some functions in accordance to the _download_only option.
							 | 
						|
								header_end() { :; }
							 | 
						|
								if [ "$_vcs_only" = true ]; then
							 | 
						|
								    header_end() {
							 | 
						|
								        if [ ! "$vcs_compile" = true ]; then
							 | 
						|
								            exit
							 | 
						|
								        fi
							 | 
						|
								    }
							 | 
						|
								fi
							 | 
						|
								if [ "$_download_only" = true ]; then
							 | 
						|
								    # Disable some functions
							 | 
						|
								    extract() { :; }
							 | 
						|
								    getfile() { :; }
							 | 
						|
								    extrafile() { :; }
							 | 
						|
								
							 | 
						|
								    # Exit at the end of the header
							 | 
						|
								    header_end() { exit; }
							 | 
						|
								fi
							 | 
						|
								
							 | 
						|
								_satellite="$(realpath "$1")"
							 | 
						|
								_satname="$(basename "$_satellite" .sat)"
							 | 
						|
								
							 | 
						|
								# Try to find the satellite file if it can't be found.
							 | 
						|
								if [ ! -f "$_satellite" ]; then
							 | 
						|
								    if [ -d "$dir_satellites" ]; then
							 | 
						|
								        file="$(find "$dir_satellites" -type f \( -name "$_satname.sat" -o -name "$_satname" \) -print -quit)"
							 | 
						|
								        if [ -f "$file" ]; then
							 | 
						|
								            _satellite="$(realpath "$file")"
							 | 
						|
								            _satname="$(basename "$_satellite" .sat)"
							 | 
						|
								        fi
							 | 
						|
								    fi
							 | 
						|
								
							 | 
						|
								    # If it still can't be found, exit.
							 | 
						|
								    if [ ! -f "$_satellite" ]; then
							 | 
						|
								        _exiterr "Can't find satellite"
							 | 
						|
								    fi
							 | 
						|
								fi
							 | 
						|
								
							 | 
						|
								# Create the directories
							 | 
						|
								if [ "$_download_only" = false ]; then
							 | 
						|
								    # This variable can be set by a wrapper script in need to nuke the install dir.
							 | 
						|
								    if [ "$_nuke_dir_install" = true ]; then
							 | 
						|
								        rm -rf "$dir_install"
							 | 
						|
								    fi
							 | 
						|
								
							 | 
						|
								    rm -rf "$dir_build"
							 | 
						|
								    mkdir -p "$dir_build"
							 | 
						|
								    mkdir -p "$dir_install"
							 | 
						|
								    cd "$dir_build"
							 | 
						|
								fi
							 | 
						|
								
							 | 
						|
								# Create the satellite
							 | 
						|
								. "$_satellite"
							 | 
						|
								
							 |