]> git.ipfire.org Git - people/ms/ipfire-3.x.git/blob - pkgs/pakfire/src/index
Move packages to pkgs subdirectory.
[people/ms/ipfire-3.x.git] / pkgs / pakfire / src / index
1 #!/bin/bash
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007, 2008, 2009 Michael Tremer & Christian Schmidt #
6 # #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
11 # #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
16 # #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
19 # #
20 ###############################################################################
21
22 . functions
23
24 db_fields="name version release group maintainer license summary description deps hash"
25 for field in $db_fields; do
26 if [ -n "${fields}" ]; then
27 fields="${fields}, '${field}'"
28 else
29 fields="'${field}'"
30 fi
31 done
32
33
34 function db() {
35 if [ -z "${database}" ]; then
36 echo "Database is not defined."
37 exit 1
38 fi
39 #echo "SQL: $@"
40 sqlite3 ${database} "$@"
41 }
42
43 while [ "$#" -gt "0" ]; do
44 case "$1" in
45 --database=*)
46 database=${1#--database=}
47 ;;
48 --force|-f)
49 FORCE=1
50 ;;
51 *.ipk)
52 packages="${packages} ${1}"
53 ;;
54 *)
55 echo "Unrecognized option: \"${1}\"."
56 ;;
57 esac
58 shift
59 done
60
61 if [ -e "${database}" ]; then
62 echo "Database \"${database}\" does already exist."
63 if [ "$FORCE" = "1" ]; then
64 > ${database}
65 else
66 exit 1
67 fi
68 fi
69
70 echo "Collecting available packages..."
71 available=$(for package in ${packages}; do
72 echo $(pkg_name $package)
73 done | sort -u)
74
75 printf " There are %4d packages available.\n\n" $(echo "${available}" | wc -w)
76
77 echo "Checking dependency tree..."
78 for package in ${packages}; do
79 #echo " ${package##*/}"
80 for dep in $(pkg_deps ${package}); do
81 okay=
82 for avail in ${available}; do
83 if [ "${dep}" = "${avail}" ]; then
84 okay=1
85 break
86 fi
87 done
88 if [ "${okay}" != "1" ]; then
89 echo "Dependency \"${dep}\" of \"${package##*/}\" could not be resolved."
90 [ "${FORCE}" = "1" ] || exit 1
91 fi
92 done
93 done
94
95 echo "Creating database..."
96 db "CREATE TABLE packages($fields);"
97
98 echo "Writing packages to database..."
99 for package in ${packages}; do
100 echo " ${package##*/}"
101 args=
102 IFS=$", "
103 for field in $db_fields; do
104 if [ -n "${args}" ]; then
105 args="${args}, \"$(pkg_$field ${package})\""
106 else
107 args="\"$(pkg_$field ${package})\""
108 fi
109 done
110 unset IFS
111
112 db "INSERT INTO packages VALUES($args);"
113 done
114
115 db "CREATE TABLE info(key, value);"
116 db "INSERT INTO info(key, value) VALUES('date', '$(date -u)');"
117 db "INSERT INTO info(key, value) VALUES('host', '$(cat /proc/sys/kernel/hostname)');"