Script to auto install fonts

jonatec

New Member
Joined
Jul 23, 2019
Messages
12
Reaction score
8
Credits
20
Anyone advise please?

Is there a way to run some sort of script which will install a set of fonts?

I'm running the Linux Mint (cinnamon) distro.

Thanks.
 


G'day @jonatec and welcome to linux.org :)

I am moving your Thread to Command Line, because it will get scripting attention there.

Let your helpers know which version Linux Mint, too eg 18, 19.

Good luck

Chris Turner
wizardfromoz
 
If I do a fresh install or re-install or upgrade WPS then my fonts disappear.

I have used a site for installing Microsoft font, but there are others that my presentations need such as Baskerville Old Face, Bookman Old Style, Century Schoolbook, etc.

I have all these fonts downloaded and stashed in a folder, but I'm wondering if there is a way to run a script which will install them all in the event of a re-install etc?
 
Have you reported this happening to WPS ? (I am assuming you are talking about the chinese office suite)

They need to know this...and I am told their support is quite good...

Or....have you tried Libre Office ?
 
I have tried LibreOffice, for me WPS has the edge. And no, I haven't reported the loss of fonts to WPS.
 
Anyway I'm a Linux newbie. Can anyone recommend an idiots guide to creating and running scripts on Linux?
 
Hi @jonatec, and welcome. There is no script, I don't think. A script would not know what fonts you have, right? I think you need a terminal command, not a script. And I believe @Condobloke's link above has the answer. If your fonts are TrueType, copy them to the /usr/share/fonts/truetype folder. You may need to use sudo to copy there, I'm not sure. After copying to the proper location, then following the link's instructions, you would enter this command:

Code:
sudo fc-cache -f -v

This should update the font cache system-wide, and should be available in WPS, LibreOffice, whatever.

Cheers
 
Anyway I'm a Linux newbie. Can anyone recommend an idiots guide to creating and running scripts on Linux?
Again, not scripts (which typically is not a good place for a newbie to start).... but terminal commands will be very useful as you learn more. Below is a link with many helpful tips on tweaking your Linux Mint Cinnamon, but you don't need to do each one... just review and see what you think. There is a special section on fonts, where it describes how to install the Microsoft collection, and another collection too.

https://easylinuxtipsproject.blogspot.com/p/first-mint-cinnamon.html
 

I will leave the creating and running scripts to someone more knowledgeable than myself.......but....the link above shows where the fonts are stored on the linux system.
Double click oin Home...then single click on File System....select usr....then share....then double click fonts.
Drop your fonts in there....they should be .ttf files......and the system should scan that folder and pick up those fonts for you, and make them available

EDIT....I have just noticed atanere's comments above......follow that course...it is much clearer than mine...tell us how you get on

Being a newbie this could be over your head.

WPS's email for support is : [email protected]

If you are going to be having a play around, it would be wise to use Timeshift. If you are using Linux mint 18.2...18.3....or 19.14....it should be already in the menu....or it will be in the Software Manager.
Timeshift works in a similar way to system restore....with one major difference being it actually works. best to have an external hard drive to send the system snapshots to.
@wizardfromoz has a tutorial on it....I will find it for you and repost later
 
I fancy getting this scripting knowledge under my belt... I've downloaded all the fonts I reckon I need into a local folder, then tried the following, but didn't work:

sudo apt-get install design.graffiti.comicsansms.ttf cour.ttf
 
Well, I will keep knocking you on the head to learn the terminology correctly! :eek::p At the moment, you are only using Linux terminal commands. A script is a different thing, kind of like a program. A script can run just a single terminal command, or it can run a very complicated set of many commands. Save your thoughts for scripts for later... because you need to learn commands first, and from there you can build scripts. :D

apt-get (install) is a terminal command to install a program... not fonts. sudo is always needed to install software in Linux, or you could become the root user first and then install.

Linux expects your .ttf fonts to be in a common location (/usr/share/fonts/truetype/) but you do not have to follow the convention. The terminal command, fc-cache, scans your system's common locations. If you don't want to copy your fonts to the common location, you can force fc-cache to scan the folder you use, but you have to tell it where that is. Example:

Code:
fc-cache /home/jonatec/myfonts

Of course, the location in the command needs to be exact. Remember that Linux is case sensitive too, so a folder named MyFonts is not the same as myfonts.

Cheers
 
Well, I will keep knocking you on the head to learn the terminology correctly! :eek::p At the moment, you are only using Linux terminal commands. A script is a different thing, kind of like a program. A script can run just a single terminal command, or it can run a very complicated set of many commands. Save your thoughts for scripts for later... because you need to learn commands first, and from there you can build scripts. :D

apt-get (install) is a terminal command to install a program... not fonts. sudo is always needed to install software in Linux, or you could become the root user first and then install.

Linux expects your fonts to be in a common location (/usr/share/fonts/truetype/) but you do not have to follow the convention. The terminal command, fc-cache, scans your system's common locations. If you don't want to copy your fonts to the common location, you can force fc-cache to scan the folder you use, but you have to tell it where that is. Example:

Code:
fc-cache /home/jonatec/myfonts

Of course, the location in the command needs to be exact. Remember that Linux is case sensitive too, so a folder named MyFonts is not the same as myfonts.

Cheers
Great, thanks!
 
I fancy getting this scripting knowledge under my belt... I've downloaded all the fonts I reckon I need into a local folder, then tried the following, but didn't work:

sudo apt-get install design.graffiti.comicsansms.ttf cour.ttf

If you want to manually install a set of fonts, you would need to copy them to the appropriate system directory and then update the systems font-cache. The instructions to do this are described in the link posted by @Condobloke .

Assuming all of the fonts are truetype .ttf fonts, then in a fresh terminal you'd use the following commands:
Bash:
cd /path/to/local-fonts/
sudo cp *.ttf /usr/share/fonts/truetype/ && sudo fc-cache -f -v
sudo -k

NOTES:
Replace /path/to/local-fonts/ in the above with the actual directory you downloaded the fonts to.

In the above the && is a logical AND operation. So the fc-cache command will only be ran if the initial cp command succeeds.

If the cp command fails - for example if there are no .ttf files in the directory - then the fc-cache command will NOT be ran.

And the sudo -k command at the end revokes administrative permissions - so the next time a sudo command is entered it will require you to enter your password.

Regarding turning those commands into a script:
The obvious payoff to creating a script is that any time you wanted to install some ttf fonts - you could just run your script and tell it which directory the fonts you want to install are in.
Which would save you having to remember the commands/paths you will need to use to install them manually.

But for the sake of one or two simple commands that would copy some ttf files and update the font-cache - you're potentially looking at quite a lot of housekeeping code to avoid any potential problems. So it might take a little time to fully develop your script and make it robust enough to handle any adverse situations.
e.g. accidental, or deliberate misuse by users.

So it's swings and roundabouts really!
If you're likely to need to install new fonts regularly - then by all means - set up a script to do it.

If you're not likely to be doing it often - just make a note of the commands required to manually install fonts and type them (or copy/paste them from a file) as and when you need to use them.
 
If you want to manually install a set of fonts, you would need to copy them to the appropriate system directory and then update the systems font-cache. The instructions to do this are described in the link posted by @Condobloke .

Assuming all of the fonts are truetype .ttf fonts, then in a fresh terminal you'd use the following commands:
Bash:
cd /path/to/local-fonts/
sudo cp *.ttf /usr/share/fonts/truetype/ && sudo fc-cache -f -v
sudo -k

NOTES:
Replace /path/to/local-fonts/ in the above with the actual directory you downloaded the fonts to.

In the above the && is a logical AND operation. So the fc-cache command will only be ran if the initial cp command succeeds.

If the cp command fails - for example if there are no .ttf files in the directory - then the fc-cache command will NOT be ran.

And the sudo -k command at the end revokes administrative permissions - so the next time a sudo command is entered it will require you to enter your password.

Regarding turning those commands into a script:
The obvious payoff to creating a script is that any time you wanted to install some ttf fonts - you could just run your script and tell it which directory the fonts you want to install are in.
Which would save you having to remember the commands/paths you will need to use to install them manually.

But for the sake of one or two simple commands that would copy some ttf files and update the font-cache - you're potentially looking at quite a lot of housekeeping code to avoid any potential problems. So it might take a little time to fully develop your script and make it robust enough to handle any adverse situations.
e.g. accidental, or deliberate misuse by users.

So it's swings and roundabouts really!
If you're likely to need to install new fonts regularly - then by all means - set up a script to do it.

If you're not likely to be doing it often - just make a note of the commands required to manually install fonts and type them (or copy/paste them from a file) as and when you need to use them.
These commands worked great! Even a dummy could follow.
Thanks for your comprehensive answer and explaining the use of the logical operator and about creating a script.
Brilliant!
1) Is there a Linux command to list the contents of the font cache? Couldn't see how to do this using fc-cache.
2) How to install an OTF font?
 
Last edited:
1) Is there a Linux command to list the contents of the font cache?
A good time to learn about the man pages (built-in help manuals). At a terminal, enter man fc-cache and it will give you instructions about usage, options, and usually examples. With fc-cache, it also names some similar commands, such as fc-list. That will generate a lot of output (because there a lot of fonts!) and so you might want to capture the full list into a file, like this:
Code:
fc-list > /home/jonatec/Desktop/myfonts.txt
Change the user name above if not the same as your user name here on the forum. This should give you a text file on your desktop that lists all the fonts in the common font location (not your private collection).


2) How to install an OTF font?
Same method as with truetype, but into a different folder. Copy your OTF files to: /user/share/fonts/opentype/ ... then run fc-cache -f -v as before.


You might also open up your Start Menu and begin typing "fonts".... there should be one or two apps that will provide some info about installed fonts.
 

Members online


Top