1
0
Fork 0

added font install script

This commit is contained in:
Kim, Jimin 2022-02-02 21:49:06 +09:00
parent a2f6a4bbe7
commit 969b0b9451
5 changed files with 86 additions and 66 deletions

View file

@ -9,6 +9,7 @@
"developomp", "developomp",
"flatpak", "flatpak",
"FOSS", "FOSS",
"noto",
"pamac", "pamac",
"ungoogled" "ungoogled"
], ],

View file

@ -10,22 +10,28 @@ def initialize():
log.log("Initializing flatpak") log.log("Initializing flatpak")
if os.system("sudo pacman -S --noconfirm --needed flatpak &> /dev/null"): if os.system("sudo pacman -S --noconfirm --needed flatpak &> /dev/null"):
log.error("Failed to install flatpak form archlinux package repository") log.error("Failed to install flatpak via pacman")
exit(1) exit(1)
log.log("Initializing pip") log.log("Initializing pip")
if os.system("sudo pacman -S --noconfirm --needed python-pip &> /dev/null"): if os.system("sudo pacman -S --noconfirm --needed python-pip &> /dev/null"):
log.error("Failed to install pip from archlinux package repository") log.error("Failed to install pip via pacman")
exit(1)
# https://pypi.org/project/requests
log.log("Initializing requests")
if os.system("pip install requests &> /dev/null"):
log.error("Failed to install requests via pip")
exit(1) exit(1)
# https://pypi.org/project/PyYAML # https://pypi.org/project/PyYAML
log.log("Initializing PyYAML") log.log("Initializing PyYAML")
if os.system("pip install PyYAML &> /dev/null"): if os.system("pip install PyYAML &> /dev/null"):
log.error("Failed to install PyYAML from pip") log.error("Failed to install PyYAML via pip")
exit(1) exit(1)
# https://github.com/bczsalba/pytermgui # https://github.com/bczsalba/pytermgui
log.log("Initializing pytermgui") log.log("Initializing pytermgui")
if os.system("pip install pytermgui &> /dev/null"): if os.system("pip install pytermgui &> /dev/null"):
log.error("Failed to install pytermgui from pip") log.error("Failed to install pytermgui via pip")
exit(1) exit(1)

View file

@ -49,67 +49,6 @@ setup_filezilla() {
package_install filezilla package_install filezilla
} }
setup_fonts() {
log "installing fonts"
# wget: For downloading zip files
# noto-fonts-emoji: Emoji fonts
# nerd-fonts-noto-sans-mono: Terminal font
# ttf-baekmuk: Korean font
package_install \
wget \
noto-fonts-emoji \
nerd-fonts-noto-sans-mono \
ttf-baekmuk
# path to temporarily save font related files
fonts_directory="$SCRIPT_DIR/tmp/fonts"
# fonts to download
font_names=(
"Audiowide"
"Varela Round"
"Ubuntu Mono"
"Nanum Gothic Coding"
)
# create fonts directory if it does not exist
if [ ! -d "$fonts_directory" ]; then
mkdir -p "$fonts_directory"
fi
# download and unzip font files if they're not downloaded already
for font_name in "${font_names[@]}"; do
zip_path="$fonts_directory/$font_name.zip"
# download and unzip if either zip file or unzipped directory exists
if [ ! -f "$zip_path" ] && [ ! -d "$fonts_directory/$font_name" ]; then
wget -O "$zip_path" "https://fonts.google.com/download?family=$font_name" # download zip file
unzip "$zip_path" -d "$fonts_directory/$font_name" # unzip file
rm "$zip_path" # remove zip file
fi
done
font_install_dir="$HOME/.local/share/fonts"
# create local fonts directory if it does not exist already
if [ ! -d "$font_install_dir" ]; then
mkdir -p "$font_install_dir"
fi
# "install" all fonts
find "$fonts_directory" -type f -name "*.ttf" | while read ttf_file_path; do
mv -f "$ttf_file_path" "$font_install_dir/${ttf_file_path##*/}"
done
# regenerate font cache
fc-cache -vf
# cleanup
rm -rf $fonts_directory
}
setup_fstab() { setup_fstab() {
if cat /etc/fstab | grep "/media/pomp/data" &>/dev/null; then if cat /etc/fstab | grep "/media/pomp/data" &>/dev/null; then
return return

54
src/setup/system/fonts.py Normal file
View file

@ -0,0 +1,54 @@
from ...util import pamac_install, smart_mkdir, download, unzip
from ...constants import tmp_dir
from shutil import rmtree, move
from os import remove, system
from os.path import exists
import requests
import glob
name = "fonts"
# path to temporarily save font related files
TMP_FONTS_DIRECTORY = f"{tmp_dir}/tmp/fonts"
# fonts to download
FONT_NAMES = ("Audiowide", "Varela Round", "Ubuntu Mono", "Nanum Gothic Coding")
# where to unzip the fonts
FONT_INSTALL_DIR = "~/.local/share/fonts"
def setup():
"""
System fonts
noto-fonts-emoji: Emoji fonts
nerd-fonts-noto-sans-mono: Terminal font
ttf-baekmuk: Korean font
"""
pamac_install(["noto-fonts-emoji", "nerd-fonts-noto-sans-mono", "ttf-baekmuk"])
smart_mkdir(TMP_FONTS_DIRECTORY)
# download and unzip font files if they're not downloaded already
for font_name in FONT_NAMES:
zip_path = f"{TMP_FONTS_DIRECTORY}/{font_name}.zip"
# download and unzip if either zip file or unzipped directory exists
if exists(zip_path) and exists("{TMP_FONTS_DIRECTORY}/{font_name}"):
download(zip_path, f"https://fonts.google.com/download?family={font_name}")
unzip(zip_path, f"{TMP_FONTS_DIRECTORY}/{font_name}")
remove(zip_path)
smart_mkdir(FONT_INSTALL_DIR)
# "install" fonts
for ttf_file_path in glob.glob(f"{TMP_FONTS_DIRECTORY}/**/*.ttf"):
move(ttf_file_path, f"{FONT_INSTALL_DIR}/{ttf_file_path}")
# regenerate font cache
system("fc-cache -vf")
# cleanup
rmtree(TMP_FONTS_DIRECTORY)

View file

@ -1,6 +1,9 @@
from .constants import tmp_dir
from os import system, makedirs from os import system, makedirs
from shutil import copy from shutil import copy
from .constants import tmp_dir import zipfile
# todo: remove all uses of AUR (use pacman instead of pamac) # todo: remove all uses of AUR (use pacman instead of pamac)
def pamac_install(packages: str | list[str]) -> None: def pamac_install(packages: str | list[str]) -> None:
@ -33,6 +36,7 @@ def smart_mkdir(path: str):
""" """
Recursively create directories if it doesn't exist already. Recursively create directories if it doesn't exist already.
""" """
try: try:
makedirs(path) makedirs(path)
except OSError: except OSError:
@ -58,6 +62,22 @@ def load_dconf(file_name: str):
system(f'dconf load / < "{tmp_dir}/dconf/{file_name}"') system(f'dconf load / < "{tmp_dir}/dconf/{file_name}"')
def download(file_name: str, url: str):
"""Downloads a file from a url."""
r = requests.get(url)
with open(file_name, "wb") as f:
f.write(r.content)
def unzip(zip_path: str, dst_dir: str):
"""Unzips a .zip file to a directory."""
smart_mkdir(dst_dir)
with zipfile.ZipFile(zip_path, "r") as zip_ref:
zip_ref.extractall(dst_dir)
""" """
def setup_essentials(): def setup_essentials():
setup_fstab setup_fstab