summaryrefslogtreecommitdiff
path: root/archPackagesUpdate
blob: 94ffc34754f7a033de0fa40005a54e3d8de21dd4 (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
#!/bin/bash

# init variables
tmpDir="$(mktemp -d /tmp/archive.XXXXXX)"
pkgDir="/srv/arch-mirror/arch/arch/archlinuxewe/os/x86_64"
pkgSrcDir="$(dirname $(readlink -f -n "$0"))"
[ "$(hostname)" == "rechenknecht" ] && aufRechenknecht=true || aufRechenknecht=false
force=false
upload=true
updateMe=true

# parse arguments
eval set -- "$(getopt -o f --long force,no-upload,no-selfUpdate -n "$(basename "$0")" -- "$@")"
while true
do
  case $1 in
    -f|--force)
      force=true
      shift
    ;;
    --no-upload)
      upload=false
      shift
    ;;
    --no-selfUpdate)
      updateMe=false
      shift
    ;;
    --)
      shift
      break
    ;;
    *)
      >&2 echo "FEHLER: Verstehe Option \"$1\" doch nicht! Ich beende."
      exit 1
  esac
done

if [ ! $# -eq 0 ]
then
  >&2 echo 'FEHLER: Zu viele Argumente! Ich beende.'
  exit 1
fi

$aufRechenknecht && pkgSrcDir="${pkgSrcDir}/archPackages"
cd "${pkgSrcDir}"

# extract git HEAD
git archive --format tar HEAD | \
  tar -x -C "${tmpDir}" -f -

cd "${tmpDir}"

# update $0
if ${updateMe} && ${aufRechenknecht} && [ -e "$(basename $0)" ] && ! diff -q "$(basename $0)" "$0" &> /dev/null
then
  cp "$(basename $0)" "$0"
  $0 $@
  err=$?
  rm -rf "${tmpDir}"
  exit ${err}
fi

# collect packages
pakete="$( \
  for paket in $( \
    echo */PKGBUILD | \
      sed "s|/PKGBUILD||g" \
    )
  do
    [ -d "${paket}" ] || continue
    . ${paket}/PKGBUILD
    pkgFile="${paket}-${pkgver}-${pkgrel}-${arch[0]}.pkg.tar.xz"
    ${force} || \
      ! ${aufRechenknecht} || \
      [ ! -e "${pkgDir}/${pkgFile}" ] && \
        echo "${paket}"
  done
  )"

if ${aufRechenknecht}
then
# build packages
  for paket in ${pakete}
  do
    cd "${tmpDir}/${paket}"
    rm -f ${paket}-*.pkg.tyr.xz
    makepkg -fcsr || exit $?
    ${upload} && scp ${tmpDir}/${paket}/${paket}-*.pkg.tyr.xz paule@127.0.0.1:${pkgDir}/
  done

# upload packages
  ${upload} && ssh paule@127.0.0.1 ' \
    cd "'${pkgDir}'"
    for paket in '${pakete}'
    do
      alles="$(ls ${paket}*.pkg.tar.xz)"
      anz="$(echo "${alles}" | wc -l)"
      for version in $( \
        echo "${alles}" | \
          sed "s|^.*-\([^-]*-[^-]*\)-[^-]*\$|\1|" | \
          sort -V | \
          head -n$[${anz}-1] \
        )
      do
        rm ${paket}-${version}-*.pkg.tar.xz
      done
    done

# update db
    repo-add \
      '${pkgDir}'/archlinuxewe.db.tar.gz \
      '${pkgDir}'/*.pkg.tar.xz
  '
else

# check packages
  err=false
  for paket in ${pakete}
  do
    . ${paket}/PKGBUILD
    echo "${source}" | \
      grep -q "opensources\.eckner\.net" || \
        continue
    remSum="$(curl -o - "${source#*::}&post=sha256sum" 2> /dev/null)"
    if [ ! "${remSum}" == "${sha256sums}" ]
    then
      echo "sha256sum von ${pkgname} stimmt nicht: ${remSum} vs. ${sha256sums}."
      err=true
    fi

  done
  ${err} && exit 1

  cd "${pkgSrcDir}"
  git push || exit $?

  ssh rechenknecht "~/archPackagesUpdate" || exit $?
fi

# clean up
rm -rf "${tmpDir}"