Ubuntu TrueType fonts installation helper for Fedora 15 Lovelock (and above)
This page provides a bash script for an easier installation of the Ubuntu TrueType fonts. I think it is useful because there is only a ubuntu-title-fonts
package included in the main repositories right now. See the main article for details:
Open a terminal and run the following commands to download and execute it (copy and paste recommended):
wget "http://blog.andreas-haerter.com/_export/code/2011/07/18/install-ubuntufonts-fedora.sh?codeblock=1" -O "/tmp/install-ubuntufonts-fedora.sh" chmod a+rx "/tmp/install-ubuntufonts-fedora.sh" su -c "/tmp/install-ubuntufonts-fedora.sh"
- install-ubuntufonts-fedora.sh
#!/bin/bash ################################################################################ # Ubuntu fonts installation helper for Fedora Linux # # This script is installing the fonts without any untrustworthy RPMs or build- # hazzle. I think it is useful because there is only a "ubuntu-title-fonts" # package included in the main repositories right now. # Please note that the yum/RPM database is bypassed, so you can't uninstall # the fonts by using yum erase/remove. # # Tested on the following Fedora versions: # - Fedora 15 Lovelock # # I don't have the time to test *every* version out there. Therefore it does not # mean that this script does not work if your version is not listed above. Just # try it out and check for an update of this script after a new version of # Fedora is released: # <http://blog.andreas-haerter.com/2011/07/18/install-ubuntufonts-fedora.sh> # # Usage: # 1) Call this script with SUPERUSER privileges (->su -c, sudo ...) # 2) If something fails, correct the thing which prevents the successful # execution and call it again. This script is designed in a way that # re-calling it should be no problem. # # Please note that the yum/RPM database is bypassed, so you can't uninstall # the fonts by using "yum erase/remove". But you may run the following commands # to get rid of the fonts: # 1) su -c 'rm -rf "/usr/share/fonts/ubuntu/"' # 2) fc-cache -fv # # Please read the UBUNTU FONT LICENCE (<http://bit.ly/ajeQvv>) for all the rules # that govern the use of the fonts. # # LICENSE: This file is open source software (OSS) and may be copied under # certain conditions. See the links below for details or try to contact # the author(s) of this file in doubt. # # @author Andreas Haerter <development@andreas-haerter.com> # @copyright 2011, Andreas Haerter # @license GPLv2 (http://www.gnu.org/licenses/gpl2.html) # @license New/3-clause BSD (http://opensource.org/licenses/bsd-license.php) # @link http://blog.andreas-haerter.com/2011/07/18/install-ubuntufonts-fedora.sh # @link http://andreas-haerter.com # @link http://font.ubuntu.com/ # @version 2011-07-18 ################################################################################ ################################################################################ # Configuration ################################################################################ #Download mirrors #Note: I did not add Google Webfonts API as additional mirror because they # provide an archive with differing TTF file names. FNT_DLMIRRORS[(${#FNT_DLMIRRORS[@]})]="http://font.ubuntu.com/download/" #Files to download + checksums FNT_DLFILES[(${#FNT_DLFILES[@]})]="ubuntu-font-family-0.71.2.zip" FNT_CHKMD5[(${#FNT_CHKMD5[@]})]="5be61a17e940a0aa9a98bf468b1e4e90" FNT_CHKSHA1[(${#FNT_CHKSHA1[@]})]="113ddacc71e219c39e7114af423425cdd8855ce7" FNT_CHKSHA256[(${#FNT_CHKSHA256[@]})]="2772a284aa48a429dc97f22a17ff96a00ed36cbff8c7913d84df15f3b9ca65d6" #FNT_DLFILES[(${#FNT_DLFILES[@]})]="secondfile" #FNT_CHKMD5[(${#FNT_CHKMD5[@]})]="md5 of secondfile" #FNT_CHKSHA1[(${#FNT_CHKSHA1[@]})]="sha1 of secondfile" #FNT_CHKSHA256[(${#FNT_CHKSHA256[@]})]="sha256 of secondfile" #target path FNT_INSTTARGETDIR="/usr/share/fonts/ubuntu" ################################################################################ # Process ################################################################################ #welcome user clear echo "###############################################################################" echo "# Ubuntu fonts installer" echo "# Found OS: $(cat /etc/fedora-release)" echo "#" echo "# Have a look at <http://font.ubuntu.com/> and/or" echo "# <http://blog.andreas-haerter.com/2011/07/08/install-ubuntufonts-fedora.sh>" echo "# for more information." echo "#" echo "# Please read the UBUNTU FONT LICENCE (<http://bit.ly/ajeQvv>) for all the" echo "# rules that govern the use of the fonts." echo "#" echo "# Note: internet connection is mandatory!" echo "###############################################################################" #check: are we root? if [ $(id -u) -ne 0 ] then echo "" echo "Superuser privileges needed. E.g. call this script using 'su -c'." 1>&2 exit 1 fi echo -n "Start? [y|n]: " read INPUT if [ ! "${INPUT}" == "y" ] && [ ! "${INPUT}" == "Y" ] && [ ! "${INPUT}" == "j" ] && [ ! "${INPUT}" == "J" ] then echo "Operation canceled by user" exit 0 fi #check if required tools are installed echo "" echo "Checking if all helper programs are available (this may take some time)..." hash wget > /dev/null 2>&1 if [ $? -ne 0 ] then echo "wget is missing, trying to install it..." yum -y install wget if [ $? -ne 0 ] then echo "Could not install missing wget" 1>&2 exit 1 fi fi hash ttmkfdir > /dev/null 2>&1 if [ $? -ne 0 ] then echo "ttmkfdir is missing, trying to install it..." yum -y install ttmkfdir if [ $? -ne 0 ] then echo "Could not install missing ttmkfdir" 1>&2 exit 1 fi fi echo "All needed programs found. Let's go!" echo "" #Download FNT_TMPDIR=$(mktemp -d "/tmp/fnt.XXXXXXXXXXXXX") #prevent symlink race condition... RND=${#FNT_DLMIRRORS[@]} #we need this temp var, [@] would not work (-> subshell problem: http://www.tldp.org/LDP/abs/html/subshells.html#PARVIS) RND=$((RANDOM % ${RND})) FNT_DLMIRROR=${FNT_DLMIRRORS[${RND}]} echo "Setting download mirror to ${FNT_DLMIRROR}" echo "" DLTRY=0 for ((i=0; i < ${#FNT_DLFILES[@]}; i++)) do echo "Downloading '${FNT_DLFILES[${i}]}'..." mkdir -p "${FNT_TMPDIR}" > /dev/null 2>&1 wget -nv --timeout=30 "${FNT_DLMIRROR}${FNT_DLFILES[${i}]}" -O "${FNT_TMPDIR}/${FNT_DLFILES[${i}]}" if [ $? -ne 0 ] then echo "Download failed, trying another mirror..." RND=${#FNT_DLMIRRORS[@]} #we need this temp var, [@] would not work (-> subshell problem: http://www.tldp.org/LDP/abs/html/subshells.html#PARVIS) RND=$((RANDOM % ${RND})) FNT_DLMIRROR=${FNT_DLMIRRORS[${RND}]} echo "Setting download mirror to ${FNT_DLMIRROR}" sleep 3 wget -nv --timeout=90 "${FNT_DLMIRROR}${FNT_DLFILES[${i}]}" -O "${FNT_TMPDIR}/${FNT_DLFILES[${i}]}" if [ $? -ne 0 ] then echo "Download of ${FNT_DLFILES[${i}]} failed again, please check your connection and try again." 1>&2 #clean up rm --preserve-root -rf "${FNT_TMPDIR}/" > /dev/null 2>&1 exit 1 fi fi echo "Download was successful, checking file..." FNT_TMPMD5=$(md5sum "${FNT_TMPDIR}/${FNT_DLFILES[${i}]}") FNT_TMPMD5=$(basename ${FNT_TMPMD5}) FNT_TMPSHA1=$(sha1sum "${FNT_TMPDIR}/${FNT_DLFILES[${i}]}") FNT_TMPSHA1=$(basename ${FNT_TMPSHA1}) FNT_TMPSHA256=$(sha256sum "${FNT_TMPDIR}/${FNT_DLFILES[${i}]}") FNT_TMPSHA256=$(basename ${FNT_TMPSHA256}) if [ ! "${FNT_TMPMD5}" == "${FNT_CHKMD5[${i}]}" ] || [ ! "${FNT_TMPSHA1}" == "${FNT_CHKSHA1[${i}]}" ] || [ ! "${FNT_TMPSHA256}" == "${FNT_CHKSHA256[${i}]}" ] then echo "${FNT_DLFILES[${i}]} is corrupted, trying again (using random mirror)..." RND=${#FNT_DLMIRRORS[@]} #we need this temp var, [@] would not work (-> subshell problem: http://www.tldp.org/LDP/abs/html/subshells.html#PARVIS) RND=$((RANDOM % ${RND})) FNT_DLMIRROR=${FNT_DLMIRRORS[${RND}]} echo "Setting download mirror to ${FNT_DLMIRROR}." sleep 3 let DLTRY=${DLTRY}+1 if [ ${DLTRY} -gt 1 ] then echo "${FNT_DLFILES[${i}]} is corrupted again, please check your connection and try again." 1>&2 echo "Expected MD5: ${FNT_CHKMD5[${i}]}" 1>&2 echo "Found MD5: ${FNT_TMPMD5}" 1>&2 echo "Expected SHA1: ${FNT_CHKSHA1[${i}]}" 1>&2 echo "Found SHA1: ${FNT_TMPSHA1}" 1>&2 echo "Expected SHA256: ${FNT_CHKSHA256[${i}]}" 1>&2 echo "Found SHA256: ${FNT_TMPSHA256}" 1>&2 #clean up rm --preserve-root -rf "${FNT_TMPDIR}/" > /dev/null 2>&1 exit 1 fi let i=${i}-1 else echo "${FNT_DLFILES[${i}]} is OK, going on." DLTRY=0 fi echo "" done #extract mkdir -p "${FNT_TMPDIR}/fonts" > /dev/null 2>&1 mkdir -p "${FNT_TMPDIR}/archive-contents" > /dev/null 2>&1 cd "${FNT_TMPDIR}" for ((i=0; i < ${#FNT_DLFILES[@]}; i++)) do EXTENSION=${FNT_DLFILES[${i}]} EXTENSION="${EXTENSION##*.}" EXTENSION=$(echo -n ${EXTENSION} | tr A-Z a-z) #lowercase with TR case ${EXTENSION} in "zip") unzip -j "${FNT_TMPDIR}/${FNT_DLFILES[${i}]}" -d "${FNT_TMPDIR}/archive-contents" if [ $? -ne 0 ] then echo "Could not extract contents of '${FNT_TMPDIR}/${FNT_DLFILES[${i}]}'." 1>&2 exit 1 fi ;; #archive extension is unknown *) echo "Sorry, '${EXTENSION}' archives are not supported right now." exit 1 ;; esac done cp "${FNT_TMPDIR}/archive-contents/"*.ttf "${FNT_TMPDIR}/fonts" if [ $? -ne 0 ] then echo "It seems that there are no TTF files in '${MSTTF_TMPDIR}/archive-contents/'?!" 1>&2 exit 1 fi #ttmkfdir is a tool to create valid and complete fonts.dir files from TrueType fonts echo "Creating fonts.dir and font.scale file..." cd "${FNT_TMPDIR}/fonts" ttmkfdir > fonts.dir if [ $? -ne 0 ] then echo "Could not create fonts.dir and font.scale." 1>&2 exit 1 fi echo "Installing fonts..." mkdir -p "${FNT_INSTTARGETDIR}" > /dev/null 2>&1 if [ $? -ne 0 ] then echo "Could not create '${FNT_INSTTARGETDIR}' dir." 1>&2 exit 1 fi cp -f "${FNT_TMPDIR}/fonts/"*.ttf "${FNT_TMPDIR}/fonts/fonts.dir" "${FNT_TMPDIR}/fonts/fonts.scale" "${FNT_INSTTARGETDIR}" if [ $? -ne 0 ] then echo "Could not copy needed files into '${FNT_INSTTARGETDIR}'." 1>&2 exit 1 else echo "SUCCESS. Fonts installed." echo "" fi #clean up rm --preserve-root -rf "${FNT_TMPDIR}/" > /dev/null 2>&1 echo "Re-building the system's font cache now..." fc-cache -fv if [ $? -ne 0 ] then echo "Updating the system's font cache failed. However, the fonts were installed" 1>&2 echo "successfully. You may try to update the cache by yourtself with 'fc-cache -fv'" 1>&2 exit 1 fi #finished echo "" echo "" echo "###############################################################################" echo "# Font installation done." echo "###############################################################################" echo "You should reboot to make everything work as expected." echo -n "Reboot now ? [y|n]: " read INPUT if [ "${INPUT}" == "y" ] || [ "${INPUT}" == "Y" ] || [ "${INPUT}" == "j" ] || [ "${INPUT}" == "J" ] then echo "" echo "!!!System will reboot in 5 seconds. Press CTRL+C to prevent this!!!" echo "" sleep 5 reboot exit 0 fi exit 0
Copying/License
The source code of the script is dual-licensed under GPLv2 and New/3-clause BSD. Please read the Ubuntu Font Licence for all the rules that govern the use of the fonts.