configure already sets TMPDIR to mixed path
[LibreOffice.git] / bin / replace_missing_fonts.sh
blobf06e6b7a6c729db6cb862de78ed263d868a4125d
1 #!/bin/bash
3 declare -A replacements
4 replacements["Agency FB"]="Noto Sans"
5 replacements["Segoe UI"]="Noto Sans"
6 replacements["Univers 45 Light"]="Noto Sans"
7 replacements["Trebuchet MS"]="Noto Sans"
8 replacements["Perpetua"]="Noto Sans"
9 replacements["Calibri Light"]="Noto Sans"
10 replacements["Rockwell"]="Noto Sans"
11 replacements["DFKai-SB"]="Noto Sans"
12 replacements["Gill Sans MT"]="Noto Sans"
13 replacements["BentonSans Medium"]="Noto Sans"
14 replacements["BentonSans"]="Noto Sans"
15 replacements["AdvPS88D1"]="Noto Sans"
16 replacements["NexusSansOT"]="Noto Sans"
17 replacements["Segoe Script"]="Noto Sans"
18 replacements["Impact"]="Noto Sans"
19 replacements["Century Gothic"]="Noto Sans"
20 replacements["Kings Caslon Text"]="Noto Sans"
21 replacements["Times"]="Liberation Serif"
22 replacements["Jokerman"]="Noto Sans"
23 replacements["FreeSans"]="Noto Sans"
24 replacements["DINPro-Medium"]="Noto Sans"
25 replacements["Open Sans Light"]="Noto Sans"
26 replacements["Lora - regular"]="Noto Sans"
27 replacements["Tahoma"]="Noto Sans"
28 replacements["Thorndale"]="Liberation Serif"
29 replacements["Albany"]="Liberation Sans"
30 replacements["Lucida Sans Unicode"]="Noto Sans"
31 replacements["Candara"]="Noto Sans"
32 replacements["Verdana"]="Noto Sans"
33 replacements["Gill Sans MT"]="Noto Sans"
35 extracted_folder=".temp_extracted"
37 for file in $(find "$1" -type f); do
38 file_name=$(basename "$file")
39 current_extension="${file_name##*.}"
41 if [[ $current_extension == "docx" || $current_extension == "xlsx" || $current_extension == "pptx" || $current_extension == "odt" ]]; then
42 base_name="${file_name%.*}"
44 # move the file to a new .zip file
45 cp "$file" "${base_name}.zip"
47 # extract the zip file to a temporary folder
48 unzip -qq ./"${base_name}.zip" -d "$extracted_folder" > /dev/null
50 for key in "${!replacements[@]}"
52 file_changed=false
53 value=${replacements[$key]}
54 for subfile in $(find "$extracted_folder" -type f); do
55 # Replace only if it's between quotes
56 if grep -q "\"$key\"" "$subfile"; then
57 sed -i "s/\"$key\"/\"$value\"/g" "$subfile"
58 file_changed=true
59 # or between '"'
60 elif grep -q ""$key"" "$subfile"; then
61 sed -i "s/"$key"/\"$value\"/g" "$subfile"
62 file_changed=true
64 done
66 if [ "$file_changed" = true ]; then
67 # Create a new zip file with the modified files
68 cd "$extracted_folder"; zip -r ../"${base_name}.zip" . > /dev/null; cd ..
70 mv "${base_name}.zip" "$file"
72 echo "Replacing '$key' with '$value' in $file"
74 done
76 # Clean up the temporary extracted folder
77 rm -rf "$extracted_folder"
79 done