#!/bin/bash # Magellan Linux Installer Functions (mage.functions.sh) # version: 0.3.1 mage_setup() { install -d $INSTALLDB } fatal_error() { #$1 is the missing file echo -e "\nFatal Error: Package seemed to be corrupt." echo -e "$1 was not found in ${PKGNAME}" exit 1 } build_unpackpkg() { tar xjmf ${PKGDIR}/${PKGNAME}.${PKGSUFFIX} -C ${BUILDDIR} } build_doinstall() { if [ -e ${BUILDDIR}/${PKGNAME}/.dirs ] then # install of dirs while read pathto posix do if [ ! -z $pathto ] then if [ "$VERBOSE" == "on" ] then echo -e "\t>>> DIR: $pathto" fi install -m $posix -d $pathto fi done << EOF $(cat ${BUILDDIR}/${PKGNAME}/.dirs) EOF else fatal_error .dir fi # install of files if [ -e ${BUILDDIR}/${PKGNAME}/.files ] then while read pathto posix user group do if [ ! -z $pathto ] then if [ "$VERBOSE" == "on" ] then echo -e "\t>>> FILE: $pathto" fi ### kleiner notfall fix ### if [ ! -d `dirname $pathto` ] then install -d `dirname $pathto` fi FILE="$pathto" install -m $posix ${BUILDDIR}/${PKGNAME}/binfiles/$FILE $pathto if [ ! -z $user ] then chown $user:$group $FILE ### <---- test fi fi done << EOF $(cat ${BUILDDIR}/${PKGNAME}/.files) EOF else fatal_error .files fi # install of symlinks if [ -e ${BUILDDIR}/${PKGNAME}/.symlinks ] then while read pathto posix link do if [ ! -z $pathto ] then if [ "$VERBOSE" == "on" ] then echo -e "\t>>> LINK: $pathto" fi ln -snf $link $pathto fi done << EOF $(cat ${BUILDDIR}/${PKGNAME}/.symlinks) EOF else fatal_error .symlinks fi if [ -e ${BUILDDIR}/${PKGNAME}/.pipes ] then # install of pipes while read pathto posix do if [ ! -z $pathto ] then if [ "$VERBOSE" == "on" ] then echo -e "\t>>> PIPE: $pathto" fi mkfifo -m $posix $pathto fi done << EOF $(cat ${BUILDDIR}/${PKGNAME}/.pipes) EOF else fatal_error .pipes fi if [ -e ${BUILDDIR}/${PKGNAME}/.char ] then # install of character devices while read pathto posix do if [ ! -z $pathto ] then if [ "$VERBOSE" == "on" ] then echo -e "\t>>> CHAR: $pathto" fi mknode -m $posix -c $pathto fi done << EOF $(cat ${BUILDDIR}/${PKGNAME}/.char) EOF else fatal_error .char fi #add package to database install -d ${INSTALLDB}/${PKGNAME} cp ${BUILDDIR}/${PKGNAME}/.{char,dirs,files,pipes,symlinks} ${INSTALLDB}/${PKGNAME} #installs mage file to database #install -m 0644 -o root -g root \ # ${MAGEDIR}/${MAGENAME} \ # ${INSTALLDB}/${PKGNAME} install -m 0644 -o root -g root \ ${MAGEFILE} \ ${INSTALLDB}/${PKGNAME} if [ "$VERBOSE" == "off" ] then if [ -f /var/tmp/proz ] then rm /var/tmp/proz fi fi } build_douninstall() { #uninstall of symlinks if [ -e ${INSTALLDB}/${PKGNAME}/.symlinks ] then while read pathto posix link do if [ ! -z $pathto ] then if [ -L $pathto ] then echo -e "\t<<< LINK: $pathto" rm $pathto else echo -e "${COLRED}! exist${COLDEFAULT} <<< LINK: $pathto" fi fi done << EOF $(cat ${INSTALLDB}/${PKGNAME}/.symlinks) EOF else fatal_error .symlinks fi #uninstall of files if [ -e ${INSTALLDB}/${PKGNAME}/.files ] then while read pathto posix user group do if [ ! -z $pathto ] then if [ -e $pathto ] then echo -e "\t<<< FILE: $pathto" rm $pathto else echo -e "${COLRED}! exist${COLDEFAULT} <<< FILE: $pathto" fi fi done << EOF $(cat ${INSTALLDB}/${PKGNAME}/.files) EOF else fatal_error .files fi if [ -e ${INSTALLDB}/${PKGNAME}/.pipes ] then while read pathto posix do if [ ! -z $pathto ] then echo -e "\t<<< PIPE: $pathto" rm $pathto fi done << EOF $(cat ${INSTALLDB}/${PKGNAME}/.pipes) EOF else fatal_error .pipes fi if [ -e ${INSTALLDB}/${PKGNAME}/.char ] then while read pathto posix do if [ ! -z $pathto ] then echo -e "\t<<< CHAR: $pathto" rm $pathto fi done << EOF $(cat ${INSTALLDB}/${PKGNAME}/.char) EOF else fatal_error .char fi #uninstall of dirs ## added small hack to fix dirs # must be reverse -> smage2 doesn't sort them if [ -e ${INSTALLDB}/${PKGNAME}/.dirs ] then while read pathto posix do if [ ! -z $pathto ] then if [ -e $pathto ] then echo -e "\t<<< DIR: $pathto" rmdir $pathto &> /dev/null if [ "$?" -ne "0" ] then #moves the cursor up echo -en \\033[A echo -e "${COLRED}! empty${COLDEFAULT} <<< DIR: $pathto" fi else echo -e "${COLRED}! exist${COLDEFAULT} <<< DIR: $pathto" fi fi done << EOF $(cat ${INSTALLDB}/${PKGNAME}/.dirs|sort -r) ##<--- the hack EOF else fatal_error .dirs fi #removes database entry if [ -d ${INSTALLDB}/${PKGNAME} ] then rm -rf ${INSTALLDB}/${PKGNAME} fi } getpackages() { if [ -z "$MIRRORS" ] then echo "You have no mirrors defined. Please edit your /etc/mage.rc." exit 1 fi local i for i in $MIRRORS do wget \ --passive-ftp \ --tries 3 \ --continue \ --progress bar \ --directory-prefix=${PKGDIR} \ ${i}/packages/${PKGNAME}.${PKGSUFFIX} if [ "$?" == "0" ] then break else continue fi done } syncmage() { if [ -z "$RSYNC" ] then echo "You have no rsync-mirrors defined. Please edit your /etc/mage.rc." exit 1 fi local i for i in $RSYNC do rsync \ --recursive \ --links \ --perms \ --times \ --devices \ --timeout=600 \ --verbose \ --compress \ --progress \ --stats \ --delete \ --delete-after \ $i $MAGEDIR if [ "$?" == "0" ] then break else continue fi done } cleanpkg(){ if [ -d "$PKGDIR" ] then echo -n "Removing downloaded packages... " rm -rf ${PKGDIR}/* echo "done." fi } ################################################### # function keepfiles # # keepfiles "$CATEGORIE/$PNAME" "$filename" # # note wildchars allowed # ################################################### keepfiles() { local name local keep name="`echo $1| cut -d '/' -f2`" keep="$2" DELPKG="`find ${INSTALLDB} -name ${name}*.mage`" DELDIR="${INSTALLDB}/$(basename ${DELPKG} .mage)" cp ${DELDIR}/.files ${DELDIR}/.files-orig sed "s:${keep}::" \ ${DELDIR}/.files-orig > ${DELDIR}/.files rm ${DELDIR}/.files-orig } ################################################### # function injectpkg # # injectpkg "$CATEGORIE/$PNAME" # # note wildchars allowed # ################################################### injectpkg() { local name local categorie local magename name="`echo $1| cut -d '/' -f2`" categorie="`echo $1| cut -d '/' -f1`" INJPKG="`find ${MAGEDIR} -name ${name}-*.mage`" for i in ${INJPKG} do magename="$(basename ${INJPKG} .mage)" echo -e "Injecting fake package for ${COLBLUE}${categorie}${COLDEFAULT}/${COLGREEN}${magename}${COLDEFAULT}" install -d ${INSTALLDB}/${magename} touch ${INSTALLDB}/${magename}/{.injected,.files,.dirs,.symlinks,.pipes,.char} #installs magefile install -m 0644 -o root -g root \ ${MAGEDIR}/${categorie}/${magename}.mage \ ${INSTALLDB}/${magename} done } ################################################### # function reminjected # # reminjected # # note: removes all injected packages # ################################################### reminjected() { DELINJ="`find ${INSTALLDB} -name .injected`" for i in ${DELINJ} do magename=$(dirname ${i}) if [ -d "${magename}" ] then # small fix to protect the mage-db deleting itself, that is not so funny :) if [ "${magename}" != "${INSTALLDB}" ] then echo -e "removing fake package ${COLRED}${magename#${INSTALLDB}/*}${COLDEFAULT}" rm -rf ${magename} fi fi done }