s243a

install_package

Jun 9th, 2018
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 6.90 KB | None | 0 0
  1. #line 172 to 387 /usr/libexec/tazpkg/install from TazPup alpha 9
  2. install_package() {
  3. debug "\ninstall_package('$1')"
  4. local dir
  5. PACKAGE_FILE="$1"
  6. TMP_DIR="$(mktemp -d)"
  7. { cd "$TMP_DIR"; cpio --quiet -i receipt >/dev/null 2>&1; } < "$PACKAGE_FILE"
  8. (
  9. . "$TMP_DIR/receipt"
  10. cat > "$TMP_DIR/receipt.var" <<EOT
  11. PACKAGE="$PACKAGE"
  12. VERSION="$VERSION"
  13. EXTRAVERSION="$EXTRAVERSION"
  14. CATEGORY="$CATEGORY"
  15. SHORT_DESC="$SHORT_DESC"
  16. WEB_SITE="$WEB_SITE"
  17. TAGS="$TAGS"
  18. DEPENDS="$DEPENDS"
  19. CONFIG_FILES="$CONFIG_FILES"
  20. PACKED_SIZE="$PACKED_SIZE"
  21. UNPACKED_SIZE="$UNPACKED_SIZE"
  22. EOT
  23. rm "$TMP_DIR/receipt"
  24. )
  25. . "$TMP_DIR/receipt.var"
  26. mkdir -p "$INSTALLED/$PACKAGE"
  27. find "$INSTALLED/$PACKAGE" -type f \( ! -name modifiers ! -name files.list \) -delete
  28. touch "$PKGS_DB/installed.$SUM"
  29. sed -i "/ $(basename "$PACKAGE_FILE")$/d" "$PKGS_DB/installed.$SUM" 2>/dev/null
  30. cd "$(dirname "$PACKAGE_FILE")"
  31. $CHECKSUM "$(basename "$PACKAGE_FILE")">> "$PKGS_DB/installed.$SUM"
  32. install_all_deps "$PACKAGE_FILE"
  33. if [ -n "$cookmode" ]; then
  34. f=${PACKAGE_FILE%/*}; f=${f%/*}; f=${f##*/}
  35. if [ "$f" == "$(cat /etc/slitaz-release)" ]; then
  36. _ 'Installing (web/cache): %s' "$(basename $PACKAGE_FILE .tazpkg)"
  37. else
  38. _ 'Installing (pkg/local): %s' "$(basename $PACKAGE_FILE .tazpkg)"
  39. fi
  40. fi
  41. if [ -n "$sequence" ]; then
  42. title 'Installation of package "%s" (%s)' "$PACKAGE" "$sequence"
  43. else
  44. title 'Installation of package "%s"' "$PACKAGE"
  45. fi
  46. if [ -z "$quiet" ]; then
  47. print_short_description "$PACKAGE"
  48. separator '-'
  49. fi
  50. action 'Copying package...'
  51. cp "$PACKAGE_FILE" "$TMP_DIR"
  52. status
  53. cd "$TMP_DIR"
  54. extract_package "$(basename "$PACKAGE_FILE")"
  55. . "$TMP_DIR/receipt.var"
  56. cd "$INSTALLED"
  57. IFS=$'\n'
  58. if [ -f "$PACKAGE/files.list" ]; then
  59. while read file; do
  60. grep -q "^$(echo "$file" | grepesc)$" "$TMP_DIR/files.list" && continue
  61. for i in $(cat "$PACKAGE/modifiers" 2>/dev/null;
  62. fgrep -sl "$PACKAGE" */modifiers | cut -d/ -f1); do
  63. grep -qs "^$(echo "$file" | grepesc)$" "$i/files.list" && continue 2
  64. done
  65. echo "$file"
  66. done < "$PACKAGE/files.list"> "$TMP_DIR/files2remove.list"
  67. fi
  68. unset IFS
  69. action 'Remember modified packages...'
  70. {
  71. check=false
  72. for i in $(fgrep -v [ $TMP_DIR/files.list); do
  73. [ -e "$root$i" ] || continue
  74. [ -d "$root$i" ] && continue
  75. echo "- $i"
  76. check=true
  77. done ;
  78. $check && \
  79. for i in *; do
  80. [ "$i" == "$PACKAGE" ] && continue
  81. [ -s "$i/files.list" ] || continue
  82. awk "{ printf \"$i %s\\n\",\$1 }" < "$i/files.list"
  83. done;
  84. } | awk '
  85. {
  86. if ($1 == "-" || file[$2] != "") {
  87. file[$2] = file[$2] " " $1
  88. if ($1 != "-") {
  89. if (pkg[$1] == "") all = all " " $1
  90. pkg[$1] = pkg[$1] " " $2
  91. }
  92. }
  93. }
  94. END {
  95. for (i = split(all, p, " "); i > 0; i--)
  96. for (j = split(pkg[p[i]], f, " "); j > 0; j--)
  97. printf "%s %s\n",p[i],f[j];
  98. }
  99. ' | while read dir file; do
  100. if grep -qs "^$dir$" "$PACKAGE/modifiers"; then
  101. rm "$TMP_DIR/$file" 2>/dev/null
  102. continue
  103. fi
  104. grep -qs "^$PACKAGE$" "$dir/modifiers" && continue
  105. if [ -s "$dir/volatile.cpio.gz" ]; then
  106. zcat "$dir/volatile.cpio.gz" | cpio -t --quiet | \
  107. grep -q "^${file#/}$" && continue
  108. fi
  109. echo "$PACKAGE">> "$dir/modifiers"
  110. done
  111. status
  112. cd "$TMP_DIR"
  113. for file in receipt files.list description.txt $CHECKSUM; do
  114. [ -f "$file" ] && cp "$file" "$INSTALLED/$PACKAGE"
  115. done
  116. call_pre_install "$INSTALLED/$PACKAGE/receipt"
  117. if [ -n "$CONFIG_FILES" ]; then
  118. action 'Saving configuration files...'
  119. debug "\n"
  120. cd fs
  121. local config_file
  122. for config_file in $CONFIG_FILES; do
  123. debug "  config_file: '$config_file'"
  124. find ${config_file#/} -type f 2>/dev/null
  125. done | cpio -o -H newc --quiet | gzip -9 > "$INSTALLED/$PACKAGE/volatile.cpio.gz"
  126. cd ..
  127. if [ -z "$newconf" ]; then
  128. debug "  no '--newconf': clean official config files"
  129. for config_file in $CONFIG_FILES; do
  130. for config_file_official in $(find "fs$config_file" ! -type d 2>/dev/null | sed 's|^fs||'); do
  131. if [ -e "$root$config_file_official" ]; then
  132. debug "    official '$config_file_official' will be skipped"
  133. rm "fs$config_file_official"
  134. else
  135. debug "    official '$config_file_official' will be written"
  136. fi
  137. done
  138. done
  139. fi
  140. :; status
  141. fi
  142. if [ -n "$(ls fs/* 2>/dev/null)" ]; then
  143. action 'Installing package...'
  144. debug '\n  resolving destination links in source'
  145. IFS=$'\n'
  146. for dir in $(find fs -type d | sed 's|^fs||;/^$/d'); do
  147. if ldir=$(readlink -n $root$dir); then
  148. debug "  * mv 'fs$dir'\n    -> 'fs${dir%/*}/$ldir'"
  149. mkdir -p "fs${dir%/*}/${ldir%/*}"
  150. mv "fs$dir" "fs${dir%/*}/$ldir"
  151. fi
  152. done
  153. unset IFS
  154. debug '  copying folders and files to destination'
  155. cp -af fs/* "$root/"
  156. status
  157. fi
  158. if [ -s files2remove.list ]; then
  159. action 'Removing old files...'
  160. while read file; do
  161. dir="$root$file"
  162. rm -f "$dir"
  163. while [ "$dir" != "$root/" ]; do
  164. dir=$(dirname "$dir")
  165. rmdir "$dir" 2>/dev/null || break
  166. done
  167. done < files2remove.list
  168. :; status
  169. fi
  170. action "Removing all tmp files..."
  171. cd ..; rm -rf "$TMP_DIR"
  172. status
  173. call_post_install "$INSTALLED/$PACKAGE/receipt"
  174. local fl="$INSTALLED/$PACKAGE/files.list" upd=0 udesk umime uicon uschm ukrnl ukrnlfs
  175. fgrep    /usr/share/applications/    "$fl" | fgrep -q .desktop && udesk='yes'
  176. fgrep -q /usr/share/mime             "$fl" && umime='yes'
  177. fgrep -q /usr/share/icon/hicolor     "$fl" && uicon='yes'
  178. fgrep    /usr/share/glib-2.0/schemas "$fl" | fgrep -q .xml && uschm='yes'
  179. fgrep    /usr/lib/gdk-pixbuf         "$fl" | fgrep -q .so && upixb='yes'
  180. if fgrep -q /lib/modules             "$fl"; then
  181. ukrnl='yes'
  182. if fgrep -q /kernel/fs/ "$fl"; then
  183. ukrnlfs='yes'
  184. fi
  185. fi
  186. if [ -n "$udesk$umime$uicon$uschm$upixb$ukrnl" ]; then
  187. action 'Update system databases...'
  188. upd=1
  189. fi
  190. [ -n "$udesk" ] && chroot "$root/" /usr/bin/update-desktop-database /usr/share/applications 2>/dev/null
  191. [ -n "$umime" ] && chroot "$root/" /usr/bin/update-mime-database /usr/share/mime
  192. [ -n "$uicon" ] && chroot "$root/" /usr/bin/gtk-update-icon-cache /usr/share/icons/hicolor
  193. [ -n "$uschm" ] && chroot "$root/" /usr/bin/glib-compile-schemas /usr/share/glib-2.0/schemas 2>&1 | fgrep -v '/apps/'
  194. [ -n "$upixb" ] && chroot "$root/" /usr/bin/gdk-pixbuf-query-loaders --update-cache
  195. if [ -n "$ukrnlfs" ]; then
  196. for i in $(awk -F/ '{if($6=="fs" && $8~$7)print $7}' "$fl" | sort -u); do
  197. touch "$root/etc/filesystems"
  198. grep -q "^$i\$" "$root/etc/filesystems" || echo "$i">> "$root/etc/filesystems"
  199. done
  200. fi
  201. [ -n "$ukrnl" ] && grep '/lib/modules' "$fl" | cut -d'/' -f4 | uniq | xargs chroot "$root/" /sbin/depmod -a
  202. [ "$upd" -eq 1 ] && status
  203. SIZES=$(echo $PACKED_SIZE $UNPACKED_SIZE | sed 's|\.0||g')
  204. DEPENDS=$(echo $DEPENDS)
  205. PKG_SUM="$(fgrep " $PACKAGE-$VERSION$EXTRAVERSION.tazpkg" "$PKGS_DB/installed.$SUM" | cut -d' ' -f1)"
  206. ii="$PKGS_DB/installed.info"
  207. sed -i "/^$PACKAGE  /d" "$ii"
  208. cat >> "$ii" <<EOT
  209. $PACKAGE    $VERSION$EXTRAVERSION   $CATEGORY   $SHORT_DESC $WEB_SITE   $TAGS   $SIZES  $DEPENDS    $PKG_SUM
  210. EOT
  211. TEMP_FILE="$(mktemp)"
  212. sort "$ii"> "$TEMP_FILE"; mv -f "$TEMP_FILE" "$ii"; chmod a+r "$ii"; unset ii
  213. cd "$CUR_DIR"
  214. footer "$(_ 'Package "%s" (%s) is installed.' "$PACKAGE" "$VERSION$EXTRAVERSION")"
  215. log_pkg Installed
  216. [ -s "$UP_LIST" ] && sed -i "/^$PACKAGE\$/d" "$UP_LIST"
  217. }
Add Comment
Please, Sign In to add comment