if[ ! -x "`which $1`"];then#check if $1 is in $PATH and can be executed
ERROR_TEXT="Amarok-svn requires $1, which wasn't found in your \$PATH!"
if["$2"];then
ERROR_TEXT="$ERROR_TEXT ($2)"
fi
Error "$ERROR_TEXT"$3
fi
}
function FlagUsage {
echo"Usage: $0 [options] [builddir]"
echo
echo"Amarok-svn installs the current development (SVN) version of Amarok on your computer."
echo
echo"Options:"
echo -e " -r, --reset\t\tAsk for settings again."
echo -e " -s, --select-server\tAsk which SVN server to use. (Only needed if you want to use your SVN account.)"
echo -e " -c, --clean\t\tClean the source tree before compiling Amarok."
echo -e " -h, --help\t\tShow this message."
echo
echo"Arguments:"
echo -e " builddir\t\tDownload and build Amarok in this directory. Default is '[your current dir]/amarok-svn'."
echo
echo"Notes:"
echo" * Options can NOT be fused together! (I.E. You can't use '-cr', you have to use '-c -r'.)"
echo" * Amarok-svn will download the Amarok sources directly into the folder you choose, without creating any subdirectory!"
echo
exit1
}
function Clean {
unsermake clean
if["$?" !="0"];then#If the command didn't finish successfully
Error "Failed to clean the source tree!"
fi
}
function Compile {
COMP_START=`date +%s`
#Run unsermake twice because of some files that gets forgotten sometimes
#(We don't want to compile as root in unsermake install, and it doesn't hurt)
unsermake && unsermake
if["$?"="0"];then#If the command did finish successfully
echo
#stopwatch.
letCOMP_TIME=`date +%s`-COMP_START
letCOMP_M=COMP_TIME/60
letCOMP_S=COMP_TIME%60
echo"Compilation successful after $COMP_M minute(s) and $COMP_S second(s)."
else
echo
if["$CLEAN_BUILD"="0"];then
echo"Compilation Failed!"
Dialog --warningyesno "Compilation failed!\nSometimes, a clean rebuild can fix this.\nDo you want to retry compiling with a clean source tree?\nIf you answer No, Amarok-svn will exit."
if["$?"="0"];then#If user said yes
echo"Retrying with a clean source tree."
CLEAN_BUILD="1"
Clean
Compile
else
Error "Compilation failed! Amarok was NOT installed/updated."
fi
else
Error "Compilation failed! Amarok was NOT installed/updated."
CheckBinary kde-config "kde-config sometimes falls out of the \$PATH for some reason."
CheckBinary kreadconfig
CheckBinary kwriteconfig
## Check the build directory
if[ -e "$BUILD_DIR" -a ! -f "$BUILD_DIR/.amarok-svn-dir"];then#if directory exist and isn't watermarked
if[ -d "$BUILD_DIR"];then
Dialog --warningyesno "The directory you choosed to build in ($BUILD_DIR) already exists, and it wasn't detected as an Amarok-svn directory.\nFiles in this directory can possibly be overwritten by the Amarok-svn procedures.\nDo you want to use this directory anyway?"
if["$?" !="0"];then#If the user said no, exit.
exit1
fi
else
Error "The build directory you have chosen exists, but it's not a directory!"
fi
fi
## Check if user is root
if["`id -u`"="0"];then#if user is root
Dialog --warningcontinuecancel "You are running Amarok-svn as root! This is not required, and generally not a good idea.\n(Amarok-svn will get root privileges by itself when needed, see the settings for details.)\nAre you sure you want to continue anyway?" --dontagain $RCFILE:root_warning
if["$?" !="0"];then#If the user said cancel.
exit1
fi
fi
## Settings
if[ -s "`kde-config --localprefix`/share/config/$RCFILE" -a "$RESET_CONF" !="1"];then#If the settings exists and the user doesn't want to change them.
GET_LANG="`ReadConfig get_lang`"
if[ -z "$GET_LANG"];then#Save default value if empty
GET_LANG="en_US"
WriteConfig get_lang "$GET_LANG"
fi
CONF_FLAGS_RAW="`ReadConfig conf_flags`"
CONF_FLAGS=""
for flag in $CONF_FLAGS_RAW;do
CONF_FLAGS="$CONF_FLAGS `echo $flag | sed -e \"s/__/--/\"`"
done
HOW_ROOT="`ReadConfig how_root`"
if[ -z "$HOW_ROOT"];then#Save default value if empty
if[ -z "$USE_ID"];then#Save default value if empty
USE_ID="0"
WriteConfig use_id "$USE_ID"
fi
else
## Language
AUTO_LANG="`kreadconfig --group Locale --key Language | sed -re \"s/:.+//\"`"
if["$AUTO_LANG" !=""];then#Generally, if the user is running KDE
Dialog --yesno "I detected that you are running KDE with language '$AUTO_LANG'.\nIf this is correct (and you want it that way), I will download localization and documentation for Amarok in that language.\nDo you want this language?"
fi
if["$?"="0" -a "$AUTO_LANG" !=""];then#If the user said yes, and is running KDE...
GET_LANG="$AUTO_LANG"
else
Dialog --msgbox "Which language do you want to download localization and documentation for?\nA list of available languages is available at http://websvn.kde.org/trunk/l10n/ (It is CaSe sensitive!)\nIf you want to use the default language (American English), either leave this empty or set it to 'en_US' (it's not in the list above).\n(Click Ok to get to the input box.)"
GET_LANG="`Dialog --inputbox \"Specify language to download localization and documentation for\"`"
fi
if[ -z "$GET_LANG"];then
GET_LANG="en_US"
fi
WriteConfig get_lang "$GET_LANG"
## ./configure flags
Dialog --yesno "Do you want to use any extra configuration options (in addition to '--prefix=`kde-config --prefix` --enable-debug=full')?\nNo extra options is the default, and that works fine.\n(For a list of available flags, say yes and enter 'help' (CaSe insensitive) in the box, then wait for Amarok-svn to get to the configuration step (step 8).)"
if["$?"="0"];then#If the user said yes
CONF_FLAGS_RAW="`Dialog --inputbox \"Specify extra configuration options to use\"`"
HOW_ROOT="`kdialog --radiolist \"How do you want Amarok-svn to get root privileges for the install/uninstall commands?\" tdesu \"With 'tdesu' (default, choose this if unsure)\" on sudo \"With 'sudo'\" off \"su -c\" \"With 'su -c'\" off`"
Dialog --yesno "Do you want to use build ID?\nThis feature is generally not needed, and often makes the compiling time longer.\nIf you use it, you can tell from the About box in Amarok when your revision was compiled.\nDefault answer is No, you can get this information from other places."
if["$?"="0"];then#If the user said yes
USE_ID="1"
fi
WriteConfig use_id "$USE_ID"
fi
if["$SELECT_SERVER"="1"];then#SVN server selection
WriteConfig svn_server "`kdialog --title \"$KD_TITLE\" --inputbox \"Specify which SVN server you want to use. Default is 'svn://anonsvn.kde.org'.\"`"
fi
SVN_SERVER="`ReadConfig svn_server`"
if[ -z "$SVN_SERVER"];then#Save default value if empty
SVN_SERVER="svn://anonsvn.kde.org"
WriteConfig svn_server "$SVN_SERVER"
fi
## Start the installation process and show the settings
INST_START=`date +%s`
echo"Used configuration"
echo"--------------------"
echo"(Use --help to get information on how to change it.)"
echo
echo -e "SVN server:\t\t\t\t\t$SVN_SERVER"
echo -e "Language for localization and documentation:\t$GET_LANG"
if["$CONF_HELP" !="true" -a "`echo $CONF_FLAGS`"];then
echo"# $C_STEP/$S_STEPS - Checking out base files."
svn co -N $SVN_SERVER/home/kde/branches/stable/extragear/multimedia $BUILD_DIR
if["$?" !="0"];then#If the command didn't finish successfully
Error "The SVN transfer didn't finish successfully."
fi
cd$BUILD_DIR
touch .amarok-svn-dir #Watermark the directory
## Get unsermake, if not installed already
echo
letC_STEP=C_STEP+1
echo"# $C_STEP/$S_STEPS - Getting unsermake."
if[ -x "`which unsermake`"];then#unsermake installed system wide?
echo"Unsermake is already installed system wide."
else
PATH="$BUILD_DIR/unsermake:$PATH"
if[ -x "`which unsermake`"];then#Is unsermake installed and in the $PATH now?
echo"Unsermake downloaded by this script. Checking for update."
else
echo"Unsermake wasn't found. Downloading it to '$BUILD_DIR/unsermake'."
fi
svn co -N $SVN_SERVER/home/kde/tags/unmaintained/3/unsermake
if["$?" !="0"];then#If the command didn't finish successfully
Error "The SVN transfer failed."
fi
fi
## Store the old uninstall commands
echo
letC_STEP=C_STEP+1
echo"# $C_STEP/$S_STEPS - Saving uninstall commands for your current revision."
if[ ! -f "Makefile"];then
echo"No current revision was found."
else
TMP_OLD_UNINFO="`mktemp`"
TEMP_FILES="$TMP_OLD_UNINFO"
unsermake -n uninstall > $TMP_OLD_UNINFO#Stored in a file so we can run it later, in a simple manner.
if["$?" !="0"];then#If the command didn't finish successfully
Error "Couldn't get uninstall commands for your current revision."
else
echo"Done."
fi
fi
## Continue checkout
echo
letC_STEP=C_STEP+1
echo"# $C_STEP/$S_STEPS - Checking out common SVN files."
svn co $SVN_SERVER/home/kde/branches/KDE/3.5/kde-common/admin #URL changed since KDE 3.5 branching
if["$?" !="0"];then#If the command didn't finish successfully
RemoveTemp
Error "The SVN transfer failed."
fi
echo
letC_STEP=C_STEP+1
echo"# $C_STEP/$S_STEPS - Updating Amarok files."
svn up amarok
if["$?" !="0"];then#If the command didn't finish successfully
RemoveTemp
Error "The SVN transfer failed.\nIf the message from svn (in console) is something like 'amarok is not under version control', you need a never version of svn.\nAt least version 1.1 is needed."
fi
if["$USE_ID"="1"];then
#Append build ID (date and time with no punctuation) to version
sed -re "s/^#define APP_VERSION \"(.*)-SVN.*\"/#define APP_VERSION \"\1-SVN-`date +%y%m%d%H%M`\"/" -i amarok/src/amarok.h
echo"Appended build ID to version number."
fi
echo
letC_STEP=C_STEP+1
echo"# $C_STEP/$S_STEPS - Getting localization and documentation:"
ENGD_STEP=""
if["$GET_LANG" !="en_US"];then#If a language (not en_US) is selected
## Localization
echo"- # 1/4 - Checking if localization for selected language exists."
svn ls $SVN_SERVER/home/kde/trunk/l10n/$GET_LANG/messages/extragear-multimedia/amarok.po > /dev/null 2>&1#Check if language exists
if["$?" !="0"];then#If the localization wasn't found
GET_LANG="en_US"
echo"WARNING: Localization for selected language was not found. Reverting to 'en_US'."
else#If localization exists
echo"- # 2/4 - Updating localization file."
if[ ! -d "po"];then
mkdir po
fi
cd po
echo"SUBDIRS = $GET_LANG" > Makefile.am
if[ ! -d $GET_LANG];then
mkdir $GET_LANG
fi
cd$GET_LANG
echo"KDE_LANG = $GET_LANG" > Makefile.am
echo"SUBDIRS = \$(AUTODIRS)" >> Makefile.am
echo"POFILES = AUTO" >> Makefile.am
echo"Downloading current localization file from server."
TMP_L10N="`mktemp`"
TMP_FILES="$TMP_FILES$TMP_L10N"
svn cat $SVN_SERVER/home/kde/trunk/l10n/$GET_LANG/messages/extragear-multimedia/amarok.po 2> /dev/null | tee $TMP_L10N > /dev/null
if["$?" !="0"];then#If the command didn't finish successfully
Error "The SVN transfer didn't finish successfully."
fi
if[ ! -s "$TMP_L10N"];then
echo"WARNING: The downloaded file was empty!"
echo"Some error must have occured."
rm -f Makefile.am
rm -f ../Makefile.am
echo"No localization downloaded, so no localization will be installed!"
elif[ -f "amarok.po"];then
if[ -z "`diff -q $TMP_L10N amarok.po 2>&1`"];then
echo"You already have the current version of the localization file."
else
echo"New localization file downloaded."
rm -f amarok.po
mv -f $TMP_L10N amarok.po
echo"Replaced the old copy with the downloaded version."
fi
else
mv -f $TMP_L10N amarok.po
echo"Localization file downloaded."
fi
cd ../..
## Localized documentation
echo"- # 3/4 - Checking if localized documentation for selected language exists."
svn ls $SVN_SERVER/home/kde/trunk/l10n/$GET_LANG/docs/extragear-multimedia/amarok > /dev/null 2>&1#Check if localized documentation exists
if["$?" !="0"];then#If the localized documentation wasn't found
GET_LANG="en_US"
echo"WARNING: Localized documentation for selected language was not found. Reverting to default (American English) documentation."
ENGD_STEP=" 4/4 -"
else#If a localized documentation exists
echo"- # 4/4 - Checking out localized documentation."
if[ ! -d "doc"];then
mkdir doc
fi
cd doc
echo"SUBDIRS = $GET_LANG" > Makefile.am
svn co $SVN_SERVER/home/kde/trunk/l10n/$GET_LANG/docs/extragear-multimedia/amarok $GET_LANG
if["$?" !="0"];then#If the command didn't finish successfully
Error "The SVN transfer failed."
fi
cd$GET_LANG
echo"KDE_LANG = $GET_LANG" > Makefile.am
echo"KDE_DOCS = amarok" >> Makefile.am
cd ../..
fi
fi
fi
if["$GET_LANG"="en_US"];then#If no language (en_US) is selected. This is a stand alone if-statement to enable fallbacks when selected language isn't found.
## Default (American English) documentation
echo"- #$ENGD_STEP Checking out default (American English) documentation."
if[ ! -d "doc"];then
mkdir doc
fi
cd doc
echo"SUBDIRS = en" > Makefile.am
svn co $SVN_SERVER/home/kde/trunk/extragear/multimedia/doc/amarok en
if["$?" !="0"];then#If the command didn't finish successfully
Error "The SVN transfer failed."
fi
cd en
echo"KDE_LANG = en" > Makefile.am
echo"KDE_DOCS = amarok" >> Makefile.am
cd ../..
fi
## Preparation
echo
letC_STEP=C_STEP+1
echo"# $C_STEP/$S_STEPS - Preparing for configuration. (This will take a while.)"
WANT_AUTOCONF="2.5" unsermake -f Makefile.cvs
if["$?" !="0"];then#If the command didn't finish successfully
Error "Preparation failed.\nProblems at this step are quite certainly problems with either unsermake or your automake configuration."
fi
echo -n "*** Patching the configure script to show when it fails... "
echo -e "\nif test \"\$all_tests\" = \"bad\"; then\n exit 1\nfi" >> configure #Does its job, albeit a little bit ugly...
if["$?" !="0"];then#If the command didn't finish successfully
echo"Fail. Amarok will compile even if some dependencies aren't met!"
KDTITLE=" :: Configuration options" Dialog --textbox $TMP_CONF600800̠x600 should be enough. Put it in the background (&) to make the user able to watch it while typing the selected options into the input box.
Dialog --yesno "Do you want to use any extra configuration options (in addition to '--prefix=`kde-config --prefix` --enable-debug=full')?\nNo extra options is the default, and that works fine.\n(Available options are displayed in another window right now.)"
if["$?"="0"];then#If the user said yes
CONF_FLAGS_RAW="`kdialog --title \"$KD_TITLE\" --inputbox \"Specify extra configuration options to use\"`"
CONF_FLAGS=""
CONF_FLAGS_SAVE=""
for flag in $CONF_FLAGS_RAW;do
if["$flag" !="--help"];then
CONF_FLAGS="$CONF_FLAGS$flag"
CONF_FLAGS_SAVE="$CONF_FLAGS_SAVE `echo $flag | sed -e \"s/--/__/\"`"
if["$?"="0"];then#If the command did finish successfully
#stopwatch.
letINST_TIME=`date +%s`-INST_START
letINST_M=INST_TIME/60
letINST_S=INST_TIME%60
echo
echo -e "# DONE - Amarok was successfully installed/updated after $INST_M minute(s) and $INST_S second(s)."
Dialog --msgbox "Done!\nAmarok was successfully installed/updated after $INST_M minute(s) and $INST_S second(s).\nCompilation took $COMP_M minute(s) and $COMP_S second(s).\nStart Amarok from your menu or by running the command \"amarok\"."
exit0#Exit succsessfully
else
echo
Error "Amarok was compiled but NOT installed.\nIf the errors above seem to be permission errors, you could try installing Amarok manually.\n(You also might want to have a look at the settings for this script, use --help to see how.)\nTo install manually, get root privileges in some way and then run 'unsermake install' in the '$BUILD_DIR' directory."