| 1 | #!/bin/bash |
| 2 | |
| 3 | #shellcheck disable=SC2154 |
| 4 | if [[ -x "${UPAC_settingsd}/10_aide_sourceslist" ]]; then |
| 5 | #shellcheck disable=SC1090 |
| 6 | . "${UPAC_settingsd}/10_aide_sourceslist" |
| 7 | fi |
| 8 | VARDIR="var/lib/apt" |
| 9 | LISTSDIR="${VARDIR}/lists" |
| 10 | CACHEDIR="var/cache/apt" |
| 11 | ARCHIVESDIR="${CACHEDIR}/archives" |
| 12 | SYSTEMDDIR="var/lib/systemd/timers" |
| 13 | LOGDIR="var/log/apt" |
| 14 | IGNORE_ARCHIVES="" |
| 15 | IGNORE_FRQCHG="" |
| 16 | |
| 17 | if [[ -r "${UPAC_settingsd}/31_aide_apt_settings" ]]; then |
| 18 | # pull in configuration |
| 19 | #shellcheck disable=SC1090 |
| 20 | . "${UPAC_settingsd}/31_aide_apt_settings" |
| 21 | fi |
| 22 | |
| 23 | if [[ -n "${DEBUG}" ]]; then |
| 24 | printf "# debug output of 31_aide_apt\\n" |
| 25 | fi |
| 26 | |
| 27 | # wait for /${LISTSDIR}/partial to be empty to reduce probabilty of finding |
| 28 | # something laying around there |
| 29 | COUNT=10 |
| 30 | while [[ -n "$(ls -A "/${LISTSDIR}/partial" 2>/dev/null)" ]] && [[ "${COUNT}" -gt 0 ]]; do |
| 31 | COUNT=$(( COUNT-1 )) |
| 32 | sleep 10 |
| 33 | done |
| 34 | |
| 35 | printf "@@if not defined APT_TRANSLATIONS\\n" |
| 36 | printf "@@define APT_TRANSLATIONS (ca|cs|da|de|de_DE|en|eo|es|eu|fi|fr|hr|hu|id|it|ja|km|ko|nb|nl|pl|pt|pt_BR|ro|ru|sk|sr|sv|uk|vi|zh|zh_CN|zh_TW)\\n" |
| 37 | printf "@@endif\\n" |
| 38 | printf "@@if not defined APT_ARCH\\n" |
| 39 | printf "@@define APT_ARCH (@@{ARCH}|all)\\n" |
| 40 | printf "@@endif\\n" |
| 41 | |
| 42 | # regular expression to parse apt source files |
| 43 | RE="^\\(deb\\|deb-src\\)[[:space:]]\\+\\(\\(\\[[^]]\\+\\]\\)[[:space:]]\\+\\)\\?\\([^[:space:]]\\+\\)[[:space:]]\\+\\([^[:space:]]\\+\\)[[:space:]]\\+\\(.*\\)$" |
| 44 | if [[ -n "${DEBUG}" ]]; then |
| 45 | printf "# SOURCESLIST: %s\\n" "${SOURCESLIST}" |
| 46 | printf "# RE: %s\\n" "${RE}" |
| 47 | fi |
| 48 | |
| 49 | |
| 50 | #shellcheck disable=SC2086 |
| 51 | awk 'FNR==1 && NR>1 {print ""} {print} END {print ""}' ${SOURCESLIST} /dev/null | sed 's/ #.*$//' | while read -r line; do |
| 52 | if [[ -n "${DEBUG}" ]]; then |
| 53 | printf "# read line: %s\n" "${line}" |
| 54 | fi |
| 55 | if [[ -n "${complete}" ]]; then |
| 56 | complete="" |
| 57 | deb="" |
| 58 | uri="" |
| 59 | dist="" |
| 60 | comp="" |
| 61 | fi |
| 62 | case "${line}" in |
| 63 | Types:*) |
| 64 | deb=$(echo "${line}" | awk '{print $2}') |
| 65 | [[ -n "${DEBUG}" ]] && printf "# Types line: %s\\n" "${deb}" |
| 66 | ;; |
| 67 | URIs:*) |
| 68 | uri=$(echo "${line}" | awk '{print $2}') |
| 69 | [[ -n "${DEBUG}" ]] && printf "# URIs line: %s\\n" "${uri}" |
| 70 | ;; |
| 71 | Suites:*) |
| 72 | dist=$(echo "${line}" | awk '{print $2}') |
| 73 | [[ -n "${DEBUG}" ]] && printf "# Suites line: %s\\n" "${dist}" |
| 74 | ;; |
| 75 | Components:*) |
| 76 | comp=$(echo "${line}" | cut -d' ' -f2-) |
| 77 | [[ -n "${DEBUG}" ]] && printf "# Components line: %s\\n" "${comp}" |
| 78 | ;; |
| 79 | "") |
| 80 | [[ -n "${DEBUG}" ]] && printf "# empty line\\n" |
| 81 | if [[ -n "${deb}" ]] || [[ -n "${uri}" ]] || [[ -n "${dist}" ]] || [[ -n "${comp}" ]]; then |
| 82 | if [[ -z "${deb}" ]] || [[ -z "${uri}" ]] || [[ -z "${dist}" ]] || [[ -z "${comp}" ]]; then |
| 83 | [[ -n "${DEBUG}" ]] && printf "# incomplete deb822 entry read\\n" |
| 84 | complete="" |
| 85 | else |
| 86 | complete=1 |
| 87 | fi |
| 88 | fi |
| 89 | ;; |
| 90 | deb*) |
| 91 | set -- $(echo "${line}" | sed -n "s/${RE}/\1 \4 \5/p") "$(echo "${line}" | sed -n "s/${RE}/\6/p")" |
| 92 | deb="${1}" |
| 93 | uri="${2}" |
| 94 | dist="${3}" |
| 95 | comp="${4}" |
| 96 | [[ -n "${DEBUG}" ]] && printf "# deb (old style) line: deb=%s uri=%s dist=%s comp=%s\\n" "${deb}" "${uri}" "${dist}" "${comp}" |
| 97 | complete="1" |
| 98 | ;; |
| 99 | esac |
| 100 | if [[ -n "${complete}" ]]; then |
| 101 | if [[ -n "${DEBUG}" ]]; then |
| 102 | |
| 103 | printf "# complete apt source entry read:\\n" |
| 104 | printf "# deb: %s\\n" "${deb}" |
| 105 | printf "# uri: %s\\n" "${uri}" |
| 106 | printf "# dist: %s\\n" "${dist}" |
| 107 | printf "# comp: %s\\n" "${comp}" |
| 108 | fi |
| 109 | #shellcheck disable=SC2001 |
| 110 | PROTOCOL="$(echo "${uri}" | sed 's|\([^:]\+\).*|\1|')" |
| 111 | if echo "${PROTOCOL}" | grep -qE '(https?|ftp)'; then |
| 112 | HOST="$(echo "${uri}" | sed -e 's|.*//\([-_.[:alnum:]]\+\).*|\1|' -e 's|\.|\\\\.|g')" |
| 113 | HOSTPATH="$(echo "${uri}" | sed -e 's|.*//[^/[:space:]]\+/\?||;s|/$||;s|/|_|g;s|^\(.\+\)$|_\1|' -e 's|\.|\\\\.|g')" |
| 114 | dist="${dist//\//_}" |
| 115 | if [[ -n "${DEBUG}" ]]; then |
| 116 | printf "# host %s\\n" "${HOST}" |
| 117 | printf "# hostpath %s\\n" "${HOSTPATH}" |
| 118 | fi |
| 119 | if [[ "${deb}" = "deb" ]]; then |
| 120 | for c in ${comp}; do |
| 121 | printf "/%s(/partial)?/%s%s_dists_%s_%s_binary-@@{APT_ARCH}_Packages(\\\\\\\\.diff_Index)?$ f VarFile\\n" "${LISTSDIR}" "${HOST}" "${HOSTPATH}" "${dist}" "${c}" |
| 122 | printf "/%s(/partial)?/%s%s_dists_%s_%s_Contents-@@{APT_ARCH}((\\\\\\\\.diff_Index|\\\\\\\\.lz4))?$ f VarFile\\n" "${LISTSDIR}" "${HOST}" "${HOSTPATH}" "${dist}" "${c}" |
| 123 | printf "/%s(/partial)?/%s%s_dists_%s_%s_dep11_Components-@@{APT_ARCH}((\\\\\\\\.yml\\\\\\\\.gz))?$ f VarFile\\n" "${LISTSDIR}" "${HOST}" "${HOSTPATH}" "${dist}" "${c}" |
| 124 | printf "@@if defined FOREIGN_ARCHES\\n" |
| 125 | printf "/%s/%s%s_dists_%s_%s_binary-@@{FOREIGN_ARCHES}_Packages(\\\\\\\\.diff_Index)?$ f VarFile\\n" "${LISTSDIR}" "${HOST}" "${HOSTPATH}" "${dist}" "${c}" |
| 126 | printf "@@endif\\n" |
| 127 | printf "/%s/%s%s_dists_%s_(InRelease|Release(\\\\\\\\.gpg)?)$ f VarFile-acl\\n" "${LISTSDIR}" "${HOST}" "${HOSTPATH}" "${dist}" |
| 128 | printf "/%s/%s%s_dists_%s_%s_i18n_Translation-@@{APT_TRANSLATIONS}(\\\\\\\\.diff_Index)?$ f VarFile\\n" "${LISTSDIR}" "${HOST}" "${HOSTPATH}" "${dist}" "${c}" |
| 129 | done |
| 130 | printf "!/%s/partial/%s%s_dists_%s_(InRelease|Release\\\\\\\\.gpg\\\\\\\\.reverify)$ f\\n" "${LISTSDIR}" "${HOST}" "${HOSTPATH}" "${dist}" |
| 131 | elif [[ "${deb}" = "deb-src" ]]; then |
| 132 | for c in ${comp}; do |
| 133 | printf "/%s/%s%s_dists_%s_%s_source_Sources(\\\\\\\\.diff_Index)?$ f VarFile\\n" "${LISTSDIR}" "${HOST}" "${HOSTPATH}" "${dist}" "${c}" |
| 134 | printf "/%s/%s%s_dists_%s_(InRelease|Release(\\\\\\\\.gpg)?)$ f VarFile-acl\\n" "${LISTSDIR}" "${HOST}" "${HOSTPATH}" "${dist}" |
| 135 | done |
| 136 | fi |
| 137 | else |
| 138 | : # other protocols are not supported. If you feel like they should |
| 139 | : # please give a good reason and probably a patch. |
| 140 | fi |
| 141 | printf "\\n\\n" |
| 142 | fi |
| 143 | done |
| 144 | |
| 145 | printf "/%s(/(auxfiles|partial))?$ d VarDir\\n" "${LISTSDIR}" |
| 146 | printf "/%s/lock$ f VarFile\\n" "${LISTSDIR}" |
| 147 | printf "/%s/periodic/(download-upgradeable|update)-stamp$ f VarTime\\n" "${VARDIR}" |
| 148 | printf "/%s/(daily_lock|extended_states)$ f VarFile\\n" "${VARDIR}" |
| 149 | printf "/%s$ d VarDir\\n" "${VARDIR}" |
| 150 | printf "\\n" |
| 151 | printf "/%s/stamp-apt-daily(-upgrade)?\\\\\\\\.timer$ f VarFile\\n" "${SYSTEMDDIR}" |
| 152 | printf "\\n" |
| 153 | printf "/%s/(term|history)\\\\\\\\.log$ f ActLog\\n" "${LOGDIR}" |
| 154 | printf "/%s/(term|history)\\\\\\\\.log\\\\\\\\.1\\\\\\\\.@@{LOGEXT}$ f CompSerLog+ANF\\n" "${LOGDIR}" |
| 155 | printf "/%s/(term|history)\\\\\\\\.log\\\\\\\\.([2-9]|1[0-1])\\\\\\\\.@@{LOGEXT}$ f MidlSerLog\\n" "${LOGDIR}" |
| 156 | printf "/%s/(term|history)\\\\\\\\.log\\\\\\\\.12\\\\\\\\.@@{LOGEXT}$ f LastSerLog\\n" "${LOGDIR}" |
| 157 | printf "/%s/eipp\\\\\\\\.log\\\\\\\\.xz$ f VarFile\\n" "${LOGDIR}" |
| 158 | printf "/%s$ d VarDir\\n" "${LOGDIR}" |
| 159 | printf "\\n" |
| 160 | printf "/var/backups/apt\\\\\\\\.extended_states\\\\\\\\.0$ f ActLog\\n" |
| 161 | printf "/var/backups/apt\\\\\\\\.extended_states\\\\\\\\.1\\\\\\\\.@@{LOGEXT}$ f CompSerLog+ANF\\n" |
| 162 | printf "/var/backups/apt\\\\\\\\.extended_states\\\\\\\\.[2345]\\\\\\\\.@@{LOGEXT}$ f MidlSerLog\\n" |
| 163 | printf "/var/backups/apt\\\\\\\\.extended_states\\\\\\\\.6\\\\\\\\.@@{LOGEXT}$ f LastSerLog\\n" |
| 164 | |
| 165 | if [[ "${IGNORE_ARCHIVES}" = "yes" ]]; then |
| 166 | printf "!/%s/[-[:alnum:]%%\.~_+]+_@@{APT_ARCH}\\\\\\\\.deb$ f\\n" "${ARCHIVESDIR}" |
| 167 | printf "@@if defined FOREIGN_ARCHES\\n" |
| 168 | printf "!/%s/[-[:alnum:]%%\.~_+]+_@@{FOREIGN_ARCHES}\\\\\\\\.deb$ f\\n" "${ARCHIVESDIR}" |
| 169 | printf "@@endif\\n" |
| 170 | fi |
| 171 | |
| 172 | if [[ "${IGNORE_FRQCHG}" = "yes" ]]; then |
| 173 | printf "/%s(/partial|/lock)?$ d VarDir\\n" "${ARCHIVESDIR}" |
| 174 | printf "!/%s/(src)?pkgcache\\\\\\\\.bin$ f\\n" "${CACHEDIR}" |
| 175 | printf "/%s$ d VarDir\\n" "${CACHEDIR}" |
| 176 | fi |
| 177 | |
| 178 | if [[ -n "${DEBUG}" ]]; then |
| 179 | printf "# end of debug output of 31_aide_apt\\n" |
| 180 | fi |
| 181 | |
| 182 | # vim: set shiftwidth=2 tabstop=2 softtabstop=2 expandtab: |