summarylogtreecommitdiffstats
path: root/pacman-ps.install
blob: 9b5d17ba48cf0758430c9374e888b77075c2dbc7 (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
# This generated the initial database for pacman-ps
DB_DIR="/var/cache/pacman-ps"
post_install() {
  # If the database exists, just update it and keep existing entries
  if [ -f "${DB_DIR}/files.db" ]; then
    pacman -Ql | sort -u -k 2,2 - "${DB_DIR}/files.db" > "${DB_DIR}/files-temp.db"
  # Otherwise create it
  else
    mkdir -p "${DB_DIR}"
    pacman -Ql | sort -u -k 2,2 -  > ${DB_DIR}/files-temp.db
  fi
  rm "${DB_DIR}/files.db"
  mv "${DB_DIR}/files-temp.db" "${DB_DIR}/files.db"
  printf "Created initial database at %s/files.db\n" "${DB_DIR}"
}

# On package upgrade if the database doesn't exist, create it
post_upgrade() {
  if [ ! -f "${DB_DIR}/files.db" ]; then
    printf "Can't find database at %s/files.db\nGenerating one" "${DB_DIR}"
    pacman -Ql | sort -u -k 2,2 - > ${DB_DIR}/files-temp.db
  fi
}

# This removes the initial database for pacman-ps if it exists
post_remove() {
  if [ -d "${DB_DIR}" ]; then
    rm -rf "${DB_DIR}"
  fi
}