#!/bin/sh # Magellan Linux Installer (mage.sh) # version: 0.3.1 ##configuration -> mage.rc #PKGDIR="/usr/src/packages" PKGSUFFIX="mpk" #BUILDDIR="/usr/src" #INSTALLDB="/var/ALXInstDB" #MAGEDIR="/usr/src/mage-0.2" MAGENAME="$2" #PKGNAME="`basename $2 .mage`" MLIBDIR=/usr/lib/mage ## nur für tests -> normalerweise in /etc/rc.d/init.d/functions COLRED="\033[1;6m\033[31m" COLGREEN="\033[1;6m\033[32m" COLBLUE="\033[1;6m\033[34m" COLDEFAULT="\033[0m" ##functions if [ -f /etc/mage.rc ] then source /etc/mage.rc else echo "Your /etc/mage.rc is missing. Aborting." exit 1 fi #loads functions source ${MLIBDIR}/mage3.functions.sh #############DIALOGE############## print_usage(){ echo -e "\nUsage: $0 [option] pkgname ..." echo "Options:" echo -e "\tpretend - pretend package's depencies" echo -e "\tinstall - installs package" echo -e "\tuninstall - removes package" echo -e "\tupdate - updates pkg database" echo -e "\tclean - removes downloaded packages" echo -e "\tunpack - unpacks package" echo -e "\tdownload - downloads package" echo -e "\tkeepfiles - prevents files from uninstalling" echo -e "\tinject - inject a package to fake depencies" echo -e "\treminjected - removes *all* fake packages" echo } xtitle() { if [ ${TERM} == "xterm" ] then echo -ne "\033]0;Mage: $1\007" fi return 0 } xtitleclean() { if [ ${TERM} == "xterm" ] then echo -ne "\033]0;\007" fi return 0 } spin_processbar() { echo -en "Processing: " while [ -f /var/tmp/proz ] do echo -en "-\b" sleep 0.01 echo -en "\\ \b\b" sleep 0.01 echo -en "|\b" sleep 0.01 echo -en "/\b" sleep 0.01 done echo "done" return 0 } #cuts full pathnames or versioniezed names down to basename choppkgname(){ #we want this only if full name was used if [ -n "$(echo ${MAGENAME}|fgrep .mage)" ] then #cuts ARCH and PBUILD #ARCH comes from /etc/mage.rc MAGENAME=$(echo ${MAGENAME} |sed -e "s:-${ARCH}-r*.::g") #cuts version number MAGENAME=$(basename ${MAGENAME%-*} .mage) fi } # get_categorie $PKGNAME, returns CATEGORIE # ret 0=ok, 1=not_found getcategorie(){ for CAT in ${MAGEDIR}/* do if [ -d ${CAT}/${MAGENAME} ] then #debug only if [ "$MAGEDEBUG" == "on" ] then echo "$MAGENAME found -> $CAT/$MAGENAME" echo "categorie = $(basename ${CAT})" fi CATEGORIE=$(basename ${CAT}) fi done #package does not exists if [ -z "$CATEGORIE" ] then echo -e "Package "${COLRED}"\"${MAGENAME}\""${COLDEFAULT}" does not exists." exit 1 fi } #check_stable_package /path/to/foo.mage # returns 0=stable 1=unstable check_stable_package(){ #be sure no previous $STATES exists unset STATE source $1 if [ "${STATE}" != "stable" ] then return 1 fi #unset the sourced varibales; #we'll got bad problems later on if we don't do this unset PKGNAME unset STATE unset DESCRIPTION unset HOMEPAGE unset DEPEND unset preinstall unset postinstall return 0 } #get_highest_magefile ${CATEGORIE} ${PKGNAME} #fake at moment returns only stable pkgs (must set to be one) # return $HIGHEST_MAGEFILE get_highest_magefile(){ unset HIGHEST_MAGEFILE #CATEGORIE=$1 #PKGNAME=$2 for i in ${MAGEDIR}/${CATEGORIE}/${MAGENAME}/* do #we exclude subdirs (for stuff like a md5sum dir) if [ ! -d ${i} ] then check_stable_package ${i} if [ "$?" == "0" ] then HIGHEST_MAGEFILE=${i} #for debug only if [ "$MAGEDEBUG" == "on" ] then echo "HIGHEST_MAGEFILE=${HIGHEST_MAGEFILE}" fi fi fi done MAGEFILE=${HIGHEST_MAGEFILE} return 0 } mage_install_virtual(){ echo -e "\nInstallation of Package: ${COLGREEN}$PKGNAME${COLDEFAULT}\n" export -f preinstall 2> /dev/null if [ "$?" == "0" ] then echo -e "\nRunning Preinstall ... \n" preinstall unset preinstall fi #creates fake db entry install -d ${INSTALLDB}/${PKGNAME} touch ${INSTALLDB}/${PKGNAME}/.virtual #fake file-descriptors touch ${INSTALLDB}/${PKGNAME}/.dirs touch ${INSTALLDB}/${PKGNAME}/.symlinks touch ${INSTALLDB}/${PKGNAME}/.files touch ${INSTALLDB}/${PKGNAME}/.pipes touch ${INSTALLDB}/${PKGNAME}/.char #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} export -f postinstall 2> /dev/null if [ "$?" == "0" ] then echo -e "\nRunning Postinstall ... \n" postinstall unset postinstall fi ${MLIBDIR}/env-rebuild.sh echo -e "\nPackage \"$PKGNAME\" sucessfully installed.\n" #unsets virtual state of packages unset PKGTYPE exit 0 } mage_install() { local MAGEFILE MAGEFILE=$1 source ${MAGEFILE} #abbruch wenn schon installiert if [ -e ${INSTALLDB}/${PKGNAME} ] then echo -e "\n${COLRED}Package \"$PKGNAME\" already installed. Installation Aborted.${COLDEFAULT}\n" exit 3 fi xtitle "[ Installing ${PKGNAME} ]" if [ "${PKGTYPE}" == "virtual" ] then mage_install_virtual fi if [ ! -e ${PKGDIR}/${PKGNAME}.${PKGSUFFIX} ] then echo -e "\nPrefetching needed Packages for ${COLGREEN}${PKGNAME}${COLDEFAULT}...\n" getpackages fi echo -e "\nInstallation of Package: ${COLGREEN}$PKGNAME${COLDEFAULT}\n" ( build_unpackpkg ) | echo -e "Unpacking Package ...\n" ##preinstall scripte export -f preinstall 2> /dev/null if [ "$?" == "0" ] then echo -e "\nRunning Preinstall ... \n" preinstall unset preinstall fi #install of package if [ "$VERBOSE" == "off" ] then touch /var/tmp/proz build_doinstall|spin_processbar fi if [ "$VERBOSE" == "on" ] then build_doinstall fi #postinstall scripte export -f postinstall 2> /dev/null if [ "$?" == "0" ] then echo -e "\nRunning Postinstall ... \n" postinstall unset postinstall fi #cleanup if [ -d ${BUILDDIR}/${PKGNAME} ] then rm -rf ${BUILDDIR}/${PKGNAME} fi #rebuilds the enviroment with the content of /etc/env.d ${MLIBDIR}/env-rebuild.sh xtitleclean echo -e "\nPackage \"$PKGNAME\" sucessfully installed.\n" } mage_uninstall() { # #installdbhome #packagedir #magefile source ${INSTALLDB}/$(basename ${MAGENAME} .mage)/$(basename ${MAGENAME}) if [ ! -e ${INSTALLDB}/${PKGNAME} ] then echo -e "\nPackage \"$PKGNAME\" is not installed. Uninstallation Aborted.\n" exit 3 fi echo -e "\nUninstall of Package:\t${COLRED}$PKGNAME${COLDEFAULT}\n" if [ -z "${MAGE_UNINSTALL_TIMEOUT}" ] then MAGE_UNINSTALL_TIMEOUT=5 fi for ((i=0; i < MAGE_UNINSTALL_TIMEOUT; i++)) do timeout=$(expr ${MAGE_UNINSTALL_TIMEOUT} - ${i}) echo -e "Starting in ${COLRED} ${timeout}" \ "${COLDEFAULT} seconds ... ( [CTRL+C] to abort )" sleep 1 #moves the cursor up echo -en \\033[A done #moves the cursor up echo -en \\033[A #min. 30 spaces needed for clearing up the rest of the line echo -e "\nUninstall ${COLRED}started${COLDEFAULT} ..." \ " \n" sleep 1 build_douninstall #rebuilds the enviroment with the content of /etc/env.d ${MLIBDIR}/env-rebuild.sh echo -e "\nPackage \"$PKGNAME\" sucessfully removed.\n" } case "$1" in download) choppkgname getcategorie get_highest_magefile source ${MAGEFILE} getpackages ;; pretend) choppkgname getcategorie get_highest_magefile ${MLIBDIR}/depwanderer.sh pretend ${MAGEFILE} ;; install) choppkgname getcategorie get_highest_magefile ALLDEPS="$(/usr/lib/mage/depwanderer.sh install ${MAGEFILE})" for i in ${ALLDEPS} do mage_install ${i} done ;; uninstall) mage_uninstall ;; unpack) build_unpackpkg ;; update) syncmage ;; clean) cleanpkg ;; keepfiles) keepfiles "$2" "$3" ;; inject) injectpkg "$2" ;; reminjected) reminjected ;; *) print_usage ;; esac