123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- #!/usr/bin/env bash
- BUILD_SYSTEM="libreboot"
- SOURCES="sources"
- ARCHIVE="tar.xz"
- usage() {
- printf 1>&2 '%s\n' "$executable [action] [sources path] (extract path)"
- printf 1>&2 '\n%s\n' 'Actions:'
- printf 1>&2 '%s\n' ' extract - Extract build system sources'
- printf 1>&2 '%s\n' ' copy - Copy projects sources'
- printf 1>&2 '%s\n' ' prepare - Extract and copy sources'
- printf '\n%s\n' ' When no extract path is provided, sources are extracted in the current'
- printf '%s\n' ' directory.'
- }
- extract() {
- local sources_path=$1
- local extract_path=$2
- local build_system_path
- local archive
- build_system_path="$extract_path/$BUILD_SYSTEM"
- if [ -d "$build_system_path" ]
- then
- return
- fi
- archive=$( find $sources_path -name "$BUILD_SYSTEM-sources.$ARCHIVE" || true )
- if [ -z "$archive" ]
- then
- printf 1>&2 '%s\n' "Finding $BUILD_SYSTEM sources archive failed!"
- usage
- exit 1
- fi
- tar -xf "$archive" -ps -C "$extract_path"
- printf '\n%s\n' "Extracted $BUILD_SYSTEM sources from $sources_path to $extract_path"
- }
- copy() {
- local sources_path=$1
- local extract_path=$2
- local build_system_path
- local build_system_sources_path
- local archives
- local file
- build_system_path="$extract_path/$BUILD_SYSTEM"
- build_system_sources_path="$build_system_path/$SOURCES"
- if ! [ -d "$build_system_path" ]
- then
- return
- fi
- mkdir -p "$build_system_path/$SOURCES"
- ( find "$sources_path" -type f -not -name "$BUILD_SYSTEM*" || true ) | while read file
- do
- cp "$file" "$build_system_sources_path"
- done
- printf '\n%s\n' "Copied $BUILD_SYSTEM sources from $sources_path to $extract_path"
- }
- requirements() {
- local requirement
- local requirement_path
- for requirement in "$@"
- do
- requirement_path=$( which "$requirement" || true )
- if [ -z "$requirement_path" ]
- then
- printf 1>&2 '%s\n' "Missing requirement: $requirement"
- exit 1
- fi
- done
- }
- setup() {
- root=$(readlink -f "$( dirname "$0" )" )
- executable=$( basename "$0" )
- }
- libreboot_sources() {
- local action=$1
- local sources_path=$2
- local extract_path=$3
- set -e
- setup "$@"
- if [ -z "$sources_path" ]
- then
- usage
- exit 1
- fi
- if [ -z "$extract_path" ]
- then
- extract_path=$root
- fi
- requirements "tar" "sha256sum" "gpg"
- case $action in
- "extract")
- extract "$sources_path" "$extract_path"
- ;;
- "copy")
- copy "$sources_path" "$extract_path"
- ;;
- "prepare")
- extract "$sources_path" "$extract_path"
- copy "$sources_path" "$extract_path"
- ;;
- esac
- }
- libreboot_sources "$@"
|