#!/bin/bash ## script to fetch and build a module of youtube-dl ## 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 PKG=youtube-dl [ ! -d $WRKDIR/$PKG/usr/bin ] && mkdir -p $WRKDIR/$PKG/usr/bin #[ ! -d $WRKDIR/$PKG/install ] && mkdir -p $WRKDIR/$PKG/install BUILD=$WRKDIR/$PKG BIND=$WRKDIR/$PKG/usr/bin # 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 checksum () { if [ -z $CHOICE ]; then printf "Verifying download integrity.." printf "Server : $SUM1" printf "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 exit } trap cleanup SIGHUP SIGINT SIGTERM # tell us where the work will be done echo "Work will be done in: $txtgreen$WRKDIR$rst " case `uname -m` in x86_64) ARCH=x86_64 SUFFIX=64 SARCH=x86_64 ;; *) ARCH=i686 SUFFIX= SARCH=i586 ;; esac #get version info SERVER=`awk -F= '/SERVER=/{print$NF}' /etc/porteus.conf` VURL=http://ytdl-org.github.io/$PKG/download.html VER=$(lynx --dump --nonumbers $VURL | grep "(sig)" | awk -F" " '{print $1}') # download URL URL=https://yt-dl.org/downloads/$VER/$PKG 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]$ ]] && exit 0 fi # Get version on porteus server SERVER_LATFILE=`lynx -dump --nonumbers --listonly $SERVER/$SARCH/current/modules | awk -F/ '/youtube/{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 ## Check that we have a binary in BIND if [ ! -f $BIND/$PKG ]; then echo sayerror "File $BIND/$PKG not found. Some went wrong with the download." cleanup fi ## Check integrity of downloaded tarball using sha256sum SUM1=$(lynx --dump --nonumbers $VURL | grep -A 1 "SHA256:" | tail -n1 | awk -F" " '{print$NF}') SUM2=$(sha256sum $BIND/$PKG | cut -d" " -f1) checksum # make executable chmod +x $BIND/$PKG 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 << EOM PACKAGE DESCRIPTION: youtube-dl: youtube-dl (YouTube video download utility) youtube-dl: youtube-dl: youtube-dl is a small command-line program to download videos youtube-dl: from YouTube.com. It's licensed under the MIT License. youtube-dl: youtube-dl: Homepage: http://www.yt-dl.org/ youtube-dl: youtube-dl: youtube-dl: youtube-dl: youtube-dl: FILE LIST: EOM find * | grep -v var >> $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