#!/bin/sh # Magellan Linux Installer (mage.sh) # version: 0.3.6-r13 ##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 MAGEVERSION=0.3.6-r13 ## 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" # default path PATH="${PATH}:${MLIBDIR}" ##functions if [ -f /etc/mage.rc ] then source /etc/mage.rc else echo "Your /etc/mage.rc is missing. Aborting." exit 1 fi #virtualdb locations VIRTUALDB_DEFAULTS=/etc/mage-profile/virtuals.defaults VIRTUALDB_FILE=${INSTALLDB}/virtuals #fix small problems [ ! -e ${VIRTUALDB_FILE} ] && touch ${VIRTUALDB_FILE} if [ ! -e ${VIRTUALDB_DEFAULTS} -a "$1" != "update" ] then echo echo "Please choose an profile from the mage tree." echo "ln -snf ${MAGEDIR}/profiles/profilename /etc/mage-profile" exit 1 fi #loads functions source ${MLIBDIR}/mage3.functions.sh #############DIALOGE############## showversion() { echo -en "Magellan Package Manager v${MAGEVERSION} " echo -e "-- Niels Rogalla (niro@magellan-linux.de)" } print_usage(){ showversion echo -e "\nUsage: (basename $0) [option] pkgname ..." echo "Options:" echo -e "\tpretend - pretends dependencies of a package" echo -e "\tsrcpretend - pretends dependencies of a package (build from source)" echo -e "\tinstall - installs a package" echo -e "\tsrcinstall - installs a package from source" echo -e "\tuninstall - removes a package" echo -e "\tupdate - updates mage-tree" echo -e "\tsearch - searches mage-tree for a package" echo -e "\tclean - removes *all* downloaded packages" echo -e "\tunpack - unpacks a package" echo -e "\tdownload - downloads a package" echo -e "\tkeepfiles - prevents files from uninstalling" echo -e "\tinject - inject a package to fake dependencies" echo -e "\treminjected - removes *all* fake packages" echo -e "\tversion - prints version info" echo echo -e "Other:" echo -e "NOINSTALL=yes $(basename $0) srcinstall PACKAGE" echo -e "Builds a Package with its dependencies, but won't install anything." echo echo -e "BOOTSTRAP=yes $(basename $0) srcinstall PACKAGE" echo -e "Force an bootstrap build for a Package." echo -e "Works only for packages wich take use of that (like glibc and binutils)," echo -e "by any other this feature will simple be ignored." echo echo -e "USE_UNSTABLE=true $(basename $0) [src]install PACKAGE" echo -e "Overrides stable packages; you can install packages that are marked unstable." echo } run_etc_update() { if [ ${PROTECT_COUNT} -eq 0 ] then return 0 fi echo echo "Important:" echo "${PROTECT_COUNT} protected file(s) were installed." echo echo "Please run 'etc-update' to update your configuration files." echo } 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_database_entry ${PKGNAME} ${PKGTYPE} export -f postinstall 2> /dev/null if [ "$?" == "0" ] then echo -e "\nRunning Postinstall ... \n" postinstall unset postinstall fi #check for virtuals and PROVIDE # if so install it to virtualdb register_virtual_pkg ${MLIBDIR}/env-rebuild.sh echo -e "\nPackage '${PKGNAME/-${ARCH}/}' sucessfully installed.\n" #unsets virtual state of packages unset PKGTYPE return 0 } register_virtual_pkg(){ #first check if this pkg is an virtual_pkg #echo "DEB: PKGNAME=${PKGNAME}" if [ -e ${BUILDDIR}/virtuals/virtuals.${PKGNAME/-${ARCH}/} ] then #add it source ${BUILDDIR}/virtuals/virtuals.${PKGNAME/-${ARCH}/} virtuals_add ${DB_VIRTUAL_NAME} ${DB_PKG_NAME} #than clean up unset DB_VIRTUAL_NAME DB_PKG_NAME rm ${BUILDDIR}/virtuals/virtuals.${PKGNAME/-${ARCH}/} fi if [ -n "${PROVIDE}" ] then local my_pgk #cut arch my_pkg=${PKGNAME/-${ARCH}/} #cut version & build my_pkg=${my_pkg%-*-*} virtuals_add ${PROVIDE} ${CATEGORIE}/${my_pkg} unset PROVIDE fi } unregister_virtual_pkg(){ if [ -n "${PROVIDE}" ] then local my_pgk local my_cat local directory local x #cut arch my_pkg=${PKGNAME/-${ARCH}/} #cut version & build my_pkg=${my_pkg%-*-*} my_cat=$(dirname ${my_pkg}) #check if this was the last one or if any other exists for directory in ${INSTALLDB}/${my_cat}/* do # continue if not a directory, # or the same PNAME-PVER-PBUILD if [ ! -d "${directory}" ] then continue fi #check if $directory is the same as $my_pkg x=$(basename ${directory}) if [[ ${my_cat}/${x%-*-*} = ${my_pkg} ]] then # break here echo "==== another version of ${my_pkg} exists, not deleting ${VIRTUAL_NAME} ..." return 0 fi done #virtuals_del ${PROVIDE} ${CATEGORIE}/${my_pkg} #my_pkg has already the categorie -> ex my_pkg=x11-base/xfree virtuals_del ${PROVIDE} ${my_pkg} unset PROVIDE fi } mage_install_sources() { #creates fake db entry install_database_entry ${PKGNAME} ${PKGTYPE} #check for virtuals and PROVIDE # if so install it to virtualdb register_virtual_pkg echo echo -e "This Package is a Source Package." echo echo -e "Only 'srcinstall' works with this type of packages" echo -en "If you have done a srcinstall before, " echo -e "you will find the files in /usr/src." echo #nice timer (4 seconds) # local x # declare -i x=4 # echo -en "Continues in 4s ..." # while [ ${x} -gt 0 ] # do # i=${x}+1 # echo -en "\b\b\b\b\b\b${x}s ..." # #beeper # echo -en "\a" # sleep 1 # done # echo sleep 1 xtitleclean } mage_install() { local MAGEFILE local PKGTARBALL MAGEFILE=$1 source ${MAGEFILE} #abbruch wenn schon installiert if [ -e ${INSTALLDB}/${PKGNAME/-${ARCH}/} ] then echo -en "\n${COLRED}Package '${PKGNAME/-${ARCH}/}'" \ echo -e "already installed. Installation Aborted.${COLDEFAULT}\n" exit 3 fi xtitle "[ Installing ${PKGNAME/-${ARCH}/} ]" if [ "${PKGTYPE}" == "virtual" ] then mage_install_virtual return 0 fi if [ "${PKGTYPE}" == "sources" ] then mage_install_sources return 0 fi if [ ! -e ${PKGDIR}/${PKGNAME}.${PKGSUFFIX} ] then echo -en "\nPrefetching needed Packages for " echo -e "${COLGREEN}${PKGNAME/-${ARCH}/}${COLDEFAULT}...\n" getpackages fi echo -e "\nInstallation of Package: ${COLGREEN}${PKGNAME/-${ARCH}/}${COLDEFAULT}\n" #( build_unpackpkg ) | echo -e "Unpacking Package ...\n" echo -en "Unpacking Package ..." build_unpackpkg echo "done" ##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 #spinner disabled #touch /var/tmp/proz #build_doinstall|spin_processbar echo -en "Processing ... " build_doinstall ${PKGNAME} echo "done" fi if [ "$VERBOSE" == "on" ] then #build_doinstall build_doinstall ${PKGNAME} fi #postinstall scripte export -f postinstall 2> /dev/null if [ "$?" == "0" ] then echo -e "\nRunning Postinstall ... \n" postinstall unset postinstall fi #install database entry install_database_entry ${PKGNAME} #cleanup if [ -d ${BUILDDIR}/${PKGNAME} ] then rm -rf ${BUILDDIR}/${PKGNAME} fi #check for virtuals and PROVIDE # if so install it to virtualdb register_virtual_pkg #update mtimes of packages and db_entries update_mtime #rebuilds toplevel info node echo -en "\n>>>> Rebuilding top-level info node ... " ${MLIBDIR}/mkinfodir /usr/share/info > /usr/share/info/dir \ && echo "done" || echo "false" #rebuilds the enviroment with the content of /etc/env.d ${MLIBDIR}/env-rebuild.sh xtitleclean echo -e "\nPackage '${PKGNAME/-${ARCH}/}' sucessfully installed.\n" } mage_uninstall() { # #installdbhome #packagedir #magefile #source ${INSTALLDB}/$(basename ${MAGENAME} .mage)/$(basename ${MAGENAME}) #source ${INSTALLDB}/${CATEGORIE}/$(basename ${MAGENAME} .mage)/$(basename ${MAGENAME}) local UNINST_MAGEFILE CAT_PKGNAME CAT_PKGNAME=$1 #trim pkgname from CAT_PKGNAME to get magefile name UNINST_MAGEFILE="$(echo ${CAT_PKGNAME}| cut -d / -f2).mage" #then source it source ${INSTALLDB}/${CAT_PKGNAME}/${UNINST_MAGEFILE} #fix for mage-0.3.6-r5 #PKGNAME=${PKGNAME/-${ARCH}/} PKGNAME=${CAT_PKGNAME} #if [ ! -e ${INSTALLDB}/${PKGNAME/-${ARCH}/} ] if [ ! -e ${INSTALLDB}/${CAT_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 ##preremove scripte export -f preremove 2> /dev/null if [ "$?" == "0" ] then echo -e "\nRunning Preremove ... \n" preremove unset preremove fi #runs uninstall build_douninstall ${PKGNAME} #postremove scripte export -f postremove 2> /dev/null if [ "$?" == "0" ] then echo -e "\nRunning Postremove ... \n" postremove unset postremove fi #remove database entry remove_database_entry ${PKGNAME} #check for PROVIDE # if so uninstall it from virtualdb unregister_virtual_pkg #rebuilds toplevel info node echo -en "\n>>>> Rebuilding top-level info node ... " ${MLIBDIR}/mkinfodir /usr/share/info > /usr/share/info/dir \ && echo "done" || echo "false" #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 || exit 1 source ${MAGEFILE} getpackages ;; pretend) choppkgname getcategorie get_highest_magefile || exit 1 ${MLIBDIR}/depwanderer.sh pretend ${MAGEFILE} #abort already installed if [ "$?" == "3" ] then echo -en "Package " echo -en "${COLRED}$(basename ${MAGEFILE} .mage)${COLDEFAULT}" echo -e " already installed." fi ;; srcpretend) choppkgname getcategorie get_highest_magefile || exit 1 ${MLIBDIR}/depwanderer.sh srcpretend ${MAGEFILE} #abort already installed if [ "$?" == "3" ] then echo -en "Package " echo -en "${COLRED}$(basename ${MAGEFILE} .mage)${COLDEFAULT}" echo -e " already installed." fi ;; install) #counter for protected files declare -i PROTECT_COUNT=0 choppkgname getcategorie get_highest_magefile || exit 1 ALLDEPS="$(/usr/lib/mage/depwanderer.sh install ${MAGEFILE})" #abort already installed if [ "$?" == "3" ] then echo -en "Package " echo -en "${COLRED}$(basename ${MAGEFILE} .mage)${COLDEFAULT}" echo -e " already installed." echo -e "Installation aborted." exit 0 fi for i in ${ALLDEPS} do #first unset all vars to be safe unset PKGNAME unset STATE unset DESCRIPTION unset HOMEPAGE unset DEPEND unset SDEPEND unset PROVIDE unset PKGTYPE unset preinstall unset postinstall #then source an evtl new generated profile [ -e /etc/profile ] && source /etc/profile #than install MY_CAT_FIX="$(dirname ${i})" CATEGORIE="$(basename ${MY_CAT_FIX%/*})" mage_install ${i} done run_etc_update ;; srcinstall) #counter for protected files declare -i PROTECT_COUNT=0 choppkgname getcategorie get_highest_magefile || exit 1 ALLDEPS="$(/usr/lib/mage/depwanderer.sh srcinstall ${MAGEFILE})" #abort already installed if [ "$?" == "3" ] then echo -en "Package " echo -en "${COLRED}$(basename ${MAGEFILE} .mage)${COLDEFAULT}" echo -e " already installed." echo -e "Installation aborted." exit 0 fi for i in ${ALLDEPS} do #first unset all vars to be safe unset PKGNAME unset STATE unset DESCRIPTION unset HOMEPAGE unset DEPEND unset SDEPEND unset PROVIDE unset PKGTYPE unset preinstall unset postinstall #then source an evtl new generated profile [ -e /etc/profile ] && source /etc/profile #than srcinstall MY_CAT_FIX="$(dirname ${i})" CATEGORIE="$(basename ${MY_CAT_FIX%/*})" #builds the package from source ${MLIBDIR}/sourceinstall.sh ${i} || exit 1 done run_etc_update ;; uninstall) RESULT=$(get_magefile_to_uninstall ${MAGENAME}) #get_magefile_to_uninstall ${MAGENAME} #echo $? #read case $? in 0) #MAGENAME=${RESULT} #mage_uninstall mage_uninstall ${RESULT} ;; 1) echo "No package found named '${RESULT}'." exit 1 ;; 2) echo -e ${COLRED}"Warning: More than one package found ..."${COLDEFAULT} echo echo "Please select the package you want to uninstall:" echo declare -i i=0 declare -i USERSEL=0 for x in ${RESULT} do echo -e "\t${COLBLUE}[${i}] ${COLGREEN}$(basename ${x})${COLDEFAULT}" SELECTION[${i}]=${x} i=${i}+1 done echo echo -n "Choose a number: " read USERSEL if [ ${USERSEL} -ge 0 -a ${USERSEL} -le ${i} ] then #the correct magefile #MAGENAME="${SELECTION[${USERSEL}]}/$(basename ${SELECTION[${USERSEL}]}).mage" MAGENAME="${SELECTION[${USERSEL}]}" mage_uninstall ${MAGENAME} else echo "Wrong input. Uninstall abortet ..." exit 1 fi #echo #echo "Uninstallation Aborted." #exit 1 ;; esac ;; search) ${MLIBDIR}/pkgsearch.sh ${MAGENAME} ;; unpack) build_unpackpkg ;; update) syncmage ;; clean) cleanpkg ;; keepfiles) keepfiles "$2" "$3" ;; inject) injectpkg "$2" ;; reminjected) reminjected ;; version) showversion ;; *) print_usage ;; esac