summary refs log tree commit diff
path: root/pkgs/desktops/kde-4.4/updatekde.sh
blob: ac3297e905d833fb536350e8fe9173e27123f7c6 (plain) (blame)
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
#!/bin/sh

if [ $# -ne 2 ]; then
  echo Run this in the kde expressions directory
  echo usage: $0 oldversion newversion
  echo example: $0 4.3.4 4.3.5
  echo
  echo This will not update the l10n expressions, which have their own generator.
  echo This code supposes that the sha* assignations happen in the immediately next
  echo line to the url assignation.
  exit 1
fi

OLD=$1
NEW=$2


# Regexp to match for the old version
regexp_old="$(echo $OLD | sed -e 's/\./\\./g')"


# stdin: the result of grep -1 "\<url" $filename
# $1: the filename grepped, because this will modify it.
function updateinfile() {
  local newhash oldhash
  local file=$1
  echo File: $file
  while read line; do
    if echo "$line" | grep -q -e "$regexp_old"; then
      url=$(echo "$line" | sed 's/.*\<url *= *"\?\(.*\)"\?.*;.*/\1/')
      echo - Url: "$url"
      newurl=$(echo $url | sed s/"$regexp_old"/$NEW/g)
      echo - New Url: "$newurl"
      newhash=$(nix-prefetch-url "$newurl")
      if [ $? -ne 0 ]; then
         echo Error downloading
         exit 1;
      fi
      echo - New Hash: "$newhash"
    elif echo "$line" | grep -q -e '\<sha[0-9]\+ *='; then
      oldhash=$(echo "$line" | sed 's/.*"\(.*\)".*/\1/')
      echo - Oldhash: $oldhash
      # Update the old hash in the file for the new hash
      sed -i 's/\(.*\)sha.*'$oldhash'.*/\1sha256 = "'$newhash'";/g' $file
    fi
  done
  sed -i s/"$regexp_old"/$NEW/g $file
}


# stdin: the nix files, which have 'fetchurl' calls downloading the old version files
function updatefiles() {
  while read A; do
    # If the file has the old version in it...
    if grep -q -e "$regexp_old" $A; then

      # Pass the url parameters and the surrounding shaXXX = expression to updateinfile
      grep -1 "\<url\>" $A > tmp;
      < tmp updateinfile $A
    fi
  done
}

# Apply the version update to all nix files but l10n from '.'
find . -\( -name *.nix -and -not -path "*l10n*" -\) | updatefiles