Merge pull request #268619 from tweag/lib-descriptions
[NixPkgs.git] / pkgs / applications / office / libreoffice / update.sh
bloba04e668e8188f33bad4d355ad21fd9372d21603c
1 #!/usr/bin/env nix-shell
2 #!nix-shell -i bash -p python3 pup curl jq nix
4 set -euo pipefail
5 echoerr() { echo "$@" 1>&2; }
7 fname="$1"
8 echoerr got fname $fname
9 shift
11 variant="$1"
12 # See comment near version_major variable
13 if [[ $variant == fresh ]]; then
14 head_tail=head
15 elif [[ $variant == still ]]; then
16 head_tail=tail
17 else
18 echoerr got unknown variant $variant
19 exit 3
21 echoerr got variant $variant
22 shift
24 # Not totally needed, but makes it easy to run the update in case tis folder is
25 # deleted.
26 mkdir -p "$(dirname $fname)/src-$variant"
27 cd "$(dirname $fname)/src-$variant"
29 # The pup command prints both fresh and still versions one after another, and
30 # we use either head -1 or tail -1 to get the right version, per the if elif
31 # above.
32 version_major="$(curl --silent https://www.libreoffice.org/download/download-libreoffice/ |\
33 pup '.dl_version_number text{}' | $head_tail -1)"
34 echoerr got from website ${variant}_version $version_major
35 baseurl=https://download.documentfoundation.org/libreoffice/src/$version_major
36 tarballs=($(curl --silent $baseurl/ |\
37 pup 'table json{}' |\
38 jq --raw-output '.. | .href? | strings' |\
39 grep "$version_major.*.tar.xz$"))
41 full_version="$(echo ${tarballs[0]} | sed -e 's/^libreoffice-//' -e 's/.tar.xz$//')"
42 echoerr full version is $full_version
43 echo \"$full_version\" > version.nix
45 for t in help translations; do
46 echo "{" > $t.nix
47 echo " sha256 = "\"$(nix-prefetch-url $baseurl/libreoffice-$t-$full_version.tar.xz)'";' >> $t.nix
48 echo " url = "\"$baseurl/libreoffice-$t-$full_version.tar.xz'";' >> $t.nix
49 echo "}" >> $t.nix
50 done
52 # Out of loop nix-prefetch-url, because there is no $t, and we want the output
53 # path as well, to get the download.lst file from there afterwards.
54 main_path_hash=($(nix-prefetch-url --print-path $baseurl/libreoffice-$full_version.tar.xz))
55 echo "{" > main.nix
56 echo " sha256 = "\"${main_path_hash[0]}'";' >> main.nix
57 echo " url = "\"$baseurl/libreoffice-$full_version.tar.xz'";' >> main.nix
58 echo "}" >> main.nix
59 echoerr got filename ${main_path_hash[1]}
61 # Environment variable required by ../generate-libreoffice-srcs.py
62 export downloadList=/tmp/nixpkgs-libreoffice-update-download-$full_version.lst
63 # Need to extract the file only if it doesn't exist, otherwise spare time be
64 # skipping this.
65 if [[ ! -f "$downloadList" ]]; then
66 tar --extract \
67 --file=${main_path_hash[1]} \
68 libreoffice-$full_version/download.lst \
69 -O > $downloadList
70 else
71 echoerr relying on previously downloaded downloadList file
73 cd ..
74 python3 ./generate-libreoffice-srcs.py > src-$variant/deps.nix