summaryrefslogtreecommitdiff
path: root/bibisect/buildWinReleasesRepository.sh
blob: c984da0ce9d20fc4e2a3c4cd708f57a550b4730a (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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/bin/bash
# This script uses msiextract.
# If you want to run it on Windows, use msiexec
# Sample: ./buildWinReleasesRepository.sh 6.3.0.0.alpha1 6.3.0.0.beta1 6.3.0.0.beta2 6.3.0.1 6.3.0.2 6.3.0.3 6.3.0.4

#Path to the folder where the msi/exe files are downloaded
rootDir=

#Path to the folder where 'win-86-releases' is
targetDir=

for var in "$@"
do
    isExeFile=0
    date
    cd $rootDir
    input=$var
    if [[ $input = *"alpha"* ||  $input = *"beta"* ]]; then
        if [[ $input = "4.0."* ]]; then
            file="LibreOfficeDev_${input}_Win_x86_install_multi.msi"
        else
            file="LibreOfficeDev_${input}_Win_x86.msi"
        fi
    else
        if [[ $input = "3.3."* ]]; then
            file="LibO_${input::-2}_Win_x86_install_all_lang.exe"
            isExeFile=1
        elif [[ $input = "3.4."* ]]; then
            file="LibO_${input::-2}_Win_x86_install_multi.exe"
            isExeFile=1
        elif [[ $input = "3.5"* ]]; then
            file="LibO_${input::-2}_Win_x86_install_multi.msi"
        elif [[ $input = "3."* ]]; then
            file="LibO_${input}_Win_x86_install_multi.msi"
        else
            file="LibreOffice_${input}_Win_x86.msi"
        fi
    fi
    if [ ! -f $rootDir/$file ]; then
        echo "File $rootDir/$file not found!"
        url="https://downloadarchive.documentfoundation.org/libreoffice/old/${input}/win/x86/${file}"
        echo "*** Downloading "
        if wget -c ${url} -O $rootDir/${file}.tmp; then
            mv $rootDir/${file}.tmp $rootDir/${file}
        else
            if [ $isExeFile -eq 1 ]; then
                extension=".exe"
            else
                extension=".msi"
            fi
            # try harder
            # In the past, some files used rcX. e.g: LibO_3.4.0rc1
            file="LibO_${input::-2}rc${input: -1}_Win_x86_install_multi${extension}"
            url="https://downloadarchive.documentfoundation.org/libreoffice/old/${input}/win/x86/${file}"
            if wget -c ${url} -O $rootDir/${file}.tmp; then
                mv $rootDir/${file}.tmp $rootDir/${file}
            else
                echo "$url doesn\'t exists"
                break
            fi
        fi
    else
        echo "File $rootDir/$file found!"
    fi

    if [ $isExeFile -eq 1 ]; then
        echo "*** Uncompressing exe file"
        7z x $rootDir/${file} -o$rootDir/exeData
        echo "*** Extracting msi"
        msiextract $rootDir/exeData/libreoffice3*.msi -C $rootDir/output &>/dev/null
        echo "*** Cleaning exe folder"
        rm -rf $rootDir/exeData/
    else
        echo "*** Extracting msi"
        msiextract $rootDir/${file} -C $rootDir/output &>/dev/null
    fi

    if [[ ! -d $rootDir/output/Program\ Files/ ]]; then
        echo "$rootDir/output/Program\ Files doesn't exists"
        rm -rf  $rootDir/output
        break
    fi

    echo "*** Moving files to instdir folder"
    mv $rootDir/output/Program\ Files/* $rootDir/instdir

    if [ $isExeFile -eq 0 ]; then
        # msvcp* and msvcr libraries
        echo "*** Copying MSVC libraries"
        if [[ $input = "3."* || $input = "4."* ]]; then
            mv $rootDir/output/Win/System/*.dll $rootDir/instdir/program/
        else
            mv $rootDir/output/System/*.dll $rootDir/instdir/program/
        fi
    fi
    rm -rf $rootDir/output

    # Change user profile folder
    echo "*** Changing bootstrap.ini"
    sed -i '/UserInstallation/d' $rootDir/instdir/program/bootstrap.ini
    echo "UserInstallation=\$ORIGIN/.." >> $rootDir/instdir/program/bootstrap.ini

    echo "*** Removing unneeded dictionaries"
    dictionaries=$(find $rootDir/instdir/share/extensions/ -type d -name dict-*)
    for dict in $dictionaries
    do
        if [[ ${dict} != *"dict-en" ]];then
            rm -r $dict
        fi
    done

    echo "*** Removing unneeded languages"
    # Use zh-TW/zh_TW to find the location of other languages not needed
    for string in zh-TW zh_TW;
    do
        findOutput=$(find $rootDir/instdir/ -name *$string*)
        for path in $findOutput
        do
            generalPath="${path/$string/"*"}"
            lsOutput=$(ls -d $generalPath)
            for filePath in $lsOutput
            do
                if [[ ${filePath} != *"US"* ]];then
                    rm -r $filePath
                fi
            done
        done
    done

    echo "*** Cleaning destination"
    rm -rf ${targetDir}/instdir/

    echo "*** Moving files to destination"
    mv $rootDir/instdir/ ${targetDir}/instdir/

    cd ${targetDir}
    par1=libreoffice-$input
    echo "*** Creating commit $par1"
    git add -A instdir/
    git commit . -m $par1 -m $file
    git clean -ffxd
    git tag -d $par1
    git tag -a $par1 -m $par1
done

cd ${targetDir}
git gc