#!/bin/bash
#
#©K. D. Hedger. Tue 31 Jul 12:03:09 BST 2018 keithdhedger@gmail.com
#
#This file (LFSFunctions) is part of LFSMakePkg.
#
#LFSMakePkg is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation, either version 3 of the License, or
#at your option) any later version.
#
#Projects is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License
#along with LFSMakePkg. If not, see
.*
.*' | awk -F'
' '{print $2}'|awk -F'
' '{print $1}'|sed 's/|/\n/g') ;; "lfsdev" | "lfsstable") infodata=$(cat ${appname}.html | tr "\n" "|" | grep -o '.*'|awk -F'' '{printf $2}'|awk -F'
' '{print $1}'|sed 's/|/\n/g') ;; esac echo $infodata|sed 's/<[^<>]*>//g;s/\. /\.\n/g' return fi done for vers in "15.0" "14.2" "14.1" "14.0" "13.37" "13.1" do echo -e "${GREEN}Checking Slackbuilds version $vers for Info ...${NORMAL}" 1>&2 subpage=$(grep -i "SLACKBUILD LOCATION:[ ]*\./[[:alnum:]]*/${appname}$" "${vers}.txt" 2>/dev/null)||true if [ X"${subpage}" != "X" ];then subpage=${subpage#?*./} page="http://slackbuilds.org/slackbuilds/$vers/${subpage}/slack-desc" if [ ! -e ${appname}-info ];then wget $page -O ${appname}-info 2>/dev/null fi infodata=$(tail -n11 ${appname}-info|tr "\n" "|"|sed "s@${appname}:[ ]*@@Ig;s@[|][|]*@\n@g") echo "$infodata" return fi done echo -e "${RED}No info found ..." 1>&2 popd &>/dev/null } showwebpage () { local appname="$1" local page local subpage local infodata local vers pushd "${DATABASEFOLDER}" &>/dev/null for usepage in "blfsstable" "lfsstable" "blfsdev" "lfsdev" do page="" case $usepage in "blfsstable") echo -e "${GREEN}Checking BLFS (stable) for $appname version ...${NORMAL}" 1>&2 subpage=$(cat blfsindex1.html | grep -i "/${appname}.html"|sed -n 's/.*\(".*.html"\).*/\1/g;s/"//gp'|head -n1) if [ X${subpage} != "X" ];then page="https://www.linuxfromscratch.org/blfs/view/stable/${subpage}" fi ;; "lfsstable") echo -e "${GREEN}Checking LFS (stable) for $appname version ...${NORMAL}" 1>&2 subpage=$(cat lfsindex1.html | grep -i "/${appname}.html"|sed -n 's/.*\(".*.html"\).*/\1/g;s/"//gp'|head -n1) if [ X${subpage} != "X" ];then page="https://www.linuxfromscratch.org/lfs/view/stable/${subpage}" fi ;; "blfsdev") echo -e "${GREEN}Checking BLFS (development) for $appname version ...${NORMAL}" 1>&2 subpage=$(cat blfsindex0.html | grep -i "/${appname}.html"|sed -n 's/.*\(".*.html"\).*/\1/g;s/"//gp'|head -n1) if [ X${subpage} != "X" ];then page="https://www.linuxfromscratch.org/blfs/view/svn/${subpage}" fi ;; "lfsdev") echo -e "${GREEN}Checking LFS (development) for $appname version ...${NORMAL}" 1>&2 subpage=$(cat lfsindex0.html | grep -i "/${appname}.html"|sed -n 's/.*\(".*.html"\).*/\1/g;s/"//gp'|head -n1) if [ X${subpage} != "X" ];then page="https://www.linuxfromscratch.org/lfs/view/development/${subpage}" fi ;; esac if [ X"$page" != "X" ];then xdg-open "$page" return fi done for vers in "15.0" "14.2" "14.1" "14.0" "13.37" "13.1" do echo -e "${GREEN}Checking Slackbuilds version $vers for Info ...${NORMAL}" 1>&2 subpage=$(grep -i "SLACKBUILD LOCATION:[ ]*\./[[:alnum:]]*/${appname}$" "${vers}.txt" 2>/dev/null)||true if [ X"${subpage}" != "X" ];then subpage=${subpage#?*./} page="http://slackbuilds.org/slackbuilds/$vers/${subpage}" xdg-open "$page" return fi done echo -e "${RED}No info found ..." 1>&2 popd &>/dev/null } printversioninfo () { case $(checkversion $1 $2) in 1) echo -e "${BLUE}Package $3 may need updating to $1${NORMAL}" >&2 # echo "$4" ;; -1) echo -e "${RED}Package $3 build script version greater than documented version ???${NORMAL}" >&2 echo -e "${RED}Package $3 build script version=$2, documented version=$1${NORMAL}" >&2 ;; 0) echo -e "${GREEN}Package $3 version $2 is Ok ...${NORMAL}" >&2 ;; esac echo "$4" } checkforversion () { local appname local page local subpage local infodata local vers local packageversion local packages pushd "${DATABASEFOLDER}" &>/dev/null for packages in ${OPTS[@]} do appname=$packages for usepage in "lfsstable" "blfsstable" "15.0" "14.2" "14.1" "14.0" "13.37" "13.1" "lfsdev" "blfsdev" do case $usepage in "lfsstable") echo -e "${GREEN}Checking LFS (stable) for $appname version ...${NORMAL}" 1>&2 subpage=$(cat lfsindex1.html | grep -i "/${appname}.html"|sed -n 's/.*\(".*.html"\).*/\1/g;s/"//gp'|head -n1) if [ X${subpage} != "X" ];then page="http://www.linuxfromscratch.org/lfs/view/stable/${subpage}" fi ;; "blfsstable") echo -e "${GREEN}Checking BLFS (stable) for $appname version ...${NORMAL}" 1>&2 subpage=$(cat blfsindex1.html | grep -i "/${appname}.html"|sed -n 's/.*\(".*.html"\).*/\1/g;s/"//gp'|head -n1) if [ X${subpage} != "X" ];then page="http://www.linuxfromscratch.org/blfs/view/stable/${subpage}" fi ;; "lfsdev") echo -e "${GREEN}Checking LFS (development) for $appname version ...${NORMAL}" 1>&2 subpage=$(cat lfsindex0.html | grep -i "/${appname}.html"|sed -n 's/.*\(".*.html"\).*/\1/g;s/"//gp'|head -n1) if [ X${subpage} != "X" ];then page="http://www.linuxfromscratch.org/lfs/view/development/${subpage}" fi ;; "blfsdev") echo -e "${GREEN}Checking BLFS (development) for $appname version ...${NORMAL}" 1>&2 subpage=$(cat blfsindex0.html | grep -i "/${appname}.html"|sed -n 's/.*\(".*.html"\).*/\1/g;s/"//gp'|head -n1) if [ X${subpage} != "X" ];then page="http://www.linuxfromscratch.org/blfs/view/svn/${subpage}" fi ;; *) echo -e "${GREEN}Checking Slackbuilds version $usepage for $appname version ...${NORMAL}" 1>&2 linenumber=$(grep --line-number -i "SLACKBUILD NAME:[ ]*${appname}$" "${usepage}.txt"|awk -F: '{print $1}') if [ X$linenumber != "X" ];then vers=$(sed -n "$((linenumber+3))p" "${usepage}.txt"|awk -F: '{print $2}') infodata=$(sed -n "/name=${appname}/I,/Installed version=/p" "${DATABASE}") packageversion=$(echo "$infodata"|sed -n '2p'|awk -F= '{print $2}') printversioninfo $vers $packageversion $appname "$infodata" subpage=$(grep -i "SLACKBUILD LOCATION:[ ]*\./[[:alnum:]]*/${appname}$" "${usepage}.txt") subpage=${subpage#?*./} page="http://slackbuilds.org/repository/${usepage}/${subpage}/?search=${appname}" echo "More info here: $page" continue 2 fi ;; esac if [ X${page} != "X" ];then if [ ! -e ${appname}.html ];then wget $page -O ${appname}.html 2>/dev/null fi infodata=$(cat ${appname}.html|grep -i "\b$appname\b"|head -n1) vers=${infodata##?*-} infodata=$(sed -n "/name=${appname}$/I,/Installed version=/p" "${DATABASE}") packageversion=$(echo "$infodata"|sed -n '2p'|awk -F= '{print $2}') printversioninfo $vers $packageversion $appname "$infodata" continue 2 fi done echo -e "${RED}No version info for $appname found ...${NORMAL}" 1>&2 done popd &>/dev/null } packageclean () { local pkgname="$1" local scriptfolder="${2:-.}" local buildscript="$0" if [ -e "$scriptfolder/preinstall" ];then cp "$scriptfolder/preinstall" "$pkgname" fi if [ -e "$scriptfolder/postinstall" ];then cp "$scriptfolder/postinstall" "$pkgname" fi if [ -e "$scriptfolder/info" ];then cp "$scriptfolder/info" "$pkgname" fi cp "${scriptfolder}/${buildscript}" "${pkgname}/buildscript.txt" pushd "$pkgname" find "$pkgname" -iname "*.la" -exec rm '{}' \; || true find | xargs file | grep -e "executable" -e "shared object" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null || true rm -rf tmp if [ ${DELETEDOCS:-0} -eq 1 ];then find usr/share/locale/ -maxdepth 1 -mindepth 1 -type d -not -iname "${LANG%_?*}*" -exec rm -rf '{}' \; || true find usr/share/doc -delete || true find usr/share/man -delete || true find usr/share/info -delete || true find usr/share/gtk-doc -delete || true fi popd ldconfig||true } extractarchive () { local archive="$1" local what=$2 local comm="tar -xvf" local upname local resetperms=1 case $what in "zip") #resetperms=0 comm="unzip" ;; *) upname="${archive^^}" if [ "${upname##?*.}" = "ZIP" ];then #resetperms=0 comm=unzip fi ;; esac if [ $UID -eq 0 ];then # su -s "/bin/sh" nobody -c "$comm "$archive""//TODO// if [ $resetperms -eq 1 ];then perms=$(stat --format="%a" $(pwd)) $comm "$archive" chmod $perms $(pwd) else $comm "$archive" fi else $comm "$archive" fi } printBuildInfo () { find $ROOTDIR/var/lib/lfspkg/packages/ -type d -iname "${1}*"|while read do echo -e "${GREEN}Pkg info for $(basename ${REPLY})${NORMAL}" cat $REPLY/info 2>/dev/null||true if [ -e $REPLY/preinstall ];then echo echo -e "${GREEN}Pre Install${NORMAL}" cat $REPLY/preinstall 2>/dev/null||true fi if [ -e $REPLY/postinstall ];then echo echo -e "${GREEN}Post Install${NORMAL}" cat $REPLY/postinstall 2>/dev/null||true fi if [ -e $REPLY/buildscript.txt ];then echo echo -e "${GREEN}Build Script${NORMAL}" cat $REPLY/buildscript.txt 2>/dev/null||true fi echo done } searchinfos () { #tobe done : } findScriptFromWeb () { local pkg="${1%%-?*}" local htmlpage=/tmp/page$$.html local lfsversion local thelink ANYVERSION=1 lfspkg -Z 3 "$pkg" #lfs for lfsversion in "stable" "svn" do curl "https://www.linuxfromscratch.org/blfs/view/stable/longindex.html" 2>/dev/null > $htmlpage startline=$(grep -n 'id="program-index"' $htmlpage|awk -F: '{print $1}') hrefs=$(sed -n "$startline,\$p" $htmlpage |grep "$pkg.*:" -A 4|sed -n "s@.*href=\"\([^\"]*\).*@http://www.linuxfromscratch.org/blfs/view/$lfsversion/\1@p"|grep -v "#"|sort -u) if [ "X$hrefs" = "X" ];then hrefs=$(sed -n "$startline,\$p" $htmlpage |grep -i "$pkg.*:" -A 4|sed -n "s@.*href=\"\([^\"]*\).*@http://www.linuxfromscratch.org/blfs/view/$lfsversion/\1@p"|grep -v "#"|sort -u) fi if [ "X$hrefs" = "X" ];then echo "Nothing at linuxfromscratch $lfsversion .." else for arg in $hrefs do echo "${arg}" done fi done rm $htmlpage #sbo search for sboversion in "15.0" "14.2" "14.1" "14.0" "13.37" "13.1" do curl "https://slackbuilds.org/result/?search=$pkg&sv=$sboversion" 2> /dev/null > $htmlpage if ! grep "No results" $htmlpage &>/dev/null;then echo "https://slackbuilds.org/result/?search=$pkg&sv=$sboversion" else echo "Nothing at SBO $sboversion .." fi done rm $htmlpage #slackware search for sboversion in "15.0" "14.2" "14.1" "14.0" "13.37" "13.1" do curl -L "https://mirrors.slackware.com/slackware/slackware-$sboversion/source/FILE_LIST" 2>/dev/null >$htmlpage thelink=$(grep "${pkg}.SlackBuild" $htmlpage |head -n1|awk '{print $NF}') if [ "$thelink" != "" ];then echo "https://mirrors.slackware.com/slackware/slackware-$sboversion/source/$thelink" else echo "Nothing at slackware $sboversion .." fi done rm $htmlpage #arch search curl "https://archlinux.org/packages/?sort=&q=$pkg&maintainer=&flagged=" 2>/dev/null >$htmlpage if ! grep "No matching packages found" $htmlpage &>/dev/null;then echo "https://archlinux.org/packages/?sort=&q=$pkg&maintainer=&flagged=" else echo "Nothing at arch .." fi rm $htmlpage }