#!/bin/bash source ScriptFunctions Import File Import GoboLinux Import OptionParser Import String Import Requirements Import Versions Import Directories Import MetadataInstallation helpOnNoArguments=yes scriptDescription="Link a program from the ${goboPrograms} hierarchy in the ${goboSystem} tree." scriptCredits="Copyright (C) Hisham Muhammad, 2001-2005 - Released under the GNU GPL." scriptUsage="[] []" scriptExample="WeirdSuperLib 2.4" scriptNotes="If no program version is specified, Current is assumed." Add_Option_Entry "s" "settings" "Link settings into ${goboSettings}." "yes" "yes no safe" Add_Option_Entry "l" "libraries" "Link libraries into ${goboLibraries}." "yes" "yes no safe" Add_Option_Entry "e" "executables" "Link executables into ${goboExecutables}." "yes" "yes no safe" Add_Option_Entry "h" "headers" "Link headers into ${goboHeaders}." "yes" "yes no safe" Add_Option_Entry "a" "shared" "Link shared files into ${goboShared}." "yes" "yes no safe" Add_Option_Entry "w" "wrappers" "Link wrappers into ${goboExecutables}." "yes" "yes no safe" Add_Option_Entry "t" "tasks" "Link tasks into ${goboExecutables}." "yes" "yes no safe" Add_Option_Entry "u" "unmanaged" "Defines what to do with unmanaged files in package." "ask" "ask install skip" Add_Option_Boolean "E" "no-environment" "Do not link entries from ${goboEnvironment}." Add_Option_Boolean "R" "no-requirements" "Do not process Resources/Requirements." Add_Option_Boolean "A" "no-variable" "Do not move variable files into ${goboVariable}." Add_Option_Boolean "M" "no-doc" "Do not link manuals and info files." Add_Option_Boolean "C" "cleanup" "Clean up after installation." Add_Option_Entry "c" "conflict" "What to do on conflicting symlinks." "keep" "keep overwrite" Add_Option_Boolean "f" "force" "Force symlinks. Same as '--conflict overwrite'." Add_Option_Boolean "n" "no-make" "Dummy option. Preserved for backwards compatibility." Add_Option_Boolean "r" "relative" "Use relative paths to link files from ${goboPrograms}." #Add_Option_Boolean "r" "rootfs" "Copy program to rootfs if a symlink." #TODO: check those 'R'/'r' options Add_Option_Boolean "t" "rootfs" "Copy program to rootfs if a symlink." Parse_Options "$@" Parse_Conf "VersionExecutables.conf" Is_Writable "$goboExecutables" || Verify_Superuser linksettings=`Entry "settings"` linklibraries=`Entry "libraries"` linkexecutables=`Entry "executables"` linktasks=`Entry "tasks"` linkheaders=`Entry "headers"` linkshared=`Entry "shared"` linkwrappers=`Entry "wrappers"` if Boolean "force" || Is_Entry "conflict" "overwrite" then conflict="overwrite" fi Boolean "relative" && symlinkrelative="--relative" || symlinkrelative="" [ "${conflict}" == "overwrite" ] && symlinkoverwrite="--overwrite" || symlinkverwrite="" ################################################################################ function system_is_ok() { #TODO: check more needed stuff (sed, awk, head, ...) GuessProgramCase Scripts &> /dev/null || { Log_Error "GuessProgramCase is not working"; return 1 ;} return 0 } ################################################################################ [ "$(Arg 1)" ] || Die "Argument missing: specify the program name or directory." if ! system_is_ok then Log_Terse "System does not seems to be ok." if [ "$(Arg 2)" ] then p_path="$goboPrograms/`basename "$(Arg 1)"`/$(Arg 2)" else p_path="$goboPrograms/`basename "$(Arg 1)"`/Current" fi Ask_Continue "About to call 'RescueSymlinkProgram ${p_path} ${goboLinks}'" RescueSymlinkProgram "${p_path}" "${goboLinks}" Log_Normal "Done" exit 0 fi package="`basename "$(Arg 1)" /`" package=`GuessProgramCase "$package" "$(Arg 2)"` packageDir="$goboPrograms/$package" current="$packageDir/Current" version="$(basename "$(readlink -f "${current}")" /)" if ! Is_Directory "$packageDir" then Log_Error "Directory $packageDir does not exist." Corrections --log-name SymlinkProgram --dir "$goboPrograms" "$package" Die fi if [ "$(Arg 2)" ] then vdir="$goboPrograms/$package/$(Arg 2)" if ! Is_Directory "$vdir" then Die "There is no version $(Arg 2) for package $(Arg 1). Available versions are:\n$(All_Versions $package)" fi [ "$version" != "$(Arg 2)" ] && ln -sfn `basename "$vdir"` "$current" version="$(Arg 2)" fi if ! Exists "$current" then youngestdir=`ls --sort=time "$packageDir" | grep -v -e "Settings" -e "Variable" -e "Current" | head -n 1` ln -sf "$youngestdir" "$current" version="$youngestdir" fi if [ "xyes" = "x$autoVersionExecutables" ] then VersionExecutables "${package}" "${version}" fi Log_Normal "Symlinking ${package} ${version}." ################################################################################ # Read $goboPrograms/$package/$version/Resources/RootFS if Exists "$goboPrograms/$package/$version/Resources/RootFS" then Log_Verbose "Resources/RootFS found." rootfs="yes" fi if Line_Match "`Find_Conf RootFSPrograms`" "$package" then Log_Verbose "Package found in Scripts/RootFSPrograms." rootfs="yes" fi if Boolean "rootfs" then rootfs="yes" fi if [ "$rootfs" = "yes" ] then Log_Normal "$package must be in RootFS" fi #Below Is_Link should really be Is_RootFS but Is_RootFS doesn´t exist #and really testing use of goboInstall. Also, my goboInstall points to #dir on root. - Carlo Calica if [ "$rootfs" = "yes" ] && Is_Link "$goboPrograms/$package/$version" then srcProgram="$(readlink -f "$goboPrograms/$package/$version")" Log_Normal "Copying $srcProgram to $goboPrograms/$package." # Copy to root partition rm -f -- "$goboPrograms/$package/$version" cp -fRp "$srcProgram" "$goboPrograms/$package" fi ################################################################################ if [ "$linksettings" != "no" ] then Log_Normal "Symlinking global settings..." Link_Directory "$packageDir/Settings" "$goboSettings" "${symlinkrelative}" "${symlinkoverwrite}" fi ################################################################################ if [ "$linktasks" != "no" ] then Log_Normal "Symlinking tasks..." Link_Directory "$current/Resources/Tasks" "$goboTasks" "${symlinkrelative}" "${symlinkoverwrite}" fi ################################################################################ if ! Boolean "no-variable" then Log_Normal "Storing variable files..." vardir="$current/../Variable" if Is_Directory "$current/Resources/Defaults/Variable" then Is_Directory "$vardir" || Make_Directory "$vardir" Quiet cp -dR --preserve=mode,timestamps,links --reply=no "$current/Resources/Defaults/Variable"/* "$vardir" fi if ! Is_Empty_Directory "$vardir" then for file in "$vardir"/* do Reverse_Link_Or_Expand "$file" "${goboVariable}" done fi fi ################################################################################ if [ "$linklibraries" != "no" ] then Log_Normal "Symlinking libraries..." Link_Directory "$current/lib" "$goboLibraries" "${symlinkrelative}" "${symlinkoverwrite}" && { Is_Real_Nonempty_Directory "${current}/lib/gtk-2.0" && Rebuild_GDK_Pixbuf_Loaders Log_Normal "Updating library database (ldconfig)..." [ -x "$goboPrograms/Glibc/Current/sbin/ldconfig" ] && Quiet "$goboPrograms/Glibc/Current/sbin"/ldconfig || Quiet ldconfig if [ -d "$current/lib" ] then Quiet pushd "$current/lib" if [ "$(find . -name '*.la' -or -name '*.pc' -or -name '*.cmake' | wc -l)" != "0" ] then Log_Normal "Correcting directory references..." find . -name '*.la' -or -name '*.pc' -or -name '*.cmake' | xargs FixDirReferences fi Quiet popd fi } fi ################################################################################ if [ "$linkheaders" != "no" ] then Log_Normal "Symlinking headers..." Link_Directory "$current/include" "$goboHeaders" "${symlinkrelative}" "${symlinkoverwrite}" fi ################################################################################ if ! Boolean "no-doc" then Log_Normal "Symlinking info..." Quiet rm -- "$current/info/dir" Link_Directory "$current/info" "$goboManuals/info" "${symlinkrelative}" "${symlinkoverwrite}" Log_Normal "Updating info dir..." for f in `ls -1 "${current}/info/" 2> /dev/null | grep "[^0-9]$" | sed 's%.*/%%g'` do Log_Verbose "$f" install-info "$goboManuals/info/" "$goboManuals/info/dir" 2> /dev/null done Log_Normal "Symlinking manuals..." # cd "$current" # SymlinkManuals if Dir_Set Manuals then Link_Directory "$current/man/man0" "$goboManuals/man0" "${symlinkrelative}" "${symlinkoverwrite}" Link_Directory "$current/man/man1" "$goboManuals/man1" "${symlinkrelative}" "${symlinkoverwrite}" Link_Directory "$current/man/man2" "$goboManuals/man2" "${symlinkrelative}" "${symlinkoverwrite}" Link_Directory "$current/man/man3" "$goboManuals/man3" "${symlinkrelative}" "${symlinkoverwrite}" Link_Directory "$current/man/man4" "$goboManuals/man4" "${symlinkrelative}" "${symlinkoverwrite}" Link_Directory "$current/man/man5" "$goboManuals/man5" "${symlinkrelative}" "${symlinkoverwrite}" Link_Directory "$current/man/man6" "$goboManuals/man6" "${symlinkrelative}" "${symlinkoverwrite}" Link_Directory "$current/man/man7" "$goboManuals/man7" "${symlinkrelative}" "${symlinkoverwrite}" Link_Directory "$current/man/man8" "$goboManuals/man8" "${symlinkrelative}" "${symlinkoverwrite}" else Link_Directory "$current/Shared/man/man0" "$goboManuals/man0" "${symlinkrelative}" "${symlinkoverwrite}" Link_Directory "$current/Shared/man/man1" "$goboManuals/man1" "${symlinkrelative}" "${symlinkoverwrite}" Link_Directory "$current/Shared/man/man2" "$goboManuals/man2" "${symlinkrelative}" "${symlinkoverwrite}" Link_Directory "$current/Shared/man/man3" "$goboManuals/man3" "${symlinkrelative}" "${symlinkoverwrite}" Link_Directory "$current/Shared/man/man4" "$goboManuals/man4" "${symlinkrelative}" "${symlinkoverwrite}" Link_Directory "$current/Shared/man/man5" "$goboManuals/man5" "${symlinkrelative}" "${symlinkoverwrite}" Link_Directory "$current/Shared/man/man6" "$goboManuals/man6" "${symlinkrelative}" "${symlinkoverwrite}" Link_Directory "$current/Shared/man/man7" "$goboManuals/man7" "${symlinkrelative}" "${symlinkoverwrite}" Link_Directory "$current/Shared/man/man8" "$goboManuals/man8" "${symlinkrelative}" "${symlinkoverwrite}" fi cd "$current" fi ################################################################################ if [ "$linkexecutables" != "no" ] then Log_Normal "Symlinking executables..." Link_Directory "$current/bin" "$goboExecutables" "${symlinkrelative}" "${symlinkoverwrite}" Link_Directory "$current/sbin" "$goboExecutables" "${symlinkrelative}" "${symlinkoverwrite}" fi if [ "$linkwrappers" != "no" ] then Log_Normal "Symlinking wrappers..." wrapdir="$current/Resources/Wrappers" if [ -d "$wrapdir" ] then chmod +x "$wrapdir"/* Link_Directory "$wrapdir" "$goboExecutables" "${symlinkrelative}" "${symlinkoverwrite}" fi fi ################################################################################ if [ "$linkshared" != "no" ] then if [ "$goboIndex" ] then Log_Normal "Symlinking shared..." Link_Directory "$current/share" "$goboShared" "${symlinkrelative}" "${symlinkoverwrite}" else Log_Normal "Symlinking shared..." cd "$current" Quiet rmdir "share" Quiet rmdir "Shared" if Is_Real_Directory "share" then [ ! -d "Shared" ] && mv share Shared fi if Is_Real_Directory "Shared" then link=`readlink -f share` if ! [ "$link" = "$goboShared" ] then Quiet rm "share" [ "`echo ${goboShared:${#goboPrefix}:${#goboShared}} | cut -b1`" != "/" ] && slash="/" if Boolean "relative" && [ -d "../../..${slash}${goboShared:${#goboPrefix}:${#goboShared}}" ] then Quiet ln -snf "../../..${slash}${goboShared:${#goboPrefix}:${#goboShared}}" share else Quiet ln -snf "$goboShared" share fi fi Link_Directory "$current/Shared" "$goboShared" "${symlinkrelative}" "${symlinkoverwrite}" fi if ! Is_Real_Directory "Shared" && Is_Link "share" then rm "share" fi if Is_Real_Directory "Shared" then if [ "$(find Shared -name '*.cmake' | wc -l)" != "0" ] then Log_Normal "Correcting directory references..." find Shared -name '*.cmake' | xargs FixDirReferences fi fi Quiet cd - fi Is_Real_Nonempty_Directory "${current}/Shared/mime/packages" && Rebuild_MIME_Database Is_Real_Nonempty_Directory "${current}/Shared/applications" && Rebuild_Desktop_Database Is_Real_Nonempty_Directory "${current}/Shared/fonts" && Rebuild_Font_Cache Is_Real_Nonempty_Directory "${current}/Shared/omf" && Update_Scrollkeeper_Database Is_Real_Nonempty_Directory "${current}/lib/gtk-2.0" && Rebuild_GDK_Pixbuf_Loaders [ -f "${current}/Resources/XmlCatalogData" ] && Add_To_XML_Catalog "${packageDir}/${version}" # it's ok to install the GConf schemas even if they are already installed # we do this to ensure that the schemas are really installed Is_Real_Nonempty_Directory "${goboPrograms}/${package}/Settings/gconf/schemas" && Install_GConf_Schemas "${package}" # Is_Real_Nonempty_Directory "${current}/Shared/sgml" && Install_SGML_DTD "${package}" fi ################################################################################ if [ -f "$current/Resources/UnmanagedFiles" ] && { { Is_Entry "unmanaged" "ask" && { Log_Normal "The program wishes to install files to these unmanaged locations:" cat $current/Resources/UnmanagedFiles Ask "Do you want to install the unmanaged files?" } } || Is_Entry "unmanaged" "install"; } then Log_Normal "Installing unmanaged files..." Install_Unmanaged_Files "$current/Resources/UnmanagedFiles" "$current/Resources/Unmanaged" fi ################################################################################ if ! Boolean "no-environment" then if Boolean "relative" then envfile="../../../$goboPrograms/$package/$version/Resources/Environment" else envfile="$current/Resources/Environment" fi if [ -e "$envfile" ] then Log_Normal "Symlinking environment..." rm -f -- "$goboEnvironment/$package--"* Verbose ln -sfv "$envfile" "$goboEnvironment/$package--$version" Gen_Env_Cache fi fi ################################################################################ if ! Boolean "no-requirements" && [ -f "$current/Resources/Requirements" ] then Log_Normal "Asserting that requirements are met..." Process_Requirements_File "$goboPrograms/$package/$version" fi ################################################################################ Log_Normal "Removing unused directories..." PrepareProgram --tree-cleanup "$package" "$version" if Boolean "cleanup" then Log_Normal "Removing any broken links..." find "${goboLinks}" | RemoveBroken fi ################################################################################ Log_Normal "Done." exit 0