Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 141 additions & 0 deletions tabs/system-setup/nerdfonts-installer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
#!/bin/sh -e

# Import common utilities
. ../common-script.sh

# List of available fonts
fonts="
0xProto_Nerd_Font
3270_Nerd_Font
Agave_Nerd_Font
AnonymicePro_Nerd_Font
Arimo_Nerd_Font
AurulentSansMono_Nerd_Font
BigBlueTerminal_Nerd_Font
BitstromWera_Nerd_Font
BlexMono_Nerd_Font
CaskaydiaCove_Nerd_Font
CaskaydiaMono_Nerd_Font
CodeNewRoman_Nerd_Font
ComicShannsMono_Nerd_Font
CommitMono_Nerd_Font
Cousine_Nerd_Font
D2Coding_Nerd_Font
DaddyTimeMono_Nerd_Font
DejaVuSansMono_Nerd_Font
DroidSansMono_Nerd_Font
EnvyCodeR_Nerd_Font
FantasqueSansMono_Nerd_Font
FiraCode_Nerd_Font
FiraMono_Nerd_Font
GeistMono_Nerd_Font
GoMono_Nerd_Font
Gohu_Nerd_Font
Hack_Nerd_Font
Hasklug_Nerd_Font
HeavyDataMono_Nerd_Font
Hurmit_Nerd_Font
iM-Writing_Nerd_Font
Inconsolata_Nerd_Font
InconsolataGo_Nerd_Font
Inconsolata_LGC_Nerd_Font
IntoneMono_Nerd_Font
Iosevka_Nerd_Font
IosevkaTerm_Nerd_Font
IosevkaTermSlab_Nerd_Font
JetBrainsMono_Nerd_Font
Lekton_Nerd_Font
Literation_Nerd_Font
Lilex_Nerd_Font
MartianMono_Nerd_Font
Meslo_Nerd_Font
Monaspice_Nerd_Font
Monofur_Nerd_Font
Monoid_Nerd_Font
Mononoki_Nerd_Font
M+_Nerd_Font
Noto_Nerd_Font
OpenDyslexic_Nerd_Font
Overpass_Nerd_Font
ProFont_Nerd_Font
ProggyClean_Nerd_Font
RecMono_Nerd_Font
RobotoMono_Nerd_Font
SauceCodePro_Nerd_Font
ShureTechMono_Nerd_Font
SpaceMono_Nerd_Font
Terminess_Nerd_Font
Tinos_Nerd_Font
Ubuntu_Nerd_Font
UbuntuMono_Nerd_Font
VictorMono_Nerd_Font
ZedMono_Nerd_Font
"

# Function to prompt user for font selection
prompt_font_selection() {
echo "Select fonts to install (separate with spaces):"
echo "---------------------------------------------"

# Set number of columns
cols=3
i=0

# Calculate the format string dynamically
for font in $fonts; do
# Print font in columns
printf "%-35s" "$i - $font"
i=$((i + 1))

# Print newline after every $cols fonts
if [ $((i % cols)) -eq 0 ]; then
echo ""
fi
done

# Print remaining fonts if the total count isn't a multiple of $cols
if [ $((i % cols)) -ne 0 ]; then
echo ""
fi

echo "---------------------------------------------"
printf "Enter the numbers of the fonts to install (e.g., '0 1 2'): "
read font_selection

echo "Fonts selected: $font_selection"
}

# Function to download and install the selected fonts
download_and_install_fonts() {
i=0
for font in $fonts; do
for selection in $font_selection; do
if [ "$i" = "$selection" ]; then
font_name=$(echo "$font" | sed 's/_/ /g') # Replace underscores with spaces
echo "Downloading and installing $font_name..."

# Check if wget and tar are installed, using common-script.sh helper
checkCommandRequirements "curl"
checkCommandRequirements "tar"

# Download the font
curl -sSLo "$HOME/tmp/$font_name.tar.xz" "https://github.com/ryanoasis/nerd-fonts/releases/latest/download/$font_name.tar.xz"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curl: (3) URL rejected: Malformed input to a URL function

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tar and curl are preloaded so what's the issue here.
I could not reproduce your error: curl: (3) URL rejected: Malformed input to a URL function

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tar and curl are preloaded so what's the issue here. I could not reproduce your error: curl: (3) URL rejected: Malformed input to a URL function

Then you did not test it, "TMP" a folder inside of the root file system does not exist inside of the users home directory


# Extract and install the font
mkdir -p ~/.local/share/fonts
tar -xf "$HOME/tmp/$font_name.tar.xz" -C "$HOME/.local/share/fonts"
rm "$HOME/tmp/$font_name.tar.xz"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
curl -sSLo "$HOME/tmp/$font_name.tar.xz" "https://github.com/ryanoasis/nerd-fonts/releases/latest/download/$font_name.tar.xz"
# Extract and install the font
mkdir -p ~/.local/share/fonts
tar -xf "$HOME/tmp/$font_name.tar.xz" -C "$HOME/.local/share/fonts"
rm "$HOME/tmp/$font_name.tar.xz"
curl -sSLo "/tmp/$font_name.tar.xz" "https://github.com/ryanoasis/nerd-fonts/releases/latest/download/$font_name.tar.xz"
# Extract and install the font
mkdir -p ~/.local/share/fonts
tar -xf "/tmp/$font_name.tar.xz" -C "$HOME/.local/share/fonts"
rm "/tmp/$font_name.tar.xz"

Copy link

@ghost ghost Sep 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adamperkowski this needs escalation_tool you cannot curl a file inside of the root file system without root permissions nvm tested it and it works, learn something new everyday

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nnyyxxxx I'm pretty sure you're wrong this time. The default /tmp permissions are drwxrwxrwt. The t at the end means that only the owner of a file or the root user can modify.
image

fi
done
i=$((i + 1))
done

# Update the font cache
fc-cache -vf
echo "Fonts installed and cache updated."
}

# Main script execution
checkEnv
prompt_font_selection
download_and_install_fonts
4 changes: 4 additions & 0 deletions tabs/system-setup/tab_data.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,7 @@ script = "3-global-theme.sh"
[[data]]
name = "Remove Snaps"
script = "4-remove-snaps.sh"

[[data]]
name = "Nerd-fonts Installer"
script = "nerdfonts-installer.sh"