#!/bin/bash ##################################################################### # # CreateRootlessEnvironment # Andre Detsch, Renato Costa, Dan # ##################################################################### function our_which() { eval 'dirs=(`echo $PATH | tr ":" " "`)' for dir in "${dirs[@]}" do if [ -e "$dir/$1" ] then echo "$dir/$1" return 0 fi done return 1 } CURRENT_SCRIPTS_VERSION=2.9.11 # This variable is automatically set by Make hostSystemDependencies=( sh sed mv cp chmod chown md5sum readlink seq sha1sum find grep python wget ) gnuSystemDependencies=( sed readlink ls ) ############################################################################### # help message on $1 == --help ############################################################################### if [ "$1" = "--help" -o "$1" = "-help" -o "$1" = "-h" ] then echo "GoboLinux Rootless environment creation script" echo "Copyright (C) Andre Detsch, 2004-2005 - Released under the GNU GPL." echo "Usage: $0 []" echo "Default prefix is ${HOME}" exit 1 fi ############################################################################### # Checking for required tools ############################################################################### for app in "${hostSystemDependencies[@]}" do if [ ! "`our_which "$app"`" ] then echo "Rootless GoboLinux requires the '$app' command in your \$PATH." exit 1 fi done for app in "${gnuSystemDependencies[@]}" do if ! { $app --version 2> /dev/null | grep -qi "GNU\|Free Software Foundation" ;} then [ "$app" == "readlink" ] && readlink -f . &> /dev/null && continue echo "Rootless GoboLinux requires the GNU version of $app in your \$PATH." exit 1 fi done ############################################################################### # Preparing env variables ############################################################################### [ ! "$ROOTLESS_GOBOLINUX" ] && export ROOTLESS_GOBOLINUX=1 # default goboPrefix is ${HOME} if [ "$1" ] then mkdir -p "$1" export goboPrefix="`readlink -f $1`" else export goboPrefix="${HOME}" fi # Saves the current directory for later restoration pwd=$PWD ############################################################################### # Startup message and 'press a key to continue' ############################################################################### echo "You are about to create a Rootless environment at" echo "${goboPrefix}" echo "Press Enter to continue or Ctrl+C to abort." read echo ############################################################################### # Preparing stub tree ############################################################################### for dir in \ .Settings \ Programs \ System \ System/Links \ System/Links/Environment \ System/Links/Executables \ System/Links/Headers \ System/Links/Libraries \ System/Links/Manuals \ System/Links/Manuals/man{0,1,2,3,4,5,6,7,8} \ System/Links/Shared \ System/Links/Tasks \ System/Settings \ System/Variable \ Files/Compile/Archives \ Files/Compile/Sources do [ -e "${goboPrefix}/$dir" ] || { echo "Creating ${goboPrefix}/$dir"; mkdir -p "${goboPrefix}/$dir"; } done # Rootless uses /tmp as tmp directory [ -e "${goboPrefix}/System/Variable/tmp" ] || ln -sfn "/tmp" "${goboPrefix}/System/Variable/tmp" ############################################################################### # Creating Rootless package ############################################################################### mkdir -p "${goboPrefix}/Programs/Rootless/1.0/bin" cd "${goboPrefix}/Programs/Rootless/" ln -sfn "1.0" "Current" if [ "${goboPrefix}" = "${HOME}" ] then rootlessPrefix='${HOME}' else rootlessPrefix="${goboPrefix}" fi echo -n '#!/bin/bash (source) export ROOTLESS_GOBOLINUX=1 alias SymlinkProgram="SymlinkProgram --relative" [ ! "$goboPrefix" ] && export goboPrefix='"$rootlessPrefix"' if [ "${ZSH_NAME}" = "zsh" -o "$(basename "$(readlink -f "${SHELL}")")" = "zsh" ] then [ -e "${goboPrefix}/System/Settings/zshrc" ] && . "${goboPrefix}/System/Settings/zshrc" elif [ "${SHELL}" = "/bin/bash" -o "$(basename "$(readlink -f "${SHELL}")")" = "bash" ] then [ -e "${goboPrefix}/System/Settings/bashrc" ] && . "${goboPrefix}/System/Settings/bashrc" fi while read pythonDirectory do PYTHONPATH="${pythonDirectory}/site-packages${PYTHONPATH:+:$PYTHONPATH}" done < <(find "${goboPrefix}/System/Links/Libraries" -maxdepth 1 -name "python*" | sort) export PYTHONPATH export PKG_CONFIG_PATH="${goboPrefix}/System/Links/Libraries/pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}:/usr/local/lib/pkgconfig:/usr/local/share/pkgconfig:/usr/lib/pkgconfig:/usr/share/pkgconfig" export LD_LIBRARY_PATH="${goboPrefix}/System/Links/Libraries${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" if [ "`uname -s`" = "Darwin" ] then export DYLD_FALLBACK_LIBRARY_PATH="${goboPrefix}/System/Links/Libraries${DYLD_FALLBACK_LIBRARY_PATH:+:$DYLD_FALLBACK_LIBRARY_PATH}" export CFLAGS="-I${goboPrefix}/System/Links/Headers${CFLAGS:+ $CFLAGS}" export CPPFLAGS="-I${goboPrefix}/System/Links/Headers${CPPFLAGS:+$CPPFLAGS}" export LDFLAGS="-L${goboPrefix}/System/Links/Libraries${LDFLAGS:+$LDFLAGS}" fi if [ -n "$(uname -s | grep -i cygwin)" ] then export CFLAGS="-I${goboPrefix}/System/Links/Headers${CFLAGS:+ $CFLAGS}" export LDFLAGS="-L${goboPrefix}/System/Links/Libraries -Wl,-u,_WinMain@16 ${LDFLAGS:+$LDFLAGS}" fi # Without calling cd, prompt does not display ~, but ${HOME} { [ `readlink -f "${PWD}"` = `readlink -f "${HOME}"` ] && cd; } 2> /dev/null ' > "${goboPrefix}/Programs/Rootless/1.0/bin/StartRootless" # preparing a real_install (which is wrapped by Scripts install)... if [ ! "`our_which real_install`" ] then if [ -e "/bin/install" ] then ln -sfn /bin/install "${goboPrefix}/Programs/Rootless/1.0/bin/real_install" elif [ -e "/usr/bin/install" ] then ln -sfn /usr/bin/install "${goboPrefix}/Programs/Rootless/1.0/bin/real_install" else i=`our_which install` g=`file "$i" | grep ELF` if [ "$g" ] then ln -sfn "$i" "${goboPrefix}/Programs/Rootless/1.0/bin/real_install" else echo Warning: no CoreUtils install binary was found. Please provide it and link it echo at "${goboPrefix}/Programs/Rootless/1.0/bin/real_install" fi fi fi ############################################################################### # Getting Scripts package and pre-linking it ############################################################################### if [ ! -e "${goboPrefix}/Programs/Scripts/Current" ] then if [ -e "/Programs/Scripts/Current" ] then echo "You are under a GoboLinux system. Copying the Scripts package to your Rootless " echo "tree is not required, but its recommended if you want to change some settings." echo "Anytime latter you can run 'InstallPackage Scripts' in order to install the " echo "latests Scripts version inside Rootless." echo "Would you like to copy /Program/Scripts to ${goboPrefix}/Programs/Scripts? [y]es/[N]o" read if [ "$REPLY" = "y" ] then scripts=`readlink -f /Programs/Scripts/Current` version=`basename "${scripts}"` mkdir "${goboPrefix}/Programs/Scripts" cp -r $scripts "${goboPrefix}/Programs/Scripts" cd "${goboPrefix}/Programs/Scripts" find -name "CVS" | xargs rm -rf ln -s "${version}" Current fi else version="${CURRENT_SCRIPTS_VERSION:-2.8.3}" scripts=Scripts--${version}--i686.tar.bz2 wget http://kundor.org/gobo/packages/official/${scripts} -O /tmp/${scripts} cd "${goboPrefix}/Programs/" tar xvfj /tmp/${scripts} && rm -f /tmp/${scripts} cd Scripts ln -sfn "$version" Current cp -R "${goboPrefix}/Programs/Scripts/$version/Resources/Defaults/Settings" "${goboPrefix}/Programs/Scripts/Settings" fi fi function link_directory() { from="$1" to="$2" cd "${to}" for entry in "${from}"/*; do ln -sfn "${entry}" . 2> /dev/null; done cd - > /dev/null } if [ -e "${goboPrefix}/Programs/Scripts/Current" ] then echo "Pre-linking Scripts..." link_directory ../../Programs/Scripts/Settings "${goboPrefix}/System/Settings" link_directory ../../../Programs/Scripts/Current/bin "${goboPrefix}/System/Links/Executables" ln -s ../../Programs/Scripts/${version}/Resources/Environment "${goboPrefix}/System/Links/Environment/Scripts--${version}" echo "Populating Dependencies.blacklist..." echo -e "Glibc\nXorg" >> "${goboPrefix}/Programs/Scripts/Settings/Scripts/Dependencies.blacklist" fi ############################################################################### # Sourcing GoboPath ############################################################################### . "${goboPrefix}/Programs/Rootless/1.0/bin/StartRootless" ############################################################################### # Load all those beautiful shell script libraries we know and love ############################################################################### echo "Accessing new Rootless environment" PATH="${PATH}:${goboPrefix}/Programs/Scripts/Current/bin/" . ScriptFunctions Import Log Import GoboLinux Log_Normal "Gobo Rootless i686 has been installed." # Function to remove things in a pretty way function rootless_remove() { while [ "$1" ]; do Log_Normal "Removing $1" rm -rf "$1" shift done } # Function to remove all the stuff created by this script function rootless_uninstall() { if Ask "Cancel rootless installation?"; then cd "${HOME}" rootless_remove "${goboPrograms}" "${goboPrefix}/System" "${goboSettings}" [ -e "/Programs/Scripts/Current" ] || rootless_remove "${HOME}/.Settings" exit 1 fi } ############################################################################### # Check whether we need to recompile anything ############################################################################### binaries_ok="no" if [ "`Get_Architecture`" != i686 ]; then Log_Terse "Your machine is `Get_Architecture`." if ! Quiet our_which gcc; then Log_Error "gcc isn't installed. Can't recompile" binaries_ok="no" elif ! Quiet our_which make; then Log_Error "make isn't installed. Can't recompile" elif [ -d "${goboPrograms}/Scripts/Current" ]; then if Ask "Recompile binaries for your system?"; then Quiet pushd "${goboPrograms}/Scripts/Current" # Temporarily create a header file to be used as a last resort if the # real one doesn't exist on the host system. mkdir -p .fakeheaders/linux echo -n ' #ifndef _LINUX_KDEV_T_H #define _LINUX_KDEV_T_H #define MAJOR(dev) ((dev)>>8) #define MINOR(dev) ((dev) & 0xff) #define MKDEV(ma,mi) ((ma)<<8 | (mi)) #endif ' >> .fakeheaders/linux/kdev_t.h old_include_path="${C_INCLUDE_PATH}" location_of_fake_kdev="${goboPrograms}/Scripts/Current/.fakeheaders" export C_INCLUDE_PATH="${C_INCLUDE_PATH}:$location_of_fake_kdev" make cleanup && make && binaries_ok="yes" [ "$binaries_ok" == "yes" ] || Log_Error "Build Failed" export C_INCLUDE_PATH="${old_include_path}" rm -rf .fakeheaders Quiet popd fi fi else binaries_ok="yes" fi if [ "$binaries_ok" != "yes" ]; then Log_Error "Rootless probably won't work here." echo -n "Rootless GoboLinux consists mostly of cross-platform shell scripts, but it does include a couple of binary (compiled) programs. If you're seeing this message, the versions of those programs currently installed were built for a different type of computer (an i686 with a GNU Linux kernel). There is an extremely slim chance that if your kernel has Linux Binary Compatibility (as do some variants of BSD), everything may work anyway, but you're probably best off reporting this to the gobolinux-users mailing list, and removing Rootless for the time being. " rootless_uninstall fi ############################################################################### # Packages Linking (Scripts, Rootless) ############################################################################### if [ -e "${goboPrefix}/Programs/Scripts/Current" ] then Log_Normal Linking Scripts... UpdateSettings Scripts SymlinkProgram Scripts elif [ ! -e "/Programs/Scripts/Current" ]; then Log_Error "Installation failed" rootless_uninstall fi echo Log_Normal Linking Rootless... SymlinkProgram Rootless ############################################################################### # Preparing Rootless startup on next sessions ############################################################################### for profile in profile bash_profile zshrc xprofile do file="${HOME}/.${profile}" line=". \"${goboPrefix}/Programs/Rootless/Current/bin/StartRootless\"" if ! grep "^${line}" "${file}" &> /dev/null then if Ask "Should a StartRootless line be added to ~/.${profile}?" then echo >> "${file}" echo "$line" >> "${file}" else Log_Terse "StartRootless was not added to ~/.${profile}." Log_Normal "To start rootless you either need to issue '. ${goboPrefix}/Programs/Rootless/Current/bin/StartRootless' at the prompt each session or add that line to ~/.${profile} manually." fi fi done # Restores the last directory cd "$pwd" Log_Terse "Installation complete." echo "" echo "You can now restart your session in order to enjoy GoboLinux Rootless. For" echo "best results, consider using the zsh shell." echo "" echo "Commands recommended to be executed afterwards:" echo " InstallPackage Compile" echo " Compile Mtail" echo "" echo "Please report any problems to gobolinux-users@lists.gobolinux.org"