#!/bin/sh # [ LICENSE CLAUSE HERE ] # WARNING: auto-generated by CI tools _appimage_metadata() { #__os="$1" #__arch="$2" case "${1}-${2}" in linux-amd64) __sha256="e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" __target="appimagetool-x86_64.AppImage" ;; linux-arm64) __sha256="5e5b242789188ab74e1ee1d0eea135377c7791cd7557771edb93df64ae47cee3" __target="appimagetool-aarch64.AppImage" ;; linux-armhf) __sha256="5177edbc5089c3164af9f42191d1c70297c7869b99b0064fa3497c7d57c4b602" __target="appimagetool-armhf.AppImage" ;; linux-i386) __sha256="9bdaeddef9e19382335346914b9469714f4dc014cc97fb7389af5cdef9438788" __target="appimagetool-i686.AppImage" ;; *) __sha256="" __target="" ;; esac # execute printf -- "%b" "${__sha256}|${__target}" } # AUTOMATION - APPEND THE FOLLOWING TO THE ABOVE print_status() { __status_mode="$1" && shift 1 __msg="" __color="" case "$__status_mode" in error) __msg="ERROR --> " __color="31" ;; warning) __msg="WARNING --> " __color="33" ;; info) __msg="INFO --> " __color="36" ;; note) __msg="NOTE --> " __color="35" ;; success) __msg="SUCCESS --> " __color="32" ;; ok) __msg=" OK --> " __color="36" ;; done) __msg=" DONE --> " __color="36" ;; plain) __msg="" ;; *) return 0 ;; esac if [ ! -z "$COLORTERM" ] || [ "$TERM" = "xterm-256color" ]; then __msg="\033[1;${__color}m${__msg}\033[0;${__color}m${@}\033[0m" else __msg="${__msg} ${@}" fi 1>&2 printf -- "${__msg}" unset __status_mode __msg __color return 0 } shasum_is_available() { # execute if [ ! -z "$(type -t shasum)" ]; then return 0 fi # report status return 1 } downloader_is_available() { # execute if [ -z "$(type -t curl)" ] && [ -z "$(type -t wget)" ]; then return 1 fi # report status return 0 } HTTP_download() { __method="$1" __url="$2" __filepath="$3" __shasum_type="$4" __shasum_value="$5" __auth_header="$6" # validate input if [ -z "$__url" ] || [ -z "$__filepath" ]; then return 1 fi if [ -z "$(type -t curl)" ] && [ -z "$(type -t wget)" ]; then return 1 fi if [ -z "$(type -t shasum)" ]; then return 1 fi if [ -z "$__method" ]; then __method="GET" fi # execute ## clean up workspace rm -rf "$__filepath" &> /dev/null mkdir -p "${__filepath%/*}" &> /dev/null ## download payload if [ ! -z "$__auth_header" ]; then if [ ! -z "$(type -t curl)" ]; then curl --header "$__auth_header" \ --output "$__filepath" \ --request "$__method" \ "$__url" elif [ ! -z "$(type -t wget)" ]; then wget --header="$__auth_header" \ --output-file"$__filepath" \ --method="$__method" \ "$__url" else return 1 fi else if [ ! -z "$(type -t curl)" ]; then curl --output "$__filepath" --request "$__method" "$__url" elif [ ! -z "$(type -t wget)" ]; then wget --output-file"$__filepath" --method="$__method" "$__url" else return 1 fi fi if [ ! -f "$__filepath" ]; then return 1 fi ## checksum payload if [ -z "$__shasum_type" ] || [ -z "$__shasum_value" ]; then return 0 fi case "$__shasum_type" in 1|224|256|384|512|512224|512256) ;; *) return 1 ;; esac __target_shasum="$(shasum -a "$__shasum_type" "$__filepath")" __target_shasum="${__target_shasum%% *}" if [ ! "$__target_shasum" = "$__shasum_value" ]; then return 1 fi # report status return 0 } install() { #__os="$1" #__arch="$2" #__path="$3" # validate input if [ -z "$1" ] || [ -z "$2" ]; then print_status error "internal error. Please report to GitHub!\n" return 1 fi if [ -z "$3" ]; then print_status error "missing destination path. Use --help for assistance.\n" return 1 fi if [ -f "$3" ]; then print_status error "${3} exists. Please clean it up.\n" return 1 fi # check dependencies shasum_is_available if [ $? -ne 0 ]; then print_status error "'shasum' is unavailable. Please install.\n" return 1 fi downloader_is_available if [ $? -ne 0 ]; then print_status error "'curl' OR 'wget' is unavailable. Please install.\n" return 1 fi # gather all metadatas __target="$(_appimage_metadata "$1" "$2")" if [ -z "$__target" ] || [ "$__target" = "|" ]; then print_status error "Sorry. Unsupported platform.\n" return 1 fi __base_url="https://github.com/AppImage/appimagetool/releases/download/continuous/" __method="GET" __algo="256" __sha256="${__target%%|*}" __target="${__target##*|}" # execute HTTP_download "$__method" "${__base_url}/${__target}" "$3" "$__algo" "$__sha256" if [ $? -ne 0 ]; then print_status error "Download failed.\n" rm -rf "$3" &> /dev/null return 1 fi print_status success "enjoy!\n\n" chmod +x "$3" return 0 } main() { # decleare version __version="1.0.0" # determine os __os="$(uname)" export __os="$(echo "$__os" | tr '[:upper:]' '[:lower:]')" case "${__os}" in windows*|ms-dos*) export __os='windows' ;; cygwin*|mingw*|mingw32*|msys*) export __os='windows' # edge cases. Set it to widnows for now ;; *freebsd) export __os='freebsd' ;; dragonfly*) export __os='dragonfly' ;; *) ;; esac print_status info "detecting os: ${__os}\n" # determine arch __arch="$(uname -m)" export __arch="$(echo "$__arch" | tr '[:upper:]' '[:lower:]')" case "${__arch}" in i686-64) export __arch='ia64' # Intel Itanium. ;; i386|i486|i586|i686) export __arch='i386' ;; x86_64) export __arch="amd64" ;; sun4u) export __arch='sparc' ;; "power macintosh") export __arch='powerpc' ;; ip*) export __arch='mips' ;; *) ;; esac print_status info "detecting arch: ${__arch}\n" # parse params __action="help" __path="" __count=1 for __value in "$@"; do case "$__value" in -i|install|--install) if [ $__count -eq 1 ]; then __action="install" fi ;; -h|help|--help) if [ $__count -eq 1 ]; then __action="help" fi ;; *) if [ "$__action" = "install" ] && [ $__count -eq 2 ]; then __path="$__value" else __action="help" fi ;; esac __count=$(($__count + 1)) done # take action case "$__action" in install) install "$__os" "$__arch" "$__path" return $? ;; *) # assume help printf -- "%b" "\ AppImage (Version ${__version}) To use: ${0} install /destination/path/directory/ Format: ${0} COMMAND [ARGUMENTS] AVAILABLE COMMANDS install, -i, --install [PATH] install the application. You must specify the destination filepath after it. help, -h, --help print this help. " return 0 ;; esac } main "$@" exit $?