2010-01-28 14:25:25 +03:00
|
|
|
#!/bin/bash
|
2010-01-13 11:30:35 +03:00
|
|
|
#
|
2011-08-13 06:31:02 +04:00
|
|
|
# Copyright (c) 2009-2010 Haiku, Inc.
|
2010-01-13 11:30:35 +03:00
|
|
|
# Distributed under the terms of the MIT License.
|
|
|
|
#
|
|
|
|
# Authors:
|
|
|
|
# Matt Madia, mattmadia@gmail.com
|
|
|
|
#
|
2010-04-29 19:50:22 +04:00
|
|
|
# Synopsis:
|
|
|
|
# Provides a controlled mechanism for end-users to install certain pre-built
|
|
|
|
# OptionalPackages. The script will determine the host information: the
|
|
|
|
# default GCC, availability of secondary GCC libs, and revision. Using this
|
2010-01-13 11:30:35 +03:00
|
|
|
# information, the user will be limited to the appropriate OptionalPackages
|
|
|
|
# that were available for that specific revision.
|
|
|
|
#
|
2010-05-15 07:55:58 +04:00
|
|
|
DISCLAIMER="\
|
|
|
|
Disclaimer:\n\
|
|
|
|
This is a temporary solution for installing OptionalPackages.\n\
|
|
|
|
In time, there will be an official package manager.\n\
|
|
|
|
See these URL's for information on the in-development package manager.\n\
|
|
|
|
http://dev.haiku-os.org/wiki/PackageManagerIdeas\n\
|
|
|
|
http://dev.haiku-os.org/wiki/PackageFormat\n\
|
|
|
|
"
|
|
|
|
|
|
|
|
USAGE="\
|
|
|
|
Usage: ./installoptionalpackage [<pkg> [<pkg> ...]]\n\
|
|
|
|
or ./installoptionalpackage [-a|-s <pkg> [<pkg> ...]]\n\
|
|
|
|
or ./installoptionalpackage [-f|-h|-l]\n\
|
|
|
|
\n\
|
|
|
|
Options:\n\
|
|
|
|
-a Add one or more packages and all dependencies\n\
|
|
|
|
-s Show the final list of packages that would be installed\n\
|
|
|
|
-f Remove cached data and list installable packages\n\
|
|
|
|
-h Print this help.\n\
|
|
|
|
-l List installable packages\n\
|
|
|
|
"
|
2010-01-13 11:30:35 +03:00
|
|
|
|
2010-01-28 14:25:25 +03:00
|
|
|
declare -A availablePackages
|
|
|
|
declare availablePackagesKeys=""
|
2010-04-21 19:18:47 +04:00
|
|
|
declare wantsToInstall=""
|
2010-06-24 01:28:41 +04:00
|
|
|
declare alreadyInstalled=""
|
2010-01-13 11:30:35 +03:00
|
|
|
# Some Packages cannot be installed,
|
|
|
|
# as they require either the source code or compiled binaries
|
2010-06-24 01:28:41 +04:00
|
|
|
declare packageIgnoreList="Bluetooth Development DevelopmentMin \
|
2010-07-20 20:48:21 +04:00
|
|
|
DevelopmentBase MandatoryPackages UserlandFS Welcome WifiFirmwareScriptData \
|
|
|
|
ICU-devel ICU "
|
2010-01-13 11:30:35 +03:00
|
|
|
|
|
|
|
|
|
|
|
function CreateInstallerScript()
|
|
|
|
{
|
|
|
|
# This function will create a secondary script, containing all of the
|
|
|
|
# information needed to install the optional package and its dependencies
|
|
|
|
|
|
|
|
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
cat << EOF > ${tmpDir}/install-optpkg.sh
|
2010-01-28 14:25:25 +03:00
|
|
|
#!/bin/bash
|
2010-01-13 11:30:35 +03:00
|
|
|
|
|
|
|
tmpDir=${tmpDir}
|
|
|
|
HAIKU_GCC_VERSION[1]=${HAIKU_GCC_VERSION[1]}
|
|
|
|
isHybridBuild=${isHybridBuild}
|
|
|
|
TARGET_ARCH=${TARGET_ARCH}
|
|
|
|
HAIKU_IMAGE_HOST_NAME=`uname -n`
|
2010-05-04 00:42:10 +04:00
|
|
|
#TODO: possibly add a CLI option to execute InstallSourceArchive
|
2010-04-13 01:48:18 +04:00
|
|
|
HAIKU_INCLUDE_SOURCES=0
|
2010-01-13 11:30:35 +03:00
|
|
|
$urlLine
|
|
|
|
$sslPkgLine
|
|
|
|
$sslUrlLine
|
|
|
|
declare -a functionArgs
|
2010-03-18 20:14:19 +03:00
|
|
|
expanderRulesFile=`finddir B_COMMON_DATA_DIRECTORY`/expander.rules
|
|
|
|
if [ -f \${expanderRulesFile} ] ; then
|
|
|
|
expanderRulesFileExists=1
|
|
|
|
fi
|
2010-01-13 11:30:35 +03:00
|
|
|
|
|
|
|
|
|
|
|
function ParseFunctionArguments()
|
|
|
|
{
|
|
|
|
# ParseFunctionArguments <args>
|
|
|
|
# Parse arguments for Jam wrapper functions into an array.
|
|
|
|
IN="\$@"
|
|
|
|
OIFS=\$IFS
|
|
|
|
IFS=":"
|
2010-04-29 19:50:22 +04:00
|
|
|
|
2010-01-13 11:30:35 +03:00
|
|
|
local count=0
|
|
|
|
functionArgs=( )
|
|
|
|
for x in \$IN
|
|
|
|
do
|
|
|
|
functionArgs[\${count}]="\${x}"
|
|
|
|
((count++))
|
|
|
|
done
|
|
|
|
IFS=\$OIFS
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function TrimLeadingSpace()
|
|
|
|
{
|
|
|
|
# TrimLeadingSpace <variable name>
|
|
|
|
eval local text='\$'"\$1"
|
|
|
|
local _outvar="\$1"
|
|
|
|
|
|
|
|
local length=\${#text}
|
|
|
|
((length--))
|
|
|
|
if [ "\${text:0:1}" == ' ' ] ; then
|
|
|
|
text=\${text#' '}
|
|
|
|
fi
|
|
|
|
|
|
|
|
eval \$_outvar="'\$text'"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function TrimEndingSpace()
|
|
|
|
{
|
|
|
|
# TrimEndingSpace <variable name>
|
|
|
|
eval local text='\$'"\$1"
|
|
|
|
local _outvar="\$1"
|
|
|
|
|
|
|
|
local length=\${#text}
|
|
|
|
((length--))
|
|
|
|
if [ "\${text:\$length}" == ' ' ] ; then
|
|
|
|
text=\${text%' '}
|
|
|
|
fi
|
|
|
|
|
|
|
|
eval \$_outvar="'\$text'"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function Exit()
|
|
|
|
{
|
|
|
|
# Exit <message>
|
|
|
|
# Wrapper for Jam rule
|
|
|
|
echo "\$@"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function InstallOptionalHaikuImagePackage()
|
|
|
|
{
|
|
|
|
# InstallOptionalHaikuImagePackage package : url : dirTokens : isCDPackage
|
2010-07-18 06:12:16 +04:00
|
|
|
|
2010-01-13 11:30:35 +03:00
|
|
|
# Wrapper for Jam rule
|
|
|
|
echo "Installing \$1 ..."
|
|
|
|
cd \$tmpDir
|
2010-04-29 19:50:22 +04:00
|
|
|
|
2010-03-02 01:13:12 +03:00
|
|
|
archiveFile=\`echo \$3 | sed -s "s/http.*\///"\`
|
|
|
|
if ! [ -f \$archiveFile ] ; then
|
2010-01-13 11:30:35 +03:00
|
|
|
echo "Downloading \$3 ..."
|
2010-07-20 21:22:02 +04:00
|
|
|
# TODO : add some error handling for downloads
|
2010-08-05 04:17:52 +04:00
|
|
|
local attempt=1
|
|
|
|
while [ \`wget -nv \$3 ; echo \$? \` -ne 0 ]; do
|
|
|
|
if [ \$attempt -eq 5 ]; then
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
(( attempt++ ))
|
|
|
|
echo "Download attempt #\$attempt failed. Retrying ..."
|
|
|
|
if [ -e \$archiveFile ]; then
|
|
|
|
rm \$archiveFile
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
if [ \$attempt -ge 5 ]; then
|
|
|
|
if [ -e \$archiveFile ]; then
|
|
|
|
rm \$archiveFile
|
|
|
|
fi
|
|
|
|
Exit "Max download retries exceeded. Halting installation."
|
|
|
|
fi
|
2010-01-13 11:30:35 +03:00
|
|
|
fi
|
2010-04-29 19:50:22 +04:00
|
|
|
|
2010-01-13 11:30:35 +03:00
|
|
|
local dirTokens='/boot'
|
|
|
|
local count=4
|
|
|
|
local i=0
|
|
|
|
for possibleToken in "\$@" ; do
|
|
|
|
if [ \$i -lt \$count ] ; then
|
|
|
|
((i++))
|
|
|
|
else
|
|
|
|
((i++))
|
2010-04-29 19:50:22 +04:00
|
|
|
if [ "\$possibleToken" != ':' ] ; then
|
2010-01-13 11:30:35 +03:00
|
|
|
dirTokens=\${dirTokens}/\$possibleToken
|
|
|
|
else
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
2010-03-02 01:13:12 +03:00
|
|
|
echo "Extracting \$archiveFile ..."
|
|
|
|
extractDir="\${dirTokens}"
|
2010-04-29 19:50:22 +04:00
|
|
|
|
2010-08-05 04:17:52 +04:00
|
|
|
local errorMessage="
|
|
|
|
...Failed while extracting \$archiveFile
|
|
|
|
You may need to manually clean up the partially extracted files.
|
|
|
|
"
|
2010-03-02 01:13:12 +03:00
|
|
|
case "\$archiveFile" in
|
|
|
|
*.zip)
|
2010-08-05 04:17:52 +04:00
|
|
|
unzip -q -o -d "\$extractDir" "\$archiveFile" \
|
|
|
|
|| Exit "\$errorMessage"
|
2010-03-02 01:13:12 +03:00
|
|
|
;;
|
|
|
|
*.tgz|*.tar.gz)
|
2010-08-05 04:17:52 +04:00
|
|
|
tar -C "\$extractDir" -xf "\$archiveFile" \
|
|
|
|
|| Exit "\$errorMessage"
|
2010-03-02 01:13:12 +03:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Unhandled archive extension in InstallOptionalHaikuImagePackage()"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
2010-04-29 19:50:22 +04:00
|
|
|
|
2010-01-13 11:30:35 +03:00
|
|
|
if [ -f '/boot/.OptionalPackageDescription' ] ; then
|
|
|
|
rm '/boot/.OptionalPackageDescription'
|
|
|
|
fi
|
2010-03-02 01:13:12 +03:00
|
|
|
rm "\$archiveFile"
|
2010-01-13 11:30:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-04 00:42:10 +04:00
|
|
|
function InstallSourceArchive()
|
|
|
|
{
|
|
|
|
if [ \$HAIKU_INCLUDE_SOURCES -gt 0 ]; then
|
|
|
|
echo "InstallSourceArchive is not implemented."
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-13 11:30:35 +03:00
|
|
|
function AddSymlinkToHaikuImage()
|
|
|
|
{
|
2010-04-29 19:50:22 +04:00
|
|
|
# AddSymlinkToHaikuImage <dir tokens> : <link target> [ : <link name> ]
|
2010-01-13 11:30:35 +03:00
|
|
|
# Wrapper for Jam rule
|
|
|
|
ParseFunctionArguments "\$@"
|
2010-04-29 19:50:22 +04:00
|
|
|
|
2010-01-13 11:30:35 +03:00
|
|
|
local dirTokens="/boot/\${functionArgs[0]}"
|
|
|
|
TrimLeadingSpace dirTokens
|
|
|
|
TrimEndingSpace dirTokens
|
|
|
|
dirTokens=\${dirTokens//' '/\/}
|
2010-04-29 19:50:22 +04:00
|
|
|
|
2010-01-13 11:30:35 +03:00
|
|
|
local linkTarget="\${functionArgs[1]}"
|
|
|
|
TrimLeadingSpace linkTarget
|
|
|
|
TrimEndingSpace linkTarget
|
2010-04-29 19:50:22 +04:00
|
|
|
|
2010-01-13 11:30:35 +03:00
|
|
|
local linkName="\${functionArgs[2]}"
|
|
|
|
TrimLeadingSpace linkName
|
|
|
|
TrimEndingSpace linkName
|
2010-04-29 19:50:22 +04:00
|
|
|
|
2010-02-06 18:46:08 +03:00
|
|
|
mkdir -p "\${dirTokens}"
|
2010-04-29 19:50:22 +04:00
|
|
|
|
2010-01-13 11:30:35 +03:00
|
|
|
if [ "\${linkName}" == '' ] ; then
|
|
|
|
ln -sf "\${linkTarget}" -t "\${dirTokens}"
|
|
|
|
else
|
|
|
|
ln -sf "\${linkTarget}" "\${dirTokens}/\${linkName}"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function AddUserToHaikuImage()
|
|
|
|
{
|
|
|
|
# AddUserToHaikuImage user : uid : gid : home : shell : realName
|
2010-04-29 19:50:22 +04:00
|
|
|
# Wrapper for Jam rule
|
2010-01-13 11:30:35 +03:00
|
|
|
ParseFunctionArguments "\$@"
|
2010-04-29 19:50:22 +04:00
|
|
|
|
2010-01-13 11:30:35 +03:00
|
|
|
local user=\${functionArgs[0]}
|
|
|
|
local uid=\${functionArgs[1]}
|
|
|
|
local gid=\${functionArgs[2]}
|
|
|
|
local home=\${functionArgs[3]}
|
|
|
|
local shell=\${functionArgs[4]}
|
|
|
|
local realName=\${functionArgs[5]}
|
2010-04-29 19:50:22 +04:00
|
|
|
|
2010-01-13 11:30:35 +03:00
|
|
|
passwdLine="\${user}:x:\${uid}:\${gid}:\${realName}:\${home}:\${shell}"
|
|
|
|
passwdLine=\${passwdLine//' :'/':'}
|
|
|
|
passwdLine=\${passwdLine//': '/':'}
|
2010-04-29 19:50:22 +04:00
|
|
|
|
2010-01-13 11:30:35 +03:00
|
|
|
local length=\${#passwdLine}
|
|
|
|
((length--))
|
|
|
|
if [ "\${passwdLine:\$length}" == ' ' ] ; then
|
|
|
|
passwdLine=\${passwdLine%' '}
|
|
|
|
fi
|
2010-04-29 19:50:22 +04:00
|
|
|
|
2010-01-13 11:30:35 +03:00
|
|
|
passwdFile="\`finddir B_COMMON_ETC_DIRECTORY\`/passwd"
|
|
|
|
touch \${passwdFile}
|
2010-04-29 19:50:22 +04:00
|
|
|
|
2010-01-13 11:30:35 +03:00
|
|
|
local userExists=1
|
|
|
|
while read line ; do
|
|
|
|
if [ "\${passwdLine}" == "\${line}" ] ; then
|
|
|
|
userExists=0
|
|
|
|
fi
|
|
|
|
done < \${passwdFile}
|
2010-04-29 19:50:22 +04:00
|
|
|
|
2010-01-13 11:30:35 +03:00
|
|
|
if [ \$userExists -ge 1 ] ; then
|
|
|
|
echo "\${passwdLine}" >> \${passwdFile}
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-18 20:14:19 +03:00
|
|
|
function AddExpanderRuleToHaikuImage()
|
|
|
|
{
|
|
|
|
# AddExpanderRuleToHaikuImage <mimetype> : <extension> : <list> : <extract>
|
2010-04-29 19:50:22 +04:00
|
|
|
# Wrapper for Jam rule
|
2010-03-18 20:14:19 +03:00
|
|
|
ParseFunctionArguments "\$@"
|
2010-04-29 19:50:22 +04:00
|
|
|
|
2010-03-18 20:14:19 +03:00
|
|
|
local mimetype=\${functionArgs[0]}
|
|
|
|
local extension=\${functionArgs[1]}
|
|
|
|
local list=\${functionArgs[2]}
|
|
|
|
local extract=\${functionArgs[3]}
|
|
|
|
|
2010-04-29 19:50:22 +04:00
|
|
|
# clean up the variables
|
2010-03-18 20:14:19 +03:00
|
|
|
TrimLeadingSpace mimetype
|
|
|
|
TrimEndingSpace mimetype
|
|
|
|
TrimLeadingSpace extension
|
|
|
|
TrimEndingSpace extension
|
|
|
|
TrimLeadingSpace list
|
|
|
|
TrimEndingSpace list
|
|
|
|
TrimLeadingSpace extract
|
|
|
|
TrimEndingSpace extract
|
|
|
|
local rule_raw="\${mimetype}\\t\${extension}\\t\${list}\\t\${extract}"
|
2010-04-29 19:50:22 +04:00
|
|
|
|
2010-03-18 20:14:19 +03:00
|
|
|
# reset this at every invocation
|
|
|
|
ruleFound=
|
2010-04-29 19:50:22 +04:00
|
|
|
|
2010-03-18 20:14:19 +03:00
|
|
|
if [ \${expanderRulesFileExists} ] ; then
|
|
|
|
# Check if a rule for the mimetype & extension exists.
|
2010-04-29 19:50:22 +04:00
|
|
|
while read line ; do
|
2010-03-18 20:14:19 +03:00
|
|
|
existing_rule=`echo \$line | awk '{ print \$1\$2 }'`
|
|
|
|
if [ "\${mimetype}\${extension}" == "\${existing_rule}" ] ; then
|
|
|
|
ruleFound=1
|
|
|
|
break
|
2010-04-29 19:50:22 +04:00
|
|
|
fi
|
2010-03-18 20:14:19 +03:00
|
|
|
done < "\${expanderRulesFile}"
|
|
|
|
fi
|
|
|
|
if ! [ \${expanderRulesFileExists} ] || ! [ \${ruleFound} ] ; then
|
2010-04-29 19:50:22 +04:00
|
|
|
# Either expander.rules does not exist or a rule for mimetype &
|
2010-03-18 20:14:19 +03:00
|
|
|
# extension does not exist. Output the new rule directly to it.
|
|
|
|
echo -e \${rule_raw} >> \${expanderRulesFile}
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-13 11:30:35 +03:00
|
|
|
EOF
|
|
|
|
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
cat ${tmpDir}/optpkg.stage2 >> ${tmpDir}/install-optpkg.sh
|
|
|
|
rm ${tmpDir}/optpkg.stage2
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-28 14:25:25 +03:00
|
|
|
function ContainsSubstring()
|
|
|
|
{
|
|
|
|
# ContainsSubstring <stringToLookIn> <stringToLookFor>
|
|
|
|
local string="$1"
|
|
|
|
local substring="$2"
|
|
|
|
local newString=${string/${substring}/''}
|
2011-10-29 05:58:39 +04:00
|
|
|
if [ ${#string} -eq $((${#newString} + ${#substring})) ] ; then
|
2010-01-28 14:25:25 +03:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-03 23:58:49 +03:00
|
|
|
function ErrorExit()
|
|
|
|
{
|
|
|
|
echo $1
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-28 14:25:25 +03:00
|
|
|
function Init()
|
|
|
|
{
|
2010-04-21 18:07:19 +04:00
|
|
|
|
2010-01-28 14:25:25 +03:00
|
|
|
# Set up some directory paths
|
|
|
|
baseDir=`finddir B_COMMON_DATA_DIRECTORY`/optional-packages
|
|
|
|
tmpDir=`finddir B_COMMON_TEMP_DIRECTORY`
|
|
|
|
libDir=`finddir B_SYSTEM_LIB_DIRECTORY`
|
|
|
|
|
2010-07-11 02:38:47 +04:00
|
|
|
installedPackagesFile="${baseDir}/InstalledPackages"
|
|
|
|
|
2010-01-28 14:25:25 +03:00
|
|
|
# Make sure these files are empty.
|
|
|
|
echo "" > ${tmpDir}/optpkg.jam
|
|
|
|
echo "" > ${tmpDir}/optpkg.stage1
|
2010-04-29 19:50:22 +04:00
|
|
|
|
2010-01-28 14:25:25 +03:00
|
|
|
if ! [ -d ${baseDir} ] ; then
|
|
|
|
mkdir -p ${baseDir}
|
|
|
|
fi
|
2010-04-21 18:07:19 +04:00
|
|
|
|
|
|
|
DetectSystemConfiguration
|
|
|
|
DownloadAllBuildFiles
|
2010-06-24 01:28:41 +04:00
|
|
|
ReadInstalledPackagesIntoMemory
|
2010-04-21 18:07:19 +04:00
|
|
|
ReadPackageNamesIntoMemory
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function DownloadAllBuildFiles()
|
|
|
|
{
|
|
|
|
# DownloadAllBuildFiles
|
2010-01-28 14:25:25 +03:00
|
|
|
# Retreive the necessary jam files from svn.
|
|
|
|
local buildFiles="OptionalPackages OptionalPackageDependencies \
|
2010-12-05 17:20:58 +03:00
|
|
|
OptionalBuildFeatures OptionalLibPackages"
|
2010-01-28 14:25:25 +03:00
|
|
|
for file in ${buildFiles} ; do
|
|
|
|
GetBuildFile ${file}
|
|
|
|
done
|
2010-04-29 19:50:22 +04:00
|
|
|
|
2010-01-28 14:25:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-13 11:30:35 +03:00
|
|
|
function GetBuildFile()
|
|
|
|
{
|
|
|
|
# GetBuildFile <file>
|
2010-01-28 14:25:25 +03:00
|
|
|
# Downloads files from Haiku's svn
|
|
|
|
local buildfile="$1"
|
|
|
|
if ! [ -f ${baseDir}/${buildfile} ] ; then
|
|
|
|
echo "Fetching ${buildfile} ..."
|
2010-01-13 11:30:35 +03:00
|
|
|
cd ${baseDir}
|
|
|
|
local baseURL=http://dev.haiku-os.org/export/
|
|
|
|
local revision=`uname -v | awk '{print $1}' | sed -e 's/r//'`
|
2010-01-28 14:25:25 +03:00
|
|
|
local url="${baseURL}${revision}/haiku/trunk/build/jam/${buildfile}"
|
2010-03-03 23:58:49 +03:00
|
|
|
wget -q ${url} || ErrorExit "...failed to download $buildfile"
|
2010-04-29 19:50:22 +04:00
|
|
|
fi
|
2010-01-13 11:30:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-28 14:25:25 +03:00
|
|
|
function DetectSystemConfiguration()
|
2010-01-13 11:30:35 +03:00
|
|
|
{
|
2010-07-18 06:12:16 +04:00
|
|
|
|
|
|
|
# Determine which GCC we're running
|
|
|
|
if [ -f "$libDir"/libsupc++.so ] ; then
|
2010-01-28 14:25:25 +03:00
|
|
|
HAIKU_GCC_VERSION[1]=4
|
|
|
|
else
|
|
|
|
HAIKU_GCC_VERSION[1]=2
|
2010-07-18 06:12:16 +04:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Test for hybrid
|
|
|
|
if [ -d "$libDir"/gcc4 -a -d "$libDir"/gcc2 ]; then
|
|
|
|
echo "Sorry, but your build appears to be broken ..."
|
|
|
|
echo "Both gcc2 and gcc4 subdirs exist."
|
|
|
|
exit 1
|
|
|
|
elif [ -d "$libDir"/gcc4 -o -d "$libDir"/gcc2 ]; then
|
|
|
|
isHybridBuild=1
|
|
|
|
else
|
2010-03-01 13:11:22 +03:00
|
|
|
isHybridBuild=""
|
2010-01-28 14:25:25 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Determine the Architecture.
|
|
|
|
if [ `uname -m` == "BePC" ] ; then
|
|
|
|
TARGET_ARCH='x86'
|
2010-07-18 06:12:16 +04:00
|
|
|
else
|
|
|
|
echo "Sorry, x86 only for now."
|
|
|
|
exit 1
|
2010-01-28 14:25:25 +03:00
|
|
|
fi
|
2010-01-13 11:30:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-24 01:28:41 +04:00
|
|
|
function ReadInstalledPackagesIntoMemory()
|
|
|
|
{
|
|
|
|
while read line ; do
|
|
|
|
alreadyInstalled="${alreadyInstalled} $line"
|
|
|
|
packageIgnoreList=${packageIgnoreList/"${line} "/' '}
|
|
|
|
done < ${installedPackagesFile}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-28 14:25:25 +03:00
|
|
|
function ReadPackageNamesIntoMemory()
|
2010-01-13 11:30:35 +03:00
|
|
|
{
|
2010-01-28 14:25:25 +03:00
|
|
|
local file="${baseDir}/OptionalPackageNames"
|
|
|
|
if ! [ -f ${file} ] ; then
|
|
|
|
GeneratePackageNames
|
|
|
|
fi
|
2010-04-29 19:50:22 +04:00
|
|
|
|
2010-01-28 14:25:25 +03:00
|
|
|
# read list into associative array
|
|
|
|
while read line ; do
|
|
|
|
local pkg=`echo ${line} | awk '{print $1}'`
|
2010-04-29 19:56:46 +04:00
|
|
|
local pkgDeps=${line/"${pkg} :"/}
|
2010-01-28 14:25:25 +03:00
|
|
|
availablePackages[${pkg}]="${pkgDeps}"
|
|
|
|
availablePackagesKeys="${availablePackagesKeys} ${pkg}"
|
|
|
|
done < ${file}
|
2010-01-13 11:30:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-28 14:25:25 +03:00
|
|
|
function GeneratePackageNames()
|
2010-01-13 11:30:35 +03:00
|
|
|
{
|
2010-01-28 14:25:25 +03:00
|
|
|
# GeneratePackageNames
|
|
|
|
# Creates a file containing available package names
|
|
|
|
# Each line shows a pakage and all of its recrusive dependencies
|
|
|
|
# "<pkg> : <dep1> <dep2> ..."
|
|
|
|
echo "Generating a list of Package Names ..."
|
2010-04-29 19:50:22 +04:00
|
|
|
|
2010-01-28 14:25:25 +03:00
|
|
|
local file="${baseDir}/OptionalPackageNames"
|
2010-06-26 22:30:25 +04:00
|
|
|
if [ -e "${file}" ]; then
|
|
|
|
rm "${file}"
|
|
|
|
fi
|
2010-04-29 19:50:22 +04:00
|
|
|
|
2010-01-28 14:25:25 +03:00
|
|
|
local regExp='/^if\ \[\ IsOptionalHaikuImagePackageAdded/p'
|
|
|
|
sed -n -e "$regExp" ${baseDir}/OptionalPackages > ${file}.temp
|
2010-12-05 17:20:58 +03:00
|
|
|
sed -n -e "$regExp" ${baseDir}/OptionalLibPackages >> ${file}.temp
|
2010-01-28 14:25:25 +03:00
|
|
|
while read line ; do
|
|
|
|
# in each non-filtered line, the 4th word is the optional package
|
|
|
|
local pkg=`echo ${line} | awk '{print $4}'`
|
2010-04-29 19:50:22 +04:00
|
|
|
|
2010-01-28 14:25:25 +03:00
|
|
|
nonRepeatingDeps=""
|
|
|
|
GetPackageDependencies "$pkg"
|
2010-04-29 19:56:46 +04:00
|
|
|
local lowerCasePkg=`echo ${pkg} | tr '[A-Z]' '[a-z]'`
|
2010-06-26 22:30:25 +04:00
|
|
|
if ! ContainsSubstring "${alreadyInstalled} " "${pkg} " ; then
|
|
|
|
if IsPackageAndDepsOkToInstall ${pkg} ; then
|
|
|
|
echo "${lowerCasePkg} : ${pkg} ${nonRepeatingDeps}" >> ${file}
|
|
|
|
fi
|
2010-01-28 14:25:25 +03:00
|
|
|
fi
|
2010-04-29 19:50:22 +04:00
|
|
|
|
2010-01-28 14:25:25 +03:00
|
|
|
done < ${file}.temp
|
|
|
|
rm ${file}.temp
|
2010-01-13 11:30:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function GetPackageDependencies()
|
|
|
|
{
|
2010-01-28 14:25:25 +03:00
|
|
|
# GetPackageDependencies <pkg>
|
2010-04-29 19:50:22 +04:00
|
|
|
|
|
|
|
# parse OptionalPackageDependencies for the single line that defines
|
2010-01-28 14:25:25 +03:00
|
|
|
# this optional package's dependencies.
|
|
|
|
local regExp="^OptionalPackageDependencies\ ${1}\ \:"
|
2010-01-13 11:30:35 +03:00
|
|
|
local inputFile="${baseDir}/OptionalPackageDependencies"
|
2010-04-29 19:50:22 +04:00
|
|
|
|
2010-01-28 14:25:25 +03:00
|
|
|
# print that single line
|
2010-01-13 11:30:35 +03:00
|
|
|
sed -n -e "/${regExp}\ /p" ${inputFile} > ${tmpDir}/optpkg.temp
|
2010-04-29 19:50:22 +04:00
|
|
|
|
2010-01-28 14:25:25 +03:00
|
|
|
# strip out "OptionalPackageDependencies PackageName :"
|
|
|
|
# this leaves "<dep1> .... ;"
|
|
|
|
tempDeps=`sed -e "s/${regExp}\ //" ${tmpDir}/optpkg.temp`
|
2010-04-29 19:50:22 +04:00
|
|
|
|
2010-01-28 14:25:25 +03:00
|
|
|
for foo in ${tempDeps%' ;'} ; do
|
|
|
|
# Prevent duplicate entries of the same dependency package.
|
|
|
|
if ! ContainsSubstring "${nonRepeatingDeps} " "${foo} " ; then
|
|
|
|
nonRepeatingDeps="$foo $nonRepeatingDeps "
|
|
|
|
nonRepeatingDeps="${nonRepeatingDeps// / }"
|
2010-04-29 19:50:22 +04:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2010-01-28 14:25:25 +03:00
|
|
|
# Recursively get the dependencies of these dependencies.
|
|
|
|
for dep in ${tempDeps%' ;'} ; do
|
|
|
|
GetPackageDependencies "$dep"
|
|
|
|
done
|
2010-04-29 19:50:22 +04:00
|
|
|
|
2010-01-13 11:30:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-28 14:25:25 +03:00
|
|
|
function IsPackageAndDepsOkToInstall()
|
2010-01-13 11:30:35 +03:00
|
|
|
{
|
2010-01-28 14:25:25 +03:00
|
|
|
# IsPackageAndDepsOkToInstall <pkg>
|
|
|
|
if ContainsSubstring "${packageIgnoreList}" "${1}"; then
|
2010-06-26 22:30:25 +04:00
|
|
|
#echo "...warning: ${1} cannot be installed"
|
2010-01-28 14:25:25 +03:00
|
|
|
return 1
|
2010-01-13 11:30:35 +03:00
|
|
|
fi
|
2010-01-28 14:25:25 +03:00
|
|
|
for foo in ${nonRepeatingDeps} ; do
|
|
|
|
if ContainsSubstring "${packageIgnoreList}" "${foo}"; then
|
2010-06-26 22:30:25 +04:00
|
|
|
#echo "...warning: ${1} cannot be installed because of ${foo}"
|
2010-01-28 14:25:25 +03:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
return 0
|
2010-01-13 11:30:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-21 19:18:47 +04:00
|
|
|
function BuildListOfRequestedPackages()
|
2010-01-13 11:30:35 +03:00
|
|
|
{
|
2010-04-21 19:51:17 +04:00
|
|
|
if [ "$1" = '-a' ] || [ "$1" = '-s' ]; then
|
2010-04-21 19:18:47 +04:00
|
|
|
shift
|
|
|
|
fi
|
|
|
|
while [ $# -gt 0 ]; do
|
2010-04-29 19:56:46 +04:00
|
|
|
local lowerCase=`echo $1 | tr '[A-Z]' '[a-z]'`
|
|
|
|
wantsToInstall="${wantsToInstall} $lowerCase"
|
2010-04-21 19:18:47 +04:00
|
|
|
shift
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function AddPackages()
|
|
|
|
{
|
|
|
|
# AddPackages
|
2010-04-29 19:50:22 +04:00
|
|
|
|
2010-01-28 14:25:25 +03:00
|
|
|
# If one or more packages can be installed, do it.
|
2010-04-21 19:51:17 +04:00
|
|
|
if BuildFinalListOfPackagesToInstall ; then
|
2010-04-29 19:50:22 +04:00
|
|
|
|
2010-01-28 14:25:25 +03:00
|
|
|
for package in ${packagesToInstall} ; do
|
|
|
|
# output the "if [ IsOptionalHaikuImagePackageAdded..." code block
|
2010-12-31 23:02:48 +03:00
|
|
|
local regExp="if\ \[\ IsOptionalHaikuImagePackageAdded\ ${package}\ "
|
2010-12-05 17:20:58 +03:00
|
|
|
for inputFile in OptionalPackages OptionalLibPackages ; do
|
|
|
|
sed -n "/^$regExp/,/^\}/p" "${baseDir}/${inputFile}" >> ${tmpDir}/optpkg.jam
|
|
|
|
done
|
2010-01-28 14:25:25 +03:00
|
|
|
done
|
2010-04-29 19:50:22 +04:00
|
|
|
|
2010-01-28 14:25:25 +03:00
|
|
|
ConvertJamToBash "${tmpDir}/optpkg.jam"
|
|
|
|
rm "${tmpDir}/optpkg.jam"
|
2010-06-24 01:28:41 +04:00
|
|
|
CreateInstallerScript
|
|
|
|
sh ${tmpDir}/install-optpkg.sh
|
2010-08-05 04:17:52 +04:00
|
|
|
exitcode=$?
|
|
|
|
if [ $exitcode -gt 0 ]; then
|
|
|
|
ErrorExit "... something went wrong when installing packages."
|
|
|
|
fi
|
2010-06-24 01:28:41 +04:00
|
|
|
rm ${tmpDir}/install-optpkg.sh
|
2010-06-26 22:30:25 +04:00
|
|
|
|
|
|
|
# update files to account for the newly installed packages
|
|
|
|
alreadyInstalled="${alreadyInstalled} ${packagesToInstall} "
|
2010-06-24 01:28:41 +04:00
|
|
|
RecordInstalledPackages
|
2010-06-26 22:30:25 +04:00
|
|
|
GeneratePackageNames
|
|
|
|
echo "... done."
|
2010-01-28 14:25:25 +03:00
|
|
|
fi
|
2010-01-13 11:30:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-21 19:51:17 +04:00
|
|
|
function BuildFinalListOfPackagesToInstall()
|
|
|
|
{
|
|
|
|
# BuildFinalListOfPackagesToInstall
|
2010-04-29 19:50:22 +04:00
|
|
|
|
2010-04-21 19:51:17 +04:00
|
|
|
packagesToInstall=""
|
|
|
|
proceedWithInstallation=false
|
2010-04-29 19:50:22 +04:00
|
|
|
|
2010-04-21 19:51:17 +04:00
|
|
|
for desiredPackage in ${wantsToInstall}; do
|
|
|
|
if IsPackageNameValid $desiredPackage ; then
|
|
|
|
for item in ${availablePackages[${desiredPackage}]} ; do
|
|
|
|
if ! ContainsSubstring "${packagesToInstall}" "${item}" ; then
|
|
|
|
packagesToInstall="${packagesToInstall} ${item}"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
proceedWithInstallation=true
|
|
|
|
fi
|
|
|
|
done
|
2010-06-24 01:28:41 +04:00
|
|
|
# pad the variable
|
|
|
|
packagesToInstall="${packagesToInstall} "
|
|
|
|
# remove entries that are already installed
|
|
|
|
for skip in ${alreadyInstalled}; do
|
|
|
|
packagesToInstall=${packagesToInstall/"${skip} "/}
|
|
|
|
done
|
|
|
|
# strip double spaces
|
|
|
|
packagesToInstall=${packagesToInstall/" "/" "}
|
|
|
|
|
2010-06-26 21:35:16 +04:00
|
|
|
if ! [ ${#packagesToInstall} -gt 1 ]; then
|
2010-06-24 01:28:41 +04:00
|
|
|
echo "... no packages need to be installed."
|
2010-08-05 04:17:52 +04:00
|
|
|
echo ""
|
|
|
|
echo "If you wish to re-install a package, run these two commands"
|
|
|
|
echo " rm ${baseDir}/OptionalPackageNames"
|
|
|
|
echo " open $installedPackagesFile"
|
|
|
|
echo "and delete the line containing the package name(s)."
|
|
|
|
echo ""
|
2010-06-24 01:28:41 +04:00
|
|
|
proceedWithInstallation=false
|
|
|
|
fi
|
|
|
|
if ! $proceedWithInstallation ; then
|
|
|
|
echo 'Not proceeding with installation.'
|
2010-04-21 19:51:17 +04:00
|
|
|
return 1
|
|
|
|
fi
|
2010-06-24 01:28:41 +04:00
|
|
|
echo "To be installed: ${packagesToInstall}"
|
|
|
|
return 0
|
2010-04-21 19:51:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-28 14:25:25 +03:00
|
|
|
function IsPackageNameValid()
|
2010-01-13 11:30:35 +03:00
|
|
|
{
|
2010-01-28 14:25:25 +03:00
|
|
|
# IsPackageNameValid <name>
|
|
|
|
for name in ${availablePackagesKeys} ; do
|
|
|
|
if [ "$1" == "$name" ] ; then
|
|
|
|
return 0
|
2010-01-13 11:30:35 +03:00
|
|
|
fi
|
2010-01-28 14:25:25 +03:00
|
|
|
done
|
|
|
|
return 1
|
2010-01-13 11:30:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-24 01:28:41 +04:00
|
|
|
function RecordInstalledPackages()
|
|
|
|
{
|
2010-06-26 22:30:25 +04:00
|
|
|
echo -e ${alreadyInstalled} | tr '\ ' '\n' | sort > ${installedPackagesFile}
|
2010-06-24 01:28:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-13 11:30:35 +03:00
|
|
|
function ConvertJamToBash()
|
|
|
|
{
|
|
|
|
# ConvertJamToBash <input file>
|
|
|
|
# The main Jam-to-Bash conversion function.
|
|
|
|
local inputFile=$1
|
|
|
|
declare -a generatedBash
|
|
|
|
countGenBashLine=0
|
2010-04-29 19:50:22 +04:00
|
|
|
|
2010-01-13 11:30:35 +03:00
|
|
|
# Parse out some variable declarations
|
2010-07-20 20:48:21 +04:00
|
|
|
|
|
|
|
# TODO : add these following variables to the CreateInstallerScript
|
|
|
|
# TODO : parse HAIKU_ICU_GCC_2_PACKAGE
|
|
|
|
#local regExp='/^HAIKU_ICU_GCC_2_PACKAGE/p'
|
|
|
|
#icuGcc2PkgLine=`sed -n -e "$regExp" ${baseDir}/OptionalBuildFeatures`
|
|
|
|
#ConvertVariableDeclarationLines "$regExp" 'icuGcc2PkgLine'
|
|
|
|
|
|
|
|
# TODO : parse HAIKU_ICU_GCC_4_PACKAGE
|
|
|
|
#local regExp='/^HAIKU_ICU_GCC_4_PACKAGE/p'
|
|
|
|
#icuGcc4PkgLine=`sed -n -e "$regExp" ${baseDir}/OptionalBuildFeatures`
|
|
|
|
#ConvertVariableDeclarationLines "$regExp" 'icuGcc4PkgLine'
|
|
|
|
|
|
|
|
# TODO : parse HAIKU_ICU_DEVEL_PACKAGE
|
|
|
|
#local regExp='/^HAIKU_ICU_DEVEL_PACKAGE/p'
|
|
|
|
#icuDevelPkgLine=`sed -n -e "$regExp" ${baseDir}/OptionalBuildFeatures`
|
|
|
|
#ConvertVariableDeclarationLines "$regExp" 'icuDevelPkgLine'
|
|
|
|
|
2010-01-13 11:30:35 +03:00
|
|
|
local regExp='/^HAIKU_OPENSSL_PACKAGE/p'
|
|
|
|
sslPkgLine=`sed -n -e "$regExp" ${baseDir}/OptionalBuildFeatures`
|
|
|
|
ConvertVariableDeclarationLines "$regExp" 'sslPkgLine'
|
2010-04-29 19:50:22 +04:00
|
|
|
|
2010-01-13 11:30:35 +03:00
|
|
|
local regExp='/^HAIKU_OPENSSL_URL/p'
|
|
|
|
sslUrlLine=`sed -n -e "$regExp" ${baseDir}/OptionalBuildFeatures`
|
|
|
|
ConvertVariableDeclarationLines "$regExp" 'sslUrlLine'
|
2010-04-29 19:50:22 +04:00
|
|
|
|
2010-01-13 11:30:35 +03:00
|
|
|
local regExp='/^local\ baseURL/p'
|
|
|
|
urlLine=`sed -n -e "$regExp" ${baseDir}/OptionalPackages`
|
|
|
|
urlLine=${urlLine/local\ /''}
|
|
|
|
ConvertVariableDeclarationLines "$regExp" 'urlLine'
|
2010-04-29 19:50:22 +04:00
|
|
|
|
2010-01-13 11:30:35 +03:00
|
|
|
# Convert the easy bits.
|
|
|
|
while read line ; do
|
|
|
|
line=${line/'Echo'/'echo'}
|
2010-04-29 19:50:22 +04:00
|
|
|
|
2010-07-20 20:48:21 +04:00
|
|
|
# TODO: add support for converting for loops.
|
|
|
|
# will need to introduce curly brace counting
|
2010-01-13 11:30:35 +03:00
|
|
|
ConvertIfStatements "$line"
|
|
|
|
ConvertVariables "$line"
|
2010-04-13 01:48:18 +04:00
|
|
|
#ReplaceComparators "$line"
|
2010-04-29 19:50:22 +04:00
|
|
|
|
2010-01-13 11:30:35 +03:00
|
|
|
line=${line/"IsOptionalHaikuImagePackageAdded"/'"SomeText" !='}
|
|
|
|
generatedBash[$countGenBashLine]=${line}
|
|
|
|
((countGenBashLine++))
|
|
|
|
done < ${tmpDir}/optpkg.jam
|
2010-04-29 19:50:22 +04:00
|
|
|
|
2010-01-13 11:30:35 +03:00
|
|
|
# output stage 1 generated code
|
|
|
|
local i=0
|
|
|
|
while [ $i -lt $countGenBashLine ] ; do
|
|
|
|
echo ${generatedBash[$i]} >> ${tmpDir}/optpkg.stage1
|
|
|
|
((i++))
|
|
|
|
done
|
2010-04-29 19:50:22 +04:00
|
|
|
|
2010-01-13 11:30:35 +03:00
|
|
|
# This converts multi-line jam statements into a single line.
|
|
|
|
# --- Start awk ---
|
|
|
|
awk '
|
|
|
|
/InstallOptionalHaikuImagePackage/,/\;/{
|
|
|
|
isRule=1;
|
2010-04-29 19:50:22 +04:00
|
|
|
if($0~/\;/) ORS="\n";
|
|
|
|
else ORS=" "; print
|
|
|
|
}
|
2010-01-13 11:30:35 +03:00
|
|
|
/AddSymlinkToHaikuImage/,/\;/{
|
|
|
|
isRule=1;
|
|
|
|
if($0~/\;/) ORS="\n";
|
2010-04-29 19:50:22 +04:00
|
|
|
else ORS=" "; print
|
|
|
|
}
|
|
|
|
/AddUserToHaikuImage/,/\;/{
|
|
|
|
isRule=1;
|
|
|
|
if($0~/\;/) ORS="\n";
|
|
|
|
else ORS=" "; print
|
2010-01-13 11:30:35 +03:00
|
|
|
}
|
2010-03-18 20:14:19 +03:00
|
|
|
/AddExpanderRuleToHaikuImage/,/\;/{
|
2010-04-29 19:50:22 +04:00
|
|
|
isRule=1;
|
|
|
|
if($0~/\;/) ORS="\n";
|
|
|
|
else ORS=" "; print
|
2010-03-18 20:14:19 +03:00
|
|
|
}
|
2010-01-13 11:30:35 +03:00
|
|
|
/Exit/,/\;/{
|
|
|
|
isRule=1;
|
2010-04-29 19:50:22 +04:00
|
|
|
if($0~/\;/) ORS="\n";
|
2010-01-13 11:30:35 +03:00
|
|
|
else ORS=" "; print
|
2010-04-29 19:50:22 +04:00
|
|
|
}
|
2010-01-13 11:30:35 +03:00
|
|
|
{
|
|
|
|
if($1!='InstallOptionalHaikuImagePackage' && isRule!=1 && $1!="\;")
|
|
|
|
print $0
|
|
|
|
}
|
|
|
|
{ isRule=0; }
|
|
|
|
' ${tmpDir}/optpkg.stage1 > ${tmpDir}/optpkg.stage2 2>/dev/null
|
|
|
|
# --- End awk ---
|
|
|
|
rm ${tmpDir}/optpkg.stage1
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-28 14:25:25 +03:00
|
|
|
function ConvertVariableDeclarationLines()
|
2010-01-13 11:30:35 +03:00
|
|
|
{
|
2010-01-28 14:25:25 +03:00
|
|
|
# ConvertVariableDeclarationLines <regex> <variable>
|
|
|
|
# One of the Jam-to-Bash conversion functions.
|
|
|
|
# Jam lines that define variables need to be parsed differently.
|
|
|
|
eval local input='$'"$2"
|
|
|
|
local regex="$1"
|
|
|
|
local _outvar="$2"
|
2010-04-29 19:50:22 +04:00
|
|
|
|
2010-01-28 14:25:25 +03:00
|
|
|
input=${input/\ =\ /=}
|
|
|
|
input=${input/\;/''}
|
|
|
|
input=${input//\(/'{'}
|
|
|
|
input=${input//\)/'}'}
|
2010-04-29 19:50:22 +04:00
|
|
|
|
2010-01-28 14:25:25 +03:00
|
|
|
eval $_outvar="'$input'"
|
2010-01-13 11:30:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-28 14:25:25 +03:00
|
|
|
function ConvertIfStatements()
|
2010-01-13 11:30:35 +03:00
|
|
|
{
|
2010-04-29 19:50:22 +04:00
|
|
|
# ConvertIfStatements <line>
|
2010-01-28 14:25:25 +03:00
|
|
|
# One of the Jam-to-Bash conversion functions.
|
|
|
|
line=${line//'} else {'/'else '}
|
|
|
|
line=${line//'} else if '/'elif '}
|
|
|
|
if ContainsSubstring "$line" "if " ; then
|
|
|
|
if ! ContainsSubstring "$line" "if [" ; then
|
|
|
|
line=${line/'if '/'if [ '}
|
|
|
|
fi
|
2010-04-29 19:50:22 +04:00
|
|
|
|
2010-01-28 14:25:25 +03:00
|
|
|
if ContainsSubstring "$line" '] {' ; then
|
|
|
|
line=${line/'{'/' ; then'}
|
|
|
|
elif ContainsSubstring "$line" '{' ; then
|
|
|
|
line=${line/'{'/' ] ; then'}
|
|
|
|
fi
|
2010-04-29 19:50:22 +04:00
|
|
|
|
2010-01-28 14:25:25 +03:00
|
|
|
for compound in '&&' '||' ; do
|
|
|
|
if ContainsSubstring "$line" "$compound" ; then
|
|
|
|
line=${line/"$compound"/"] $compound ["}
|
|
|
|
fi
|
2010-01-13 11:30:35 +03:00
|
|
|
done
|
2010-04-13 01:48:18 +04:00
|
|
|
ReplaceComparators "$line"
|
2010-01-13 11:30:35 +03:00
|
|
|
fi
|
2010-01-28 14:25:25 +03:00
|
|
|
# Assume all remaining closing braces are part of if statements
|
|
|
|
line=${line/'}'/'fi'}
|
2010-01-13 11:30:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-28 14:25:25 +03:00
|
|
|
function ConvertVariables()
|
2010-01-13 11:30:35 +03:00
|
|
|
{
|
2010-01-28 14:25:25 +03:00
|
|
|
# ConvertVariables
|
|
|
|
# One of the Jam-to-Bash conversion functions.
|
2010-04-29 19:50:22 +04:00
|
|
|
|
2010-01-28 14:25:25 +03:00
|
|
|
# NOTE: jam's variables are normally '$(VARIABLE)'. \n
|
|
|
|
# The issue is with '(' and ')', so let's replace them globally.
|
|
|
|
if ContainsSubstring "$line" '$(' ; then
|
|
|
|
line=${line//'('/'{'}
|
|
|
|
line=${line//')'/'}'}
|
|
|
|
fi
|
2010-01-13 11:30:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-28 14:25:25 +03:00
|
|
|
function ReplaceComparators()
|
2010-01-13 11:30:35 +03:00
|
|
|
{
|
2010-01-28 14:25:25 +03:00
|
|
|
# ReplaceComparators <line>
|
|
|
|
# One of the Jam-to-Bash conversion functions.
|
2010-04-29 19:50:22 +04:00
|
|
|
|
2010-01-28 14:25:25 +03:00
|
|
|
# Preserve string comparators for TARGET_ARCH.
|
|
|
|
if ! ContainsSubstring "$line" 'TARGET_ARCH' ; then
|
|
|
|
line=${line//'>='/'-ge'}
|
|
|
|
line=${line//'<='/'-le'}
|
|
|
|
line=${line//'>'/'-gt'}
|
|
|
|
line=${line//'<'/'-lt'}
|
|
|
|
line=${line//'!='/'-ne'}
|
2010-04-13 01:48:18 +04:00
|
|
|
line=${line//'='/'-eq'}
|
2010-01-13 11:30:35 +03:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2010-01-28 14:25:25 +03:00
|
|
|
|
|
|
|
function DisplayUsage()
|
2010-01-13 11:30:35 +03:00
|
|
|
{
|
2010-05-15 07:55:58 +04:00
|
|
|
echo -e "$DISCLAIMER"
|
|
|
|
echo -e "$USAGE"
|
2010-01-28 14:25:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-21 18:07:19 +04:00
|
|
|
function RemoveCachedFiles()
|
|
|
|
{
|
|
|
|
# RemoveCachedFiles
|
|
|
|
echo "Removing cached files ..."
|
2010-07-11 02:38:47 +04:00
|
|
|
if [ -e ${baseDir}/OptionalPackageNames ]; then
|
|
|
|
rm ${baseDir}/OptionalPackageNames
|
2010-04-21 18:07:19 +04:00
|
|
|
fi
|
2010-04-29 19:50:22 +04:00
|
|
|
|
2010-04-21 18:07:19 +04:00
|
|
|
# Unset variables, which prevents duplicate entries.
|
|
|
|
declare -A availablePackages
|
|
|
|
declare availablePackagesKeys=""
|
2010-04-29 19:50:22 +04:00
|
|
|
|
2010-04-21 18:07:19 +04:00
|
|
|
# Reinitialize
|
|
|
|
Init
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-28 14:25:25 +03:00
|
|
|
function ListPackages()
|
|
|
|
{
|
|
|
|
# ListPackages
|
2010-06-26 22:30:25 +04:00
|
|
|
echo ""
|
|
|
|
echo "Optional Packages that have been installed:"
|
|
|
|
echo ${alreadyInstalled}
|
|
|
|
|
2010-01-28 14:25:25 +03:00
|
|
|
echo ""
|
|
|
|
echo ""
|
2010-06-26 22:30:25 +04:00
|
|
|
echo "Installable Optional Packages:"
|
2010-04-29 19:50:22 +04:00
|
|
|
|
2010-01-28 14:25:25 +03:00
|
|
|
# single line:
|
|
|
|
echo ${availablePackagesKeys}
|
2010-04-29 19:50:22 +04:00
|
|
|
|
2010-01-28 14:25:25 +03:00
|
|
|
# one per line:
|
|
|
|
#for package in ${availablePackagesKeys} ; do
|
|
|
|
# echo ${package}
|
|
|
|
#done
|
2010-01-13 11:30:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# If no arguments were passed to the script, display its usage and exit.
|
|
|
|
if [ "$#" -lt 1 ] ; then
|
|
|
|
DisplayUsage
|
|
|
|
exit 0
|
|
|
|
else
|
|
|
|
Init
|
|
|
|
fi
|
|
|
|
|
2010-04-21 19:18:47 +04:00
|
|
|
# Support `installoptionalpackage <pkg> <pkg> ...`
|
2010-04-21 19:51:17 +04:00
|
|
|
if [ "$1" != '-f' ] && [ "$1" != '-l' ] && [ "$1" != '-h' ] \
|
|
|
|
&& [ "$1" != '-s' ]; then
|
2010-04-21 19:18:47 +04:00
|
|
|
BuildListOfRequestedPackages $@
|
|
|
|
AddPackages
|
|
|
|
exit 0
|
2010-04-29 19:50:22 +04:00
|
|
|
fi
|
2010-04-21 19:18:47 +04:00
|
|
|
|
2010-01-13 11:30:35 +03:00
|
|
|
# Parse the arguments given to the script.
|
2010-04-21 19:51:17 +04:00
|
|
|
while getopts "as:fhl" opt; do
|
2010-01-13 11:30:35 +03:00
|
|
|
case $opt in
|
|
|
|
a)
|
2010-04-21 19:18:47 +04:00
|
|
|
BuildListOfRequestedPackages $@
|
|
|
|
AddPackages
|
2010-01-13 11:30:35 +03:00
|
|
|
exit 0
|
|
|
|
;;
|
2010-04-21 18:07:19 +04:00
|
|
|
f)
|
|
|
|
RemoveCachedFiles
|
|
|
|
ListPackages
|
|
|
|
exit 0
|
|
|
|
;;
|
2010-01-13 11:30:35 +03:00
|
|
|
h)
|
|
|
|
DisplayUsage
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
l)
|
|
|
|
ListPackages
|
|
|
|
exit 0
|
|
|
|
;;
|
2010-04-21 19:51:17 +04:00
|
|
|
s)
|
|
|
|
BuildListOfRequestedPackages $@
|
|
|
|
BuildFinalListOfPackagesToInstall
|
|
|
|
exit 0
|
|
|
|
;;
|
2010-01-13 11:30:35 +03:00
|
|
|
\?)
|
|
|
|
echo "Invalid option: -$OPTARG" >&2
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
:)
|
|
|
|
echo "Option -$OPTARG requires an argument." >&2
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|