xplshn / pelf

Pack an ELF. Turn your binaries into single-file executables [.AppBundle|.blob], similar to AppImages and compatible with AppDirs. LIBC-independent, works on *BSDs.
BSD 3-Clause "New" or "Revised" License
12 stars 1 forks source link

[+] Provide an example build script for an example program for Toolpacks #5

Closed Azathothas closed 3 weeks ago

Azathothas commented 3 weeks ago

Hello, you have often shoved pelf right at me, but sadly I never took pelf seriously, for which I am genuinely sorry. But after the chain of events of, as documented well in: https://github.com/Azathothas/Toolpacks/issues/28 , I would like to give pelfs a chance.

So could you submit (in the replies) an example build script which would pack, let's say mpv using pelf to an AppBundle. I know you are a massive alpine fan, so please use the templates like this: Another example: https://github.com/Azathothas/Toolpacks/blob/main/.github/scripts/x86_64_Linux/bins/xdotool.sh (this uses ppkg in alpine)

Edit: Sourced from TG Texts

#!/usr/bin/env bash

#-------------------------------------------------------#
#Sanity Checks
if [ "$BUILD" != "YES" ] || \
   [ -z "$BINDIR" ] || \
   [ -z "$EGET_EXCLUDE" ] || \
   [ -z "$EGET_TIMEOUT" ] || \
   [ -z "$GIT_TERMINAL_PROMPT" ] || \
   [ -z "$GIT_ASKPASS" ] || \
   [ -z "$GITHUB_TOKEN" ] || \
   [ -z "$SYSTMP" ] || \
   [ -z "$TMPDIRS" ]; then
 #exit
  echo -e "\n[+]Skipping Builds...\n"
  exit 1
fi
#-------------------------------------------------------#

#-------------------------------------------------------#
##Main
export SKIP_BUILD="NO" #YES, in case of deleted repos, broken builds etc
if [ "$SKIP_BUILD" == "NO" ]; then
    #mpv : 🎥 Command line video player
     export BIN="mpv"
     export SOURCE_URL="https://github.com/mpv-player/mpv"
     echo -e "\n\n [+] (Building | Fetching) $BIN :: $SOURCE_URL\n"
      ##Build:
       pushd "$($TMPDIRS)" >/dev/null 2>&1
       docker stop "alpine-builder" 2>/dev/null ; docker rm "alpine-builder" 2>/dev/null
       docker run --privileged --net="host" --name "alpine-builder" "azathothas/alpine-builder:latest" \
        bash -c '
        #Setup ENV
         mkdir -p "/build-bins" && pushd "$(mktemp -d)" >/dev/null 2>&1
        #Install Deps
         curl -qfsSL "https://raw.githubusercontent.com/xplshn/pelf/master/pelf" -o "/usr/local/bin/pelf" && chmod +x "/usr/local/bin/pelf"
         apk update --no-interactive 2>/dev/null
         apk add "mpv" --latest --upgrade --no-interactive 2>/dev/null
        #Get Media
         #Icon
          apk info -L "mpv" | grep "share/icons.*\.png" | sort -n | head -n 1 | xargs -I {} realpath /{} | xargs -I {} sh -c "cp {} ./mpv.png"
         #Desktop
          apk info -L "mpv" | grep "share/.*\.desktop" | sort -n | head -n 1 | xargs -I {} realpath /{} | xargs -I {} sh -c "cp {} ./mpv.desktop"
          sed -e "s/^TryExec=.*/TryExec=mpv.AppBundle/" -e "s/^Exec=[^ ]*/Exec=mpv.AppBundle/" -i "./mpv.desktop"
        #Generate AppBundle
         pelf --main-bin "$(which mpv)" --output-to "/build-bins/mpv.AppBundle" \
         --add-metadata "$(find . -name "*.png" -exec realpath {} \; | head -n 1)" \
         --add-metadata "$(find . -name "*.desktop" -exec realpath {} \; | head -n 1)" \
         --add-ld-and-libc "$(find /lib -name "ld-musl*.so*" -exec realpath {} \; | head -n 1)" \
         "$(find /lib -name "libc*$(uname -m)*.so*" -exec realpath {} \; | head -n 1)"
         popd >/dev/null 2>&1
        '
      #Copy & Meta
       docker cp "alpine-builder:/build-bins/." "$(pwd)/"
       find "." -maxdepth 1 -type f -exec file -i "{}" \; | cut -d":" -f1 | xargs realpath
       #Meta
       find "." -maxdepth 1 -type f -exec sh -c 'file "{}"; du -sh "{}"' \;
       sudo rsync -av --copy-links --exclude="*/" "./." "$BINDIR"
      #Delete Containers
       docker stop "alpine-builder" 2>/dev/null ; docker rm "alpine-builder"
       popd >/dev/null 2>&1
fi
#-------------------------------------------------------#

#-------------------------------------------------------#
##Cleanup
unset SKIP_BUILD ; export BUILT="YES"
#In case of zig polluted env
unset AR CC CFLAGS CXX CPPFLAGS CXXFLAGS DLLTOOL HOST_CC HOST_CXX LDFLAGS LIBS OBJCOPY RANLIB
#In case of go polluted env
unset GOARCH GOOS CGO_ENABLED CGO_CFLAGS
#PKG Config
unset PKG_CONFIG_PATH PKG_CONFIG_LIBDIR PKG_CONFIG_SYSROOT_DIR PKG_CONFIG_SYSTEM_INCLUDE_PATH PKG_CONFIG_SYSTEM_LIBRARY_PATH
#-------------------------------------------------------#
xplshn commented 3 weeks ago

Do I close this issue?