aboutsummaryrefslogtreecommitdiffstats
path: root/mageia_doc_binaries.sh
blob: 742c25e24e3e155c2b7410893e1d1601e43d2847 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/bin/bash
#
# Fetch EPUB and PDF files from http://docteam.mageia.nl and copy properly named file to git
#
# Filip Komar, June 2017, 2019
# @license GPL v2
# @author Filip
# @copyright 2017, 2019
#
# "Usage: mageia_doc_binaries.sh "/mirror/dir_name/" "/local_git/dir_name/"
# but first adjust variables bellow

release=7
epub_dir='https://docteam.mageia.org.uk/EPUB/'
pdf_dir='https://docteam.mageia.org.uk/Mga7/PDF/'

function rename_binary {
    doc_regex="(.+)($1)-(cover-)?(.+)-(PDF|EPUB).(.+)"
    doc_dir_prefix="$download_dir/doc/mga$release"
    doc_dir="$doc_dir_prefix/$2/*"
    languages=""
    for dir_filename in $(\ls -d $doc_dir)
    do
        [[ "$dir_filename" =~ $doc_regex ]]
      # echo "${a,,}" # bash 4 lower case
        manual=${BASH_REMATCH[2]}
        language=${BASH_REMATCH[4],,}
        extension=${BASH_REMATCH[6],,}
        new_name="Mageia$release-$manual-$language.$extension"
        check=${#BASH_REMATCH[0]}
        if [ $check -ge 1 ]; then
            # option fo skip certain files if needed (currently pdf)
          # skip_languages=( "cs" "el" "jp" "ru" "sl" "tg" "uk" "zh-cn" )
          # skip_this_language=$( printf "%s\n" "${skip_languages[@]}" | grep -n -m 1 "^${language}$" | cut -d ":" -f1 )

            if [[ $extension == 'pdf' && -n $skip_this_language ]]; then
                echo -e "\E[31m"
                echo "Language $language skiped for $extension in $manual."
                echo -e "\E[m"
            else
              # echo $new_name
                languages="$languages|$language"
                mkdir --parents "$local_git/doc_binaries_for_website/mga$release/$extension/$manual"
                # set copying options (-i: interactive, -v: verbose, -u: update, -r: recursive)
                cp -u "$dir_filename" "$local_git/doc_binaries_for_website/mga$release/$extension/$manual/$new_name"
                git add "doc_binaries_for_website/mga$release/$extension/$manual/$new_name"
                git_clean=`git diff --name-only`
                if [ ! -z $git_clean ]; then
                    commit_needed="yes"
                fi
            fi
        else
            echo -e "\E[31m"
            echo "Manual file $1 in $2 missed by regex: $dir_filename"
            echo -e "\E[m"
        fi
    done
    echo -n "manual $1 ($2) is in languages: " >> "$list_file"
    echo $languages | cut -c 2- >> "$list_file"
    git commit -m "adding and updating $1 $extension manual for release $release"
}

if [ -z "$2" ]; then
    echo "Usage: mageia_doc_binaries.sh \"/mirror/dir_name/\" \"/local_git/dir_name/\""
    exit 2
else
    download_dir="$1"
    local_git="$2"
fi

# save pwd to saved_dir
saved_dir=$(pwd)
cd "$local_git"

git_clean=`git diff --name-only`
if [ ! -z $git_clean ]; then
    echo "Please commit changes first"
    git status

    # restore saved_dir
    cd "$saved_dir"
    exit 2
fi

list_file="$download_dir/doc/mga$release/manuals_in_languages.txt"

wget_options="--directory-prefix=$download_dir/doc/mga$release --timestamping --no-host-directories --recursive --no-parent --quiet"

echo "Mageia PDF and EPUB management tool (current release=$release):"
echo ''

echo 'Downloading EPUB files...'
wget $wget_options --accept epub $epub_dir

echo 'Downloading PDF files...'
wget $wget_options --accept pdf $pdf_dir

echo "Manuals in PDF and EPUB form are available in languages: " > "$list_file"

echo 'Renaming and pushing to git...'
# remember to fix 2nd argument to real directories:
rename_binary 'DrakX' 'EPUB/installer'
rename_binary 'DrakX' 'PDF/installer'

rename_binary 'MCC' 'EPUB/MCC'
rename_binary 'MCC' 'PDF/MCC'

rename_binary 'NetInstall' 'EPUB/netinstall'
rename_binary 'NetInstall' 'PDF/netinstall'

rename_binary 'DrakLive' 'EPUB/draklive'
rename_binary 'DrakLive' 'PDF/draklive'

if [ "$commit_needed" == "yes" ]; then
    echo Mageia $release > "$local_git/doc_binaries_for_website/mga$release/date.txt"
    LC_ALL=C date -u >> "$local_git/doc_binaries_for_website/mga$release/date.txt"
    git add "doc_binaries_for_website/mga$release/date.txt"
    git commit -m "adding/updating date.txt file (mirror upload date check) for release $release"
fi

echo ""
echo "List file shown bellow is here: $list_file"
cat "$list_file"

# restore saved_dir
cd "$saved_dir"