#!/bin/bash ## script to fetch and build a module of yt-dlp ## by ncmprhnsbl @ forum.porteus.org ## version 20201126 . /usr/share/porteus/porteus-functions get_colors # Check for root if [ $(whoami) != "root" ]; then echo "Only root can run this." exit 1 fi # functions set work directory(default is /tmp) to current work directory set_tmp() { WRKDIR=/tmp } set_pwd() { WRKDIR=$(pwd) } set_tmp # set up fakeroot and set some variables # echo usage show_help() { echo " options: -d : do operations in the present directory, instead of /tmp . " echo " -h : show this usage. " } while getopts ":-d:-h:" o; do case "$1" in -d) set_pwd ;; -h) show_help exit 0 ;; *) show_help exit 1 ;; esac done case "$1" in "") set_tmp ;; esac PKG=yt-dlp [ ! -d $WRKDIR/$PKG/usr/bin ] && mkdir -p $WRKDIR/$PKG/usr/bin #[ ! -d $WRKDIR/$PKG/install ] && mkdir -p $WRKDIR/$PKG/install BUILD=$WRKDIR/$PKG BIND=$BUILD/usr/bin checksum() { if [ -z $CHOICE ]; then echo "Verifying download integrity.." echo "Server : $SUM1" echo "Download: $SUM2" if [ "$SUM1" = "$SUM2" ]; then echo "Download verified." else echo "Integrity check failed." cleanup fi fi } # tidy up after cleanup() { echo [ -d $BUILD ] && rm -rf $BUILD [ -f $WRKDIR/SHA2-256SUMS ] && rm $WRKDIR/SHA2-256SUMS [ -f $WRKDIR/deno-*.zip ] && rm $WRKDIR/deno-*.zip exit } trap cleanup SIGHUP SIGINT SIGTERM # set arch case $(uname -m) in x86_64) ARCH=x86_64 SUFFIX=64 SARCH=x86_64 ;; *) ARCH=i686 SUFFIX= SARCH=i586 ;; esac # i586 unsupported if [ $ARCH != "x86_64" ]; then echo "Sorry 32bit is no longer supported" exit 1 fi # tell us where the work will be done echo "Work will be done in: $txtgreen$WRKDIR$rst " echo echo "$txtgreen Note: now using yt-dlp instead of youtube-dl.$rst" echo #get version info SERVER=$(awk -F= '/SERVER=/{print$NF}' /etc/porteus.conf) VURL=https://github.com/yt-dlp/yt-dlp VER=$(lynx --dump --nonumbers https://github.com/yt-dlp/yt-dlp | grep "releases/tag" | awk -F"/" '{print$NF}') # download URL URL=$VURL/releases/download/$VER/yt-dlp_linux DURL=https://github.com/denoland/deno/releases/download/v2.5.6/deno-x86_64-unknown-linux-gnu.zip TAG=ncm REV=1 # check for installed version if [ $(which $PKG 2>/dev/null) ]; then IVER=$($PKG --version) echo "you have version $IVER installed" else echo "$PKG is not installed" fi # check installed version is up to date, if so offer escape. if [ "$VER" = "$IVER" ]; then read -p " You already have the latest version $txtgreen$CVER$rst. Do you still want to continue? [y/n]" -n 1 -r -s && echo [[ $REPLY =~ ^[Nn]$ ]] && cleanup fi # Get version on porteus server SERVER_LATFILE=$(lynx -dump --nonumbers --listonly $SERVER/$SARCH/current/modules | awk -F/ '/yt-dlp/{print$NF}' | tail -n1) SERVER_LATVER=$(awk -F- '{print$3}' <<<"${SERVER_LATFILE}") echo "Checking $SERVER/$SARCH/current/modules" # show all version information echo "The Porteus$txtgreen SERVER$rst version is :" $txtgreen "$SERVER_LATVER" $rst echo echo "The latest $PKG version is :" $txtgreen "$VER" $rst echo cyan "You can choose to download the premade module from our server," cyan "or download the version from github." echo read -p " Would you like to download the porteus server version? [y/n]" -n 1 -r -s && echo if [[ $REPLY =~ ^[Yy]$ ]]; then echo download $SERVER/$SARCH/current/modules/$SERVER_LATFILE $WRKDIR ## Check that we have a module in $WRKDIR if [ ! -f $WRKDIR/$SERVER_LATFILE ]; then echo sayerror "Download of the $PKG module failed." echo cleanup else echo echo "Your file is at:" $txtcyan "$WRKDIR/$SERVER_LATFILE" $rst echo "Please move it to your modules folder to survive a reboot." echo cleanup fi fi read -p " Would you like to download $txtgreen $PKG-$VER $rst ? [y/n]" -n 1 -r -s && echo if [[ ! $REPLY =~ ^[Yy]$ ]]; then cleanup fi # download the latest version download $URL $BIND # downdload deno and extract to $BIND [ ! -f $WRKDIR/deno*.zip ] && download $DURL $WRKDIR unzip $WRKDIR/deno*.zip -d $BIND/ ## Check that we have a binary in BIND if [ ! -f $BIND/${PKG}_linux ]; then echo sayerror "File $BIND/${PKG}_linux not found. Some went wrong with the download." cleanup fi ## Check integrity of downloaded tarball using sha256sum download $VURL/releases/download/$VER/SHA2-256SUMS $WRKDIR SUM1=$(grep yt-dlp_linux $WRKDIR/SHA2-256SUMS | head -n1 | cut -d" " -f1) SUM2=$(sha256sum $BIND/${PKG}_linux | cut -d" " -f1) checksum mv $BIND/${PKG}_linux $BIND/$PKG # make executable chmod +x $BIND/* cd $BUILD ### fake slackware type package info: super dumb version PKGINFO=var/lib/pkgtools/packages #FILES=`find *` mkdir -p $PKGINFO echo "PACKAGE NAME: $PKG-$VER-noarch-$REV$TAG" >$PKGINFO/$PKG-$VER-noarch-$REV$TAG # add slack-desc cat >>$PKGINFO/$PKG-$VER-noarch-$REV$TAG <>$PKGINFO/$PKG-$VER-noarch-$REV$TAG # make slackware pkg #cd $BUILD && makepkg -l n -c n $WRKDIR/$PKG-$VER-noarch-$REV$TAG.txz # make module #cd $WRKDIR && txz2xzm $PKG-$VER-noarch-$REV$TAG.txz cd $WRKDIR && dir2xzm $PKG $PKG-$VER-noarch-$REV$TAG.xzm echo "Your module $txtgreen $PKG-$VER-noarch-$REV$TAG.xzm $rst is ready in $WRKDIR " cyan "Please copy it to your modules folder or somewhere safe." cleanup