summaryrefslogtreecommitdiff
path: root/toru
blob: 1ae336b410db4e43b7d3f6af5c201d2e5cef3479 (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
#!/bin/bash
# Queries the ABS
# License: GPL3

## TODO
# * Add license text
# * Add everything
# * Compare pacman sync against ABS (db-functions could be useful)
# * Create symlinks from pkgbase to pkgname[@] for easy package finding

## GOALS
# * Have a searchable database of PKGBUILD metadata
# * Have an interface for source-only builds
# * Possibility to hook up ABS dirs besides ABSROOT
# * Tell updates and non available binary packages

source /etc/abs.conf
source /etc/libretools.conf

[ ! -w / ] && {
    error "This script must be run as root."
    exit 1
}

# This is the syncfile, stores the last date as content and mtime
lastsyncfile=${ABSROOT}/toru.lastsync

TMPDIR=$(mktemp -d)

[[ -z ${TMPDIR} ]] && exit 1

# Stores the lastsync date
lastsync() {
  [ -e ${lastsyncfile} -a ! -w ${lastsyncfile} ] && {
      error "The sync date can't be saved. ${lastsyncfile} isn't writable."
      return 1
  }

  date +%s > ${lastsyncfile}
  touch ${lastsyncfile}
}

# Adds a field=value on the package description
addfield() {
}

# Updates the database by finding all PKGBUILDS
# Args:
update() {
# Find all the PKGBUILDs newer than the last update
# Update newer, otherwise everything
  if [ ! -e ${lastsyncfile} -o "${force}" = "y" ]; then
      msg "Forcing upgrade"
      pkgbuilds=($(find ${@} -maxdepth 2 -type f -name 'PKGBUILD'))
  else
      pkgbuilds=($(find ${@} -maxdepth 2 -type f -name 'PKGBUILD' -newer ${lastsyncfile}))
  fi

# Inform how many PKGBUILDS were found and quit immediately if none
  msg "Found $((${#pkgbuilds[*]}-1)) packages to update"
  [ ${#pkgbuilds[*]} -eq 1 ] && {
      msg2 "There's nothing to be done. Phew!"
      exit 0
  }

  for _pkgbuild in ${pkgbuilds[@]}; do

# The repo name is guessed
# You *must* use repo/pkgbase structure
    _pkgpath=$(dirname "${_pkgbuild}")
    _pkgbase=$(basename "${_pkgpath}")
    _pkgrepo=$(basename $(dirname "${_pkgpath}"))

    msg2 "Updating ${_pkgrepo}/${_pkgbase}"

    source ${_pkgbuild}

    for _pkg in ${pkgname[@]}; do
    done

    unset pkgbase pkgname pkgver pkgrel source

  done

  lastsync

}



## MAIN
command=${1:-update}; shift
force=${1:-n}; shift
dirs=${@}

${command} ${dirs[@]}

exit $?