tazpkg annotate modules/recharge @ rev 953

revision of german messages
author Hans-G?nter Theisgen
date Mon Oct 09 17:16:43 2017 +0100 (2017-10-09)
parents ce0db4329d29
children 9d683c983e2e
rev   line source
al@834 1 #!/bin/sh
al@834 2 # TazPkg - Tiny autonomous zone packages manager, hg.slitaz.org/tazpkg
al@834 3 # recharge - TazPkg module
al@834 4 # Recharge packages databases from a mirror
al@834 5
al@834 6
al@834 7 # Options:
al@834 8 # [main|<repository>] Repository name to recharge (all if empty)
al@834 9
al@834 10 # Environment variables:
al@834 11 # root Root of the packages DB
al@834 12 # UA User Agent string ("TazPkg-<version>")
al@834 13
al@834 14
al@834 15 # Connect function libraries
al@834 16 . /lib/libtaz.sh
al@834 17
al@836 18 # Get TazPkg working environment
al@840 19 . @@MODULES@@/getenv
al@834 20
al@834 21
al@836 22
al@836 23
al@834 24 # Functions
al@834 25 # ---------
al@834 26
al@834 27 # Download a file from specified mirror
al@834 28
al@836 29 get_from_mirror() {
al@857 30 debug "get_from_mirror($1)"
al@857 31 debug " mirror='$mirror'"
al@836 32 case "$mirror" in
al@836 33 http://* | https://* | ftp://*)
al@857 34 debug " wget -c -q -T 30 -U '$UA' '$mirror$1'"
al@846 35 wget -c -q -T 30 -U "$UA" "$mirror$1" 2>/dev/null;;
al@836 36 *)
al@889 37 debug " cp '$mirror$1' ."
al@889 38 cp "$mirror$1" .;;
al@836 39 esac
al@836 40 status
al@834 41 }
al@834 42
al@834 43
al@834 44 # When recharging errors occur
al@834 45
al@834 46 recharging_failed() {
al@834 47 # Restore database from bak files
al@834 48 action 'Restoring database files...'
al@834 49 [ -e 'ID' -a ! -e 'ID.bak' ] && rm ID
al@834 50 [ -e 'IDs' -a ! -e 'IDs.bak' ] && rm IDs
al@840 51 for file in $(ls "$1"/*.bak); do
al@840 52 mv -f "$file" "${file%.bak}"
al@834 53 done
al@834 54 status
al@834 55
al@834 56 footer "$(colorize 31 "$(_ 'Recharging failed')")"
al@834 57 }
al@834 58
al@834 59
al@834 60
al@834 61
al@834 62 REPO="$1"
al@834 63
al@834 64 # What to recharge: main, or all, or selected undigest
al@834 65 case "$REPO" in
al@834 66 main) repo_to_recharge="$PKGS_DB";;
al@834 67 '') repo_to_recharge="$PKGS_DB $PKGS_DB/undigest/*";;
al@834 68 *) repo_to_recharge="$PKGS_DB/undigest/$REPO"
al@834 69 if [ ! -d "$repo_to_recharge" ]; then
al@834 70 _ "Repository \"%s\" doesn't exist." "$repo_to_recharge" >&2
al@834 71 exit 1
al@834 72 fi
al@834 73 ;;
al@834 74 esac
al@834 75
al@834 76 for path in $repo_to_recharge; do
al@899 77 # skip?
al@899 78 [ ! -s "$path/mirror" ] && continue
al@840 79 cd "$path"
al@836 80 # Mirror URL will have a trailing slash
al@840 81 mirror=$(cat mirror); mirror="${mirror%/}/"
al@834 82
al@834 83 # Repository name
al@834 84 if [ "$path" == "$PKGS_DB" ]; then
al@834 85 repo_name='Main'
al@834 86 else
al@834 87 repo_name="$(_n 'Undigest %s' "$(basename "$path")")"
al@834 88 fi
al@834 89
al@834 90 title 'Recharging repository "%s"' "$repo_name"
al@834 91
al@834 92 # Don't let ID be a symlink when using local repository.
al@834 93 if [ -h ID ]; then mv -f ID ID.lnk; cat ID.lnk > ID; rm ID.lnk; fi
al@834 94 if [ -h IDs ]; then mv -f IDs IDs.lnk; cat IDs.lnk > IDs; rm IDs.lnk; fi
al@834 95
al@899 96 # Compatibility with "old" ID
al@899 97 [ -f ID ] && mv ID ID.bak
al@834 98 [ -f IDs ] && mv IDs IDs.bak
al@836 99 action 'Checking...'
al@836 100 get_from_mirror IDs
al@836 101
al@899 102 # Compatibility with "old" ID
al@899 103 [ -e 'IDs' ] && awk '{print $1}' IDs > ID
al@899 104 [ -e 'IDs' -a -z "$quiet" ] && \
al@899 105 _ 'Database timestamp: %s' "$(date -d "@$(awk '{print $2}' IDs)" "+%x %R")"
al@834 106
al@834 107 # Check if recharging is needed
al@840 108 if [ -f 'IDs' ] && [ -f 'packages.info' ] && [ -f 'files.list.lzma' ] && \
al@840 109 cmp -s IDs IDs.bak; then
al@834 110 footer "$(_ 'Repository "%s" is up to date.' "$repo_name")"
al@834 111 rm IDs.bak ID.bak
al@834 112 continue
al@834 113 fi
al@834 114 rm IDs.bak ID.bak 2>/dev/null
al@834 115
al@834 116 action 'Creating backup of the last packages list...'
al@834 117 for i in packages.desc packages.$SUM packages.txt packages.list \
al@834 118 packages.equiv files.list.lzma extra.list mirrors packages.info; do
al@834 119 [ -f "$i" ] && mv -f $i $i.bak 2>/dev/null
al@834 120 done
al@840 121 # Always "[ Done ]"
al@840 122 :; status
al@834 123
al@834 124 # Download and extract bundle: extra.list, mirrors, files-list.md5,
al@834 125 # packages.{info,desc,md5,txt,list,equiv}
al@834 126 bundle='bundle.tar.lzma'
al@840 127 action 'Getting "%s"...' "$bundle"
al@840 128 get_from_mirror "$bundle"
al@834 129 if [ -f "$bundle" ]; then
al@846 130 tar -xaf "$bundle"; rm "$bundle"
al@834 131 else
al@840 132 recharging_failed "$path"; continue
al@834 133 fi
al@834 134
al@834 135 # Download files.list.lzma
al@834 136 files_local='files.list.lzma'; files_remote='files-list.lzma'
al@834 137 if [ -e "$files_local.bak" ]; then
al@840 138 md5sum "$files_local.bak" | awk '{printf $1}' > files-list.md5.bak
al@834 139 if cmp -s files-list.md5 files-list.md5.bak; then
al@840 140 mv "$files_local.bak" "$files_remote"
al@834 141 else
al@840 142 action 'Getting "%s"...' "$files_remote"
al@840 143 get_from_mirror "$files_remote"
al@834 144 fi
al@834 145 else
al@840 146 action 'Getting "%s"...' "$files_remote"
al@840 147 get_from_mirror "$files_remote"
al@834 148 fi
al@834 149
al@834 150 if [ ! -e "$files_remote" ]; then
al@840 151 recharging_failed "$path"; continue
al@834 152 fi
al@840 153 mv -f "$files_remote" "$files_local"
al@834 154
al@834 155 # Remove old database files (but packages.list.bak, extra.list.bak)
al@834 156 for i in packages.desc packages.$SUM packages.txt packages.equiv \
al@834 157 files.list.lzma mirrors packages.info files-list.md5; do
al@834 158 [ -f "$i.bak" ] && rm $i.bak 2>/dev/null
al@834 159 done
al@834 160
al@834 161 footer "$(_ 'Last database is ready to use.')"
al@834 162
al@834 163 # Check diff
al@834 164 if [ -f 'packages.list.bak' ]; then
al@834 165 diff -u packages.list.bak packages.list | grep ^+[a-z] > packages.diff
al@834 166 rm packages.list.bak
al@834 167 if [ -f 'extra.list.bak' ]; then
al@834 168 if [ -f 'extra.list' ]; then
al@840 169 awk -F'|' '{print $1 " (extra)"}' extra.list > extra.list1
al@834 170 awk -F'|' '{print $1 " (extra)"}' extra.list.bak > extra.list1.bak
al@834 171 diff -u extra.list1.bak extra.list1 | grep ^+[a-z] >> packages.diff
al@834 172 rm extra.list.bak extra.list1 extra.list1.bak
al@834 173 else
al@834 174 mv extra.list.bak extra.list
al@834 175 fi
al@834 176 fi
al@834 177 sed -i s/+// packages.diff
al@834 178
al@834 179 new_pkgs=$(wc -l < packages.diff)
al@834 180 if [ "$new_pkgs" -gt 0 ]; then
al@834 181 title 'Mirrored packages diff'
al@834 182 cat packages.diff
al@834 183 footer "$(emsg "$(_p \
al@834 184 '%s new package on the mirror.' \
al@840 185 '%s new packages on the mirror.' "$new_pkgs" \
al@834 186 "<c 32>$new_pkgs</c>")")"
al@834 187 fi
al@834 188 else
al@834 189 longline "$(_ "Note that next time you recharge the list, a list of \
al@834 190 differences will be displayed to show new and upgradeable packages.")"
al@834 191 fi
al@834 192 done
al@834 193 newline
al@840 194
al@840 195 # Close tazpkg-notify
al@840 196 echo "quit" > /tmp/tazpkg-notify.fifo