jpenguin

ttf-vista-fonts-installer.sh

Sep 27th, 2020 (edited)
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.98 KB | None | 0 0
  1. #!/bin/bash
  2. # Author: Maxwel Leite
  3. # Website: http://needforbits.wordpress.com/
  4. # Description: Script to install Microsoft Vista TrueType Fonts (TTF) aka Microsoft’s ClearType fonts on Ubuntu distros
  5. # Microsoft added a group of new "ClearType Fonts" to Windows with Windows Vista and Office 2007.
  6. # These fonts are named Constantia, Corbel, Calibri, Cambria (and Cambria Math), Candara, and Consolas.
  7. # Calibri became the default font on Microsoft Word 2007, and it’s still the default font on Word 2016 today.
  8. # Dependencies: wget, fontforge and cabextract
  9. # Note: Microsoft no longer provides the PowerPoint Viewer 2007 (v12.0.4518.1014) or any version anymore for download
  10. # Tested: Ubuntu Saucy/Trusty/Xenial/Bionic
  11.  
  12. output_dir="/usr/share/fonts/truetype/vista"
  13. tmp_dir="/tmp/fonts-vista"
  14.  
  15. if [[ $EUID -ne 0 ]]; then
  16. echo -e "You must be a root user!\nTry: sudo ./ttf-vista-fonts-installer.sh" 2>&1
  17. exit 1
  18. fi
  19.  
  20. if ! which wget >/dev/null; then
  21. echo "Error: wget is required to download the file"
  22. echo "Run the following command to install it:"
  23. echo "sudo apt-get install wget"
  24. exit 1
  25. fi
  26.  
  27. if ! which cabextract >/dev/null; then
  28. echo "Error: cabextract is required to unpack the files"
  29. echo "Run the following command to install it:"
  30. echo "sudo apt-get install cabextract"
  31. exit 1
  32. fi
  33.  
  34. if ! which fontforge >/dev/null; then
  35. echo "Error: fontforge is required to convert TTC files into TTF"
  36. echo "Run the following command to install it:"
  37. echo "sudo apt-get install fontforge"
  38. exit 1
  39. fi
  40.  
  41. file="$tmp_dir/PowerPointViewer.exe"
  42. mkdir -p "$tmp_dir"
  43. cd "$tmp_dir"
  44. err=0
  45.  
  46. echo -e "\n:: Downloading PowerPoint Viewer...\n"
  47. wget -O "$file" https://web.archive.org/web/20171225132744/http://download.microsoft.com/download/E/6/7/E675FFFC-2A6D-4AB0-B3EB-27C9F8C8F696/PowerPointViewer.exe
  48. #wget -O "$file" https://filedn.com/lHGef0SOQKnBTotcJeEfshJ/PowerPointViewer.exe
  49. if [ $? -ne 0 ]; then
  50. rm -f "$file"
  51. echo -e "\nError: Download failed!?\n"
  52. err=1
  53. else
  54. echo -e "Done!\n"
  55. fi
  56.  
  57. if [ $err -ne 1 ]; then
  58. echo -n ":: Extracting... "
  59. cabextract -t "$file" &> /dev/null
  60. if [ $? -ne 0 ]; then
  61. echo "Error: Can't extract. Corrupted download!?"
  62. err=1
  63. else
  64. cabextract -F ppviewer.cab "$file" &> /dev/null
  65. cabextract -L -F '*.tt?' ppviewer.cab &> /dev/null
  66. if [ $? -ne 0 ]; then
  67. echo "Error: Can't extract 'ppviewer.cab' from 'PowerPointViewer.exe'. Corrupted download!?"
  68. err=1
  69. else
  70. echo "Done!"
  71. fi
  72. fi
  73. fi
  74.  
  75. if [ $err -ne 1 ]; then
  76. # If you need the Cambria and Cambria Math (regular) font, you'll need to convert it to TTF because the font is available
  77. # as a TrueType Collection (TTC) and unless you convert it, you won't be able to use it in LibreOffice for instance.
  78. echo -n ":: Converting 'Cambria Regular' and 'Cambria Math Regular' (TTC - TrueType Collection) to TrueType (TTF)... "
  79. fontforge -lang=ff -c 'Open("cambria.ttc(Cambria)"); Generate("cambria.ttf"); Close(); Open("cambria.ttc(Cambria Math)"); Generate("cambriamath.ttf"); Close();' &> /dev/null
  80. if [ $? -ne 0 ]; then
  81. echo "Error: Can't convert file 'combria.ttc'."
  82. err=1
  83. else
  84. echo "Done!"
  85. fi
  86. fi
  87.  
  88. if [ $err -ne 1 ]; then
  89. echo -n ":: Installing... "
  90. mkdir -p "$output_dir"
  91. cp -f "$tmp_dir"/*.ttf "$output_dir" &> /dev/null
  92. if [ $? -ne 0 ]; then
  93. echo "Error: Can't copy files to output directory."
  94. err=1
  95. else
  96. echo "Done!"
  97. fi
  98. fi
  99.  
  100. if [ $err -ne 1 ]; then
  101. echo -n ":: Clean the font cache... "
  102. fc-cache -f "$output_dir" &> /dev/null
  103. echo "Done!"
  104. fi
  105.  
  106. echo -n ":: Cleanup... "
  107. cd - &> /dev/null
  108. rm -rf "$tmp_dir" &> /dev/null
  109. echo "Done!"
  110.  
  111. if [ $err -ne 1 ]; then
  112. echo -e "\nCongratulations! Installation successful!!\n"
  113. else
  114. echo -e "\nSome error occurred! Please try again!!\n"
  115. fi
Add Comment
Please, Sign In to add comment