Advertisement
Guest User

buddy

a guest
Mar 30th, 2020
897
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 36.79 KB | None | 0 0
  1.  
  2. #========================================================================
  3. #
  4. # PROGRAM FUNCTIONS
  5. #
  6.  
  7. # Clean-up tmp and lock files
  8. #
  9. function cleanup() {
  10. [ "$SPINNING" = "off" ] || tput cnorm
  11. if [ -e $TMPDIR/error.log ]; then
  12. echo -e "
  13. \n==============================================================================
  14. WARNING! WARNING! WARNING! WARNING! WARNING!
  15. ==============================================================================
  16. One or more errors occurred while slackpkg was running:
  17. "
  18. cat $TMPDIR/error.log
  19. echo -e "
  20. =============================================================================="
  21. fi
  22. echo
  23. if [ "$DELALL" = "on" ] && [ "$NAMEPKG" != "" ]; then
  24. rm $CACHEPATH/$NAMEPKG &>/dev/null
  25. fi
  26. ( rm -f /var/lock/slackpkg.$$ && rm -rf $TMPDIR ) &>/dev/null
  27. exit
  28. }
  29. trap 'cleanup' 2 14 15 # trap CTRL+C and kill
  30.  
  31. # This create an spinning bar
  32. spinning() {
  33. local WAITFILE
  34. local SPININTERVAL
  35. local COUNT
  36.  
  37. if [ "$SPIN" = "" ]; then
  38. SPIN=( "|" "/" "-" "\\" )
  39. fi
  40. COUNT=${#SPIN[@]}
  41.  
  42. [ -n "$1" ] && WAITFILE=$1 || WAITFILE=/tmp/waitfile
  43. [ -n "$2" ] && SPININTERVAL=$2 || SPININTERVAL=0.1
  44.  
  45. count=0
  46. tput civis
  47. while [ -e $WAITFILE ] ; do
  48. count=$(( count + 1 ))
  49. tput sc
  50. echo -n ${SPIN[$(( count % COUNT ))]}
  51. tput rc
  52. sleep $SPININTERVAL
  53. done
  54. tput cnorm
  55. }
  56.  
  57. # System setup
  58. #
  59. function system_setup() {
  60.  
  61. # Set LOCAL if mirror isn't through network
  62. # If mirror is through network, select the command to fetch
  63. # files and packages from there.
  64. #
  65. MEDIA=${SOURCE%%:*}
  66. if [ "$MEDIA" = "cdrom" ] || [ "$MEDIA" = "file" ] || \
  67. [ "$MEDIA" = "local" ]; then
  68. SOURCE=/${SOURCE#${MEDIA}://}
  69. LOCAL=1
  70. else
  71. LOCAL=0
  72. if [ "$DOWNLOADER" = "curl" ]; then
  73. DOWNLOADER="curl ${CURLFLAGS} -o"
  74. else
  75. DOWNLOADER="wget ${WGETFLAGS} -O"
  76. fi
  77. fi
  78.  
  79. # Set MORECMD, EDITCMD and check BATCH mode
  80. #
  81. if [ "$BATCH" = "on" ] || [ "$BATCH" = "ON" ]; then
  82. DIALOG=off
  83. SPINNING=off
  84. MORECMD=cat
  85. EDITCMD=vi
  86. if [ "$DEFAULT_ANSWER" = "" ]; then
  87. DEFAULT_ANSWER=n
  88. fi
  89. else
  90. if [ "${PAGER}" ]; then
  91. MORECMD="${PAGER}"
  92. else
  93. MORECMD=more
  94. fi
  95. if [ "${EDITOR}" ]; then
  96. EDITCMD="${EDITOR}"
  97. else
  98. EDITCMD=vi
  99. fi
  100. fi
  101.  
  102. # Set ARCH, SLACKKEY and others by slackware port
  103. #
  104. if [ "$ARCH" = "" ]; then
  105. ARCH=$(uname -m)
  106. fi
  107. case $ARCH in
  108. i386|i486|i586|i686)
  109. ARCH=[i]*[3456x]86[^_]*
  110. SLACKKEY=${SLACKKEY:-"Slackware Linux Project <security@slackware.com>"}
  111. PKGMAIN=${PKGMAIN:-slackware}
  112. ;;
  113. x86-64|x86_64|X86-64|X86_64)
  114. ARCH=x86[_64]*
  115. SLACKKEY=${SLACKKEY:-"Slackware Linux Project <security@slackware.com>"}
  116. PKGMAIN=${PKGMAIN:-slackware64}
  117. ;;
  118. s390)
  119. ARCH=s390
  120. # Slack390 didn't have signed packages
  121. CHECKGPG=off
  122. PKGMAIN=${PKGMAIN:-slackware}
  123. ;;
  124. arm*)
  125. ARCH=arm[v5tel]*
  126. SLACKKEY=${SLACKKEY:-"ARMedslack Security (ARMedslack Linux Project Security) <security@armedslack.org>"}
  127. PKGMAIN=${PKGMAIN:-slackware}
  128. ;;
  129. powerpc|ppc)
  130. ARCH=powerpc
  131. SLACKKEY=${SLACKKEY:-"Slackintosh-Project Sign <slackdev@workaround.ch>"}
  132. PKGMAIN=${PKGMAIN:-slackintosh}
  133. ;;
  134. *)
  135. ARCH=none
  136. ;;
  137. esac
  138.  
  139. # Sub %PKGMAIN with the correct $PKGMAIN value
  140. #
  141. MAIN=$PKGMAIN
  142. for i in 0 1 2 3 4 ; do
  143. if [ "${PRIORITY[$i]}" = "%PKGMAIN" ]; then
  144. PRIORITY[$i]=$PKGMAIN
  145. fi
  146. done
  147.  
  148. TEMPLATEDIR=$CONF/templates
  149. if [ ! -d $TEMPLATEDIR ]; then
  150. mkdir $TEMPLATEDIR
  151. fi
  152.  
  153. SLACKCFVERSION=$(grep "# v[0-9.]\+" $CONF/slackpkg.conf | cut -f2 -dv)
  154. CHECKSUMSFILE=$WORKDIR/CHECKSUMS.md5
  155. KERNELMD5=$(md5sum /boot/vmlinuz 2>/dev/null)
  156. DIALOG_MAXARGS=${DIALOG_MAXARGS:-19500}
  157. echo "$0 $VERSION - Slackware Linux $SLACKWARE_VERSION" > $TMPDIR/timestamp
  158. }
  159.  
  160. # Syntax Checking
  161. #
  162. function system_checkup() {
  163.  
  164. # Check slackpkg.conf version
  165. #
  166. SLCKCFVL=$( expr length $SLACKCFVERSION )
  167. if [ "$SLACKCFVERSION" != "$( echo $VERSION |cut -c1-$SLCKCFVL)" ] &&\
  168. [ "$CMD" != "new-config" ]; then
  169. echo -e "\
  170. \nYour slackpkg.conf is outdated. Please, edit it using slackpkg.conf.new\n\
  171. as example or overwrite it with slackpkg.conf.new.\n\
  172. \nYou can use 'slackpkg new-config' to do that.\n"
  173. cleanup
  174. fi
  175.  
  176. # Check if ARCH is set
  177. #
  178. if [ "$ARCH" = "none" ] && [ "$CMD" != "new-config" ]; then
  179. echo -e "\
  180. \nThe ARCH values in slackpkg.conf are now different. You can remove\n\
  181. ARCH from there, and slackpkg you use your current ARCH or you can look\n\
  182. at slackpkg.conf.new or slackpkg.conf manual page to see the new valid\n\
  183. ARCH values\n"
  184. cleanup
  185. fi
  186.  
  187. # Check if the config files are updated to the new slackpkg version
  188. #
  189. if [ "$WORKDIR" = "" ]; then
  190. echo -e "\
  191. \nYou need to upgrade your slackpkg.conf.\n\
  192. This is a new slackpkg version and many changes happened in config files.\n\
  193. In ${CONF}/slackpkg.conf.new, there is a sample of the new configuration.\n\
  194. \nAfter updating your configuration file, run: slackpkg update\n"
  195. cleanup
  196. fi
  197.  
  198. # Checking if another instance of slackpkg is running
  199. #
  200. if [ "$(ls /var/lock/slackpkg.* 2>/dev/null)" ] && \
  201. [ "$CMD" != "search" ] && \
  202. [ "$CMD" != "help" ] && \
  203. [ "$CMD" != "file-search" ]; then
  204. echo -e "\
  205. \nAnother instance of slackpkg is running. If this is not correct, you can\n\
  206. remove /var/lock/slackpkg.* files and run slackpkg again.\n"
  207. cleanup
  208. else
  209. ls /var/lock/slackpkg.* &>/dev/null || \
  210. touch /var/lock/slackpkg.$$
  211. fi
  212.  
  213. # Checking if the we can create TMPDIR
  214. #
  215. if [ "$TMPDIR" = "FAILED" ]; then
  216. echo -e "\
  217. \nA problem was encountered writing to slackpkg's temporary dir in /tmp.\n\
  218. Check to ensure you have permissions to write in /tmp and make sure the\n\
  219. filesystem is not out of free space. Run slackpkg again after correcting\n\
  220. the problem.\n"
  221. cleanup
  222. fi
  223.  
  224. # Checking if is the first time running slackpkg
  225. #
  226. if ! [ -f ${WORKDIR}/pkglist ] && [ "$CMD" != "update" ]; then
  227. if [ "$SOURCE" = "" ]; then
  228. echo -e "\
  229. \nThis appears to be the first time you have run slackpkg.\n\
  230. Before you install|upgrade|reinstall anything, you need to uncomment\n\
  231. ONE mirror in ${CONF}/mirrors and run:\n\n\
  232. \t# slackpkg update\n\n\
  233. You can see more information about slackpkg functions in slackpkg manpage."
  234. cleanup
  235. elif [ "$CMD" != "new-config" ]; then
  236. echo -e "\
  237. \nThe package list is missing.\n\
  238. Before you install|upgrade|reinstall anything you need to run:\n\n\
  239. \t# slackpkg update\n"
  240. cleanup
  241. fi
  242. fi
  243.  
  244.  
  245. # Checking if /etc/slackpkg/mirrors are in correct syntax.
  246. #
  247. if [ "$SOURCE" = "" ] ; then
  248. echo -e "\
  249. \nYou do not have any mirror selected in ${CONF}/mirrors\n\
  250. Please edit that file and uncomment ONE mirror. Slackpkg\n\
  251. only works with ONE mirror selected.\n"
  252. cleanup
  253. else
  254. COUNT=$(echo $SOURCE | wc -w | tr -d " ")
  255. if [ "$COUNT" != "1" ]; then
  256. echo -e "\n\
  257. Slackpkg only works with ONE mirror selected. Please edit your\n\
  258. ${CONF}/mirrors and comment all but one line - two or more\n\
  259. mirrors uncommented is not valid syntax.\n"
  260. cleanup
  261. fi
  262. fi
  263.  
  264. # It will check if the mirror selected are ftp.slackware.com
  265. # if set to "ftp.slackware.com" tell the user to choose another
  266. #
  267. if echo ${SOURCE} | grep "^ftp://ftp.slackware.com" &>/dev/null ; then
  268. echo -e "\n\
  269. Please use one of the mirrors.\n\
  270. ftp.slackware.com should be reserved so that the\n\
  271. official mirrors can be kept up-to-date.\n"
  272. cleanup
  273. fi
  274.  
  275. # Checking if the user has the permissions to install/upgrade/update
  276. #
  277. if [ "$(id -u)" != "0" ] && \
  278. [ "$CMD" != "search" ] && \
  279. [ "$CMD" != "file-search" ] && \
  280. [ "$CMD" != "check-updates" ] && \
  281. [ "$CMD" != "info" ]; then
  282. echo -e "\n\
  283. Only root can install, upgrade, or remove packages.\n\
  284. Please log in as root or contact your system administrator.\n"
  285. cleanup
  286. fi
  287.  
  288. # Check if the "which" command is there
  289. if ! which which 1>/dev/null 2>/dev/null ; then
  290. echo -e "\n\
  291. No 'which' command found, please install it if you want to\n\
  292. use slackpkg.\n"
  293. cleanup
  294. fi
  295.  
  296. # Check if we have md5sum in the PATH. Without md5sum, disables
  297. # md5sum checks
  298. #
  299. if ! [ $(which md5sum 2>/dev/null) ]; then
  300. CHECKMD5=off
  301. elif ! [ -f ${WORKDIR}/CHECKSUMS.md5 ] && \
  302. [ "$CMD" != "update" ] && \
  303. [ "$CHECKMD5" = "on" ]; then
  304. echo -e "\n\
  305. No CHECKSUMS.md5 found! Please disable md5sums checking\n\
  306. on your ${CONF}/slackpkg.conf or run slackpkg update\n\
  307. to download a new CHECKSUMS.md5 file.\n"
  308. cleanup
  309. fi
  310.  
  311. # Check if awk is installed
  312. #
  313. if ! [ "$(which awk 2>/dev/null)" ]; then
  314. echo -e "\n\
  315. awk package not found! Please install awk before you run slackpkg,\n\
  316. as slackpkg cannot function without awk.\n"
  317. cleanup
  318. fi
  319.  
  320. # Check if tput is there
  321. #
  322. if ! which tput 1>/dev/null 2>/dev/null ; then
  323. SPINNING=off
  324. fi
  325.  
  326. # Check if gpg is enabled but no GPG command are found.
  327. #
  328. if ! [ "$(which gpg 2>/dev/null)" ] && [ "${CHECKGPG}" = "on" ]; then
  329. CHECKGPG=off
  330. echo -e "\n\
  331. gpg package not found! Please disable GPG in ${CONF}/slackpkg.conf or install\n\
  332. the gnupg package.\n\n\
  333. To disable GPG, edit slackpkg.conf and change the value of the CHECKGPG \n\
  334. variable to "off" - you can see an example in the original slackpkg.conf.new\n\
  335. file distributed with slackpkg.\n"
  336. sleep 5
  337. fi
  338.  
  339. # Check if the Slackware GPG key are found in the system
  340. #
  341. GPGFIRSTTIME="$(gpg --list-keys \"$SLACKKEY\" 2>/dev/null \
  342. | grep -c "$SLACKKEY")"
  343. if [ "$GPGFIRSTTIME" = "0" ] && \
  344. [ "$CMD" != "search" ] && \
  345. [ "$CMD" != "file-search" ] && \
  346. [ "$CMD" != "info" ] && \
  347. [ "$CMD" != "new-config" ] && \
  348. [ "$CMD" != "update" ] && \
  349. [ "$CMD" != "check-updates" ] && \
  350. [ "$CHECKGPG" = "on" ]; then
  351. echo -e "\n\
  352. You need the GPG key of $SLACKKEY.\n\
  353. To download and install that key, run:\n\n\
  354. \t# slackpkg update gpg\n\n\
  355. You can disable GPG checking too, but it is not a good idea.\n\
  356. To disable GPG, edit slackpkg.conf and change the value of the CHECKGPG\n\
  357. variable to "off" - you can see an example in the original slackpkg.conf.new\n\
  358. file distributed with slackpkg.\n"
  359. cleanup
  360. fi
  361. echo
  362. }
  363.  
  364. # Got the name of a package, without version-arch-release data
  365. #
  366. function cutpkg() {
  367. echo ${1/%.t[blxg]z/} | awk -F- -f /usr/libexec/slackpkg/cutpkg.awk
  368. }
  369.  
  370. # The same, but reading packages from stdin
  371. #
  372. function batchcutpkg() {
  373. awk -F- -f /usr/libexec/slackpkg/cutpkg.awk
  374. }
  375.  
  376. # Show the slackpkg usage
  377. #
  378. function usage() {
  379. echo -e "\
  380. slackpkg - version $VERSION\n\
  381. \nUsage:\n\
  382. \tslackpkg [OPTIONS] {install|remove|search|file-search|
  383. \t\t\t upgrade|reinstall|blacklist} {PATTERN|FILE}
  384. \tslackpkg [OPTIONS] {generate-template|install-template|remove-template}
  385. \t\t\t TEMPLATENAME
  386. \tslackpkg [OPTIONS] info PACKAGE
  387. \tslackpkg [OPTIONS] update [gpg]
  388. \tslackpkg [OPTIONS] {clean-system|upgrade-all|install-new}
  389. \tslackpkg [OPTIONS] {new-config|check-updates|help}
  390. \nIf you need more information try to use 'slackpkg help' or look the\n\
  391. slackpkg's manpage.
  392. "
  393. cleanup
  394. }
  395.  
  396. function full_usage() {
  397. echo -e "\
  398. slackpkg - version $VERSION\n\
  399. \nUsage: \tslackpkg update [gpg]\t\tdownload and update files and
  400. \t\t\t\t\tpackage indexes
  401. \tslackpkg check-updates\t\tcheck if there is any news on
  402. \t\t\t\t\tSlackware's ChangeLog.txt
  403. \tslackpkg install package\tdownload and install packages
  404. \tslackpkg upgrade package\tdownload and upgrade packages
  405. \tslackpkg reinstall package\tsame as install, but for packages
  406. \t\t\t\t\talready installed
  407. \tslackpkg remove package\t\tremove installed packages
  408. \tslackpkg clean-system\t\tremove all packages which are not
  409. \t\t\t\t\tpresent in the official Slackware
  410. \t\t\t\t\tpackage set. Good to keep the house
  411. \t\t\t\t\tin order
  412. \tslackpkg upgrade-all\t\tsync all packages installed in your
  413. \t\t\t\t\tmachine with the selected mirror. This
  414. \t\t\t\t\tis the "correct" way to upgrade all of
  415. \t\t\t\t\tyour machine.
  416. \tslackpkg install-new\t\tinstall packages which are added to
  417. \t\t\t\t\tthe official Slackware package set.
  418. \t\t\t\t\tRun this if you are upgrading to another
  419. \t\t\t\t\tSlackware version or using "current".
  420. \tslackpkg blacklist\t\tBlacklist a package. Blacklisted
  421. \t\t\t\t\tpackages cannot be upgraded, installed,
  422. \t\t\t\t\tor reinstalled by slackpkg
  423. \tslackpkg download\t\tOnly download (do not install) a package
  424. \tslackpkg info package\t\tShow package information
  425. \t\t\t\t\t(works with only ONE package)
  426. \tslackpkg search package\t\tSearch packages that have a
  427. \t\t\t\t\tselected name
  428. \tslackpkg file-search file\tSearch for a specific file in the
  429. \t\t\t\t\tentire package collection
  430. \tslackpkg new-config\t\tSearch for new configuration files and
  431. \t\t\t\t\task to user what to do with them.
  432. \tslackpkg generate-template\tCreate a template with all
  433. \t\t\t\t\tofficial Slackware packages installed
  434. \t\t\t\t\tin your machine.
  435. \tslackpkg install-template\tInstall selected template.
  436. \tslackpkg remove-template\tRemove selected template. Be careful.
  437. \tslackpkg help\t\t\tShow this screen.
  438. \nYou can see more information about slackpkg usage and some examples
  439. in slackpkg's manpage. You can use partial package names (such as xorg
  440. instead of xorg-server, xorg-docs, etc), or even Slackware series
  441. (such as "n","ap","xap",etc) when searching for packages.
  442. "
  443. cleanup
  444. }
  445.  
  446. # Verify if we have enough disk space to install selected package
  447. #
  448. function havespace() {
  449. local DSIZE
  450. local ASIZE
  451. DSIZE=$(grep "^${1}" ${TMPDIR}/tempsize | \
  452. awk 'BEGIN { tot=0 } { tot+=$2 } END { print int(tot/1024)+1}')
  453. ASIZE=$(df ${1} | awk '/% \// { print 0+$(NF-2) }')
  454. if [ ${DSIZE} -gt ${ASIZE} ] ; then
  455. ISOK=0
  456. fi
  457. }
  458.  
  459. function checksize() {
  460. local i
  461. local ISOK=1
  462. tar -tvf ${1} | tr -s ' ' | grep -v '^[dl]' | cut -f6,3 -d\ | \
  463. sed 's,[^/]*$,,' | awk '
  464. { size[$2]+=$1 }
  465. END {
  466. for (i in size) {
  467. print "/"i,size[i]
  468. }
  469. }' > ${TMPDIR}/tempsize
  470.  
  471. for i in $(tac /proc/mounts | grep "^/dev" |cut -f2 -d\ ); do
  472. if grep -q "^${i}" ${TMPDIR}/tempsize ; then
  473. havespace ${i}
  474. grep -v "^${i}/" ${TMPDIR}/tempsize > ${TMPDIR}/tempsize.tmp
  475. mv ${TMPDIR}/tempsize.tmp ${TMPDIR}/tempsize
  476. fi
  477. done
  478. echo ${ISOK}
  479. }
  480.  
  481. # Verify if the package was corrupted by checking md5sum
  482. #
  483. function checkmd5() {
  484. local MD5ORIGINAL
  485. local MD5DOWNLOAD
  486.  
  487. MD5ORIGINAL=$( grep -v "/source/" ${CHECKSUMSFILE} |\
  488. grep -m1 "/$(basename $1)$" | cut -f1 -d \ )
  489. MD5DOWNLOAD=$(md5sum ${1} | cut -f1 -d \ )
  490. if [ "$MD5ORIGINAL" = "$MD5DOWNLOAD" ]; then
  491. echo 1
  492. else
  493. echo 0
  494. fi
  495. }
  496.  
  497. # Verify the GPG signature of files/packages
  498. #
  499. function checkgpg() {
  500. gpg --verify ${1}.asc ${1} 2>/dev/null && echo "1" || echo "0"
  501. }
  502.  
  503. # Found packages in repository.
  504. # This function selects the package from the higher priority
  505. # repository directories.
  506. #
  507. function givepriority {
  508. local DIR
  509. local ARGUMENT=$1
  510. local PKGDATA
  511.  
  512. unset NAME
  513. unset FULLNAME
  514. unset PKGDATA
  515.  
  516. for DIR in ${PRIORITY[@]} ; do
  517. [ "$PKGDATA" ] && break
  518. PKGDATA=( $(grep "^${DIR} ${ARGUMENT} " ${TMPDIR}/pkglist) )
  519. if [ "$PKGDATA" ]; then
  520. NAME=${PKGDATA[1]}
  521. FULLNAME=$(echo "${PKGDATA[5]}.${PKGDATA[7]}")
  522. fi
  523. done
  524. }
  525.  
  526. # Creates files with mirror package names (spkg), local package
  527. # names (lpkg) and packages unique to one or other file (dpkg)
  528. #
  529. function listpkgname() {
  530. cut -f2 -d\ ${TMPDIR}/pkglist | sort > ${TMPDIR}/spkg
  531. cut -f2 -d\ ${TMPDIR}/tmplist | sort > ${TMPDIR}/lpkg
  532. cat ${TMPDIR}/pkglist ${TMPDIR}/tmplist | \
  533. cut -f2-6 -d\ |sort | uniq -u | \
  534. cut -f1 -d\ | uniq > ${TMPDIR}/dpkg
  535. }
  536.  
  537. function applyblacklist() {
  538. grep -vEw -f ${TMPDIR}/blacklist
  539. }
  540.  
  541. # Function to make install/reinstall/upgrade lists
  542. #
  543. function makelist() {
  544. local ARGUMENT
  545. local i
  546. local VRFY
  547.  
  548. INPUTLIST=$@
  549.  
  550. grep -vE "(^#|^[[:blank:]]*$)" ${CONF}/blacklist > ${TMPDIR}/blacklist
  551. if echo $CMD | grep -q install ; then
  552. ls -1 /var/log/packages/* | awk -f /usr/libexec/slackpkg/pkglist.awk > ${TMPDIR}/tmplist
  553. else
  554. ls -1 /var/log/packages/* | awk -f /usr/libexec/slackpkg/pkglist.awk | applyblacklist > ${TMPDIR}/tmplist
  555. fi
  556. cat ${WORKDIR}/pkglist | applyblacklist > ${TMPDIR}/pkglist
  557.  
  558. touch ${TMPDIR}/waiting
  559.  
  560. case "$CMD" in
  561. clean-system)
  562. echo -n "Looking for packages to remove. Please wait... "
  563. ;;
  564. upgrade-all)
  565. echo -n "Looking for packages to upgrade. Please wait... "
  566. ;;
  567. install-new)
  568. echo -n "Looking for NEW packages to install. Please wait... "
  569. ;;
  570. *-template)
  571. echo -n "Looking for packages in \"$ARG\" template to ${CMD/%-template/}. Please wait..."
  572. ;;
  573. *)
  574. echo -n "Looking for $(echo $INPUTLIST | tr -d '\\') in package list. Please wait... "
  575. ;;
  576. esac
  577.  
  578. [ "$SPINNING" = "off" ] || spinning ${TMPDIR}/waiting &
  579.  
  580. case "$CMD" in
  581. download)
  582. for ARGUMENT in $(echo $INPUTLIST); do
  583. for i in $(grep -w -- "${ARGUMENT}" ${TMPDIR}/pkglist | cut -f2 -d\ | sort -u); do
  584. LIST="$LIST $(grep " ${i} " ${TMPDIR}/pkglist | cut -f6,8 -d\ --output-delimiter=.)"
  585. done
  586. LIST="$(echo -e $LIST | sort -u)"
  587. done
  588. ;;
  589. blacklist)
  590. for ARGUMENT in $(echo $INPUTLIST); do
  591. for i in $(cat ${TMPDIR}/pkglist ${TMPDIR}/tmplist | \
  592. grep -w -- "${ARGUMENT}" | cut -f2 -d\ | sort -u); do
  593. grep -qx "${i}" ${CONF}/blacklist || LIST="$LIST $i"
  594. done
  595. done
  596. ;;
  597. install|upgrade|reinstall)
  598. for ARGUMENT in $(echo $INPUTLIST); do
  599. for i in $(grep -w -- "${ARGUMENT}" ${TMPDIR}/pkglist | cut -f2 -d\ | sort -u); do
  600. givepriority $i
  601. [ ! "$FULLNAME" ] && continue
  602.  
  603. case $CMD in
  604. 'upgrade')
  605. VRFY=$(cut -f6 -d\ ${TMPDIR}/tmplist | \
  606. grep -x "${NAME}-[^-]\+-\(noarch\|fw\|${ARCH}\)-[^-]\+")
  607. [ "${FULLNAME/%.t[blxg]z/}" != "${VRFY}" ] && \
  608. [ "${VRFY}" ] && \
  609. LIST="$LIST ${FULLNAME}"
  610. ;;
  611. 'install')
  612. grep -q " ${NAME} " ${TMPDIR}/tmplist || \
  613. LIST="$LIST ${FULLNAME}"
  614. ;;
  615. 'reinstall')
  616. grep -q " ${FULLNAME/%.t[blxg]z} " ${TMPDIR}/tmplist && \
  617. LIST="$LIST ${FULLNAME}"
  618. ;;
  619. esac
  620. done
  621. done
  622. ;;
  623. remove)
  624. for ARGUMENT in $(echo $INPUTLIST); do
  625. for i in $(cat ${TMPDIR}/pkglist ${TMPDIR}/tmplist | \
  626. grep -w -- "${ARGUMENT}" | cut -f6 -d\ | sort -u); do
  627. PKGDATA=( $(grep -w -- "$i" ${TMPDIR}/tmplist) )
  628. [ ! "$PKGDATA" ] && continue
  629. LIST="$LIST ${PKGDATA[5]}"
  630. unset PKGDATA
  631. done
  632. done
  633. ;;
  634. clean-system)
  635. listpkgname
  636. for i in $(comm -2 -3 ${TMPDIR}/lpkg ${TMPDIR}/spkg) ; do
  637. PKGDATA=( $(grep -- "^local $i " ${TMPDIR}/tmplist) )
  638. [ ! "$PKGDATA" ] && continue
  639. LIST="$LIST ${PKGDATA[5]}"
  640. unset PKGDATA
  641. done
  642. ;;
  643. upgrade-all)
  644. listpkgname
  645. for i in $(comm -1 -2 ${TMPDIR}/lpkg ${TMPDIR}/dpkg | \
  646. comm -1 -2 - ${TMPDIR}/spkg) ; do
  647.  
  648. givepriority ${i}
  649. [ ! "$FULLNAME" ] && continue
  650.  
  651. VRFY=$(cut -f6 -d\ ${TMPDIR}/tmplist | grep -x "${NAME}-[^-]\+-\(noarch\|fw\|${ARCH}\)-[^-]\+")
  652. [ "${FULLNAME/%.t[blxg]z}" != "${VRFY}" ] && \
  653. [ "${VRFY}" ] && \
  654. LIST="$LIST ${FULLNAME}"
  655. done
  656. ;;
  657. install-new)
  658. for i in $(awk -f /usr/libexec/slackpkg/install-new.awk ${WORKDIR}/ChangeLog.txt |\
  659. sort -u ) dialog aaa_terminfo fontconfig \
  660. ntfs-3g ghostscript wqy-zenhei-font-ttf \
  661. xbacklight xf86-video-geode ; do
  662.  
  663. givepriority $i
  664. [ ! "$FULLNAME" ] && continue
  665.  
  666. grep -q " ${NAME} " ${TMPDIR}/tmplist || \
  667. LIST="$LIST ${FULLNAME}"
  668. done
  669. ;;
  670. install-template)
  671. for i in $INPUTLIST ; do
  672. givepriority $i
  673. [ ! "$FULLNAME" ] && continue
  674. grep -q " ${NAME} " ${TMPDIR}/tmplist || \
  675. LIST="$LIST ${FULLNAME}"
  676. done
  677. ;;
  678. remove-template)
  679. for i in $INPUTLIST ; do
  680. givepriority $i
  681. [ ! "$FULLNAME" ] && continue
  682. grep -q " ${NAME} " ${TMPDIR}/tmplist && \
  683. LIST="$LIST ${FULLNAME}"
  684. done
  685. ;;
  686. search|file-search)
  687. # -- temporary file used to store the basename of selected
  688. # packages.
  689.  
  690. PKGNAMELIST=$(tempfile --directory=$TMPDIR)
  691.  
  692. if [ "$CMD" = "file-search" ]; then
  693. # Search filelist.gz for possible matches
  694. for i in ${PRIORITY[@]}; do
  695. if [ -e ${WORKDIR}/${i}-filelist.gz ]; then
  696. PKGS="$(zegrep -w "${INPUTLIST}" ${WORKDIR}/${i}-filelist.gz | \
  697. cut -d\ -f 1 | awk -F'/' '{print $NF}')"
  698. for FULLNAME in $PKGS ; do
  699. NAME=$(cutpkg ${FULLNAME})
  700. grep -q "^${NAME}$" $PKGNAMELIST && continue
  701. LIST="$LIST ${FULLNAME}"
  702. echo "$NAME" >> $PKGNAMELIST
  703. done
  704. fi
  705. done
  706. else
  707. for i in ${PRIORITY[@]}; do
  708. PKGS=$(grep "^${i}.*${PATTERN}" \
  709. ${TMPDIR}/pkglist | cut -f6 -d\ )
  710. for FULLNAME in $PKGS ; do
  711. NAME=$(cutpkg ${FULLNAME})
  712.  
  713. grep -q "^${NAME}$" $PKGNAMELIST && continue
  714. LIST="$LIST ${FULLNAME}"
  715. echo "$NAME" >> $PKGNAMELIST
  716. done
  717. done
  718. fi
  719. rm -f $PKGNAMELIST
  720. ;;
  721. esac
  722. LIST=$(echo -e $LIST | tr \ "\n" | uniq )
  723.  
  724. rm ${TMPDIR}/waiting
  725.  
  726. echo -e "DONE\n"
  727. }
  728.  
  729. # Function to count total of packages
  730. #
  731. function countpkg() {
  732. local COUNTPKG=$(echo -e "$1" | wc -w)
  733.  
  734. if [ "$COUNTPKG" != "0" ]; then
  735. echo -e "Total package(s): $COUNTPKG\n"
  736. fi
  737. }
  738.  
  739. function answer() {
  740. if [ "$BATCH" = "on" ]; then
  741. ANSWER="$DEFAULT_ANSWER"
  742. echo $DEFAULT_ANSWER
  743. else
  744. read ANSWER
  745. fi
  746. }
  747.  
  748. function searchlist() {
  749. local i
  750. local BASENAME
  751. local RAWNAME
  752. local STATUS
  753. local INSTPKG
  754.  
  755. for i in $1; do
  756. if [ "$BASENAME" = "$(cutpkg ${i})" ]; then
  757. continue
  758. fi
  759. # BASENAME is base package name
  760. BASENAME="$(cutpkg ${i})"
  761.  
  762. # RAWNAME is Latest available version
  763. RAWNAME="${i/%.t[blxg]z/}"
  764.  
  765. # Default is uninstalled
  766. STATUS="uninstalled"
  767.  
  768. # First is the package already installed?
  769. # Amazing what a little sleep will do
  770. # exclusion is so much nicer :)
  771. INSTPKG=$(ls -1 /var/log/packages | \
  772. grep -e "^${BASENAME}-[^-]\+-\(${ARCH}\|fw\|noarch\)-[^-]\+")
  773.  
  774. # INSTPKG is local version
  775. if [ ! "${INSTPKG}" = "" ]; then
  776.  
  777. # If installed is it uptodate?
  778. if [ "${INSTPKG}" = "${RAWNAME}" ]; then
  779. STATUS=" installed "
  780. echo "[${STATUS}] - ${INSTPKG}"
  781. else
  782. STATUS=" upgrade "
  783. echo "[${STATUS}] - ${INSTPKG} --> ${RAWNAME}"
  784. fi
  785. else
  786. echo "[${STATUS}] - ${RAWNAME}"
  787. fi
  788. done
  789. }
  790.  
  791. # Show the lists and asks if the user want to proceed with that action
  792. # Return accepted list in $SHOWLIST
  793. #
  794. function showlist() {
  795. local ANSWER
  796. local i
  797.  
  798. for i in $1; do echo $i; done | $MORECMD
  799. echo
  800. countpkg "$1"
  801. echo -e "Do you wish to $2 selected packages (Y/n)? \c"
  802. answer
  803. if [ "$ANSWER" = "N" -o "$ANSWER" = "n" ]; then
  804. cleanup
  805. else
  806. SHOWLIST="$1"
  807. continue
  808. fi
  809. }
  810.  
  811. function getfile() {
  812. if [ "$LOCAL" = "1" ]; then
  813. echo -e "\t\t\tLinking $1..."
  814. if [ -e $1 ]; then
  815. ln -s $1 $2 2>/dev/null
  816. else
  817. return 1
  818. fi
  819. else
  820. echo -e "\t\t\tDownloading $1..."
  821. $DOWNLOADER $2 $1
  822. fi
  823. }
  824.  
  825. # Function to download the correct package and many "checks"
  826. #
  827. function getpkg() {
  828. local ISOK="1"
  829. local ERROR=""
  830. local PKGNAME
  831. local FULLPATH
  832. local NAMEPKG
  833. local CACHEPATH
  834.  
  835. PKGNAME=( $(grep -w -m 1 -- "${1/%.t[blxg]z/}" ${TMPDIR}/pkglist) )
  836. NAMEPKG=${PKGNAME[5]}.${PKGNAME[7]}
  837. FULLPATH=${PKGNAME[6]}
  838. CACHEPATH=${TEMP}/${FULLPATH}
  839.  
  840. # Create destination dir if it isn't there
  841. if ! [ -d $CACHEPATH ]; then
  842. mkdir -p $CACHEPATH
  843. fi
  844.  
  845. if ! [ -e ${CACHEPATH}/${NAMEPKG} ]; then
  846. echo -e "\nPackage: $1"
  847. # Check if the mirror are local, if is local, copy files
  848. # to CACHEPATH else, download packages from remote host and
  849. # put then in CACHEPATH
  850. #
  851. getfile ${SOURCE}${FULLPATH}/${NAMEPKG} \
  852. ${CACHEPATH}/${NAMEPKG}
  853. if [ "$CHECKGPG" = "on" ]; then
  854. getfile ${SOURCE}${FULLPATH}/${NAMEPKG}.asc \
  855. ${CACHEPATH}/${NAMEPKG}.asc
  856. fi
  857.  
  858. if ! [ -e ${CACHEPATH}/$1 ]; then
  859. ERROR="Not found"
  860. ISOK="0"
  861. echo -e "${NAMEPKG}:\t$ERROR" >> $TMPDIR/error.log
  862. fi
  863. else
  864. echo -e "\tPackage $1 is already in cache - not downloading"
  865. fi
  866.  
  867. # Check if we have sufficient disk space to install selected package
  868. if [ "$CHECKSIZE" = "on" ] && [ "$ISOK" = "1" ]; then
  869. ISOK=$(checksize ${CACHEPATH}/$1)
  870. if [ "$ISOK" = "0" ]; then
  871. ERROR="Insufficient disk space"
  872. echo -e "${NAMEPKG}:\t$ERROR" >> $TMPDIR/error.log
  873. fi
  874. fi
  875.  
  876. # If MD5SUM checks are enabled in slackpkg.conf, check the
  877. # packages md5sum to detect if they are corrupt or not
  878. #
  879. if [ "$CHECKMD5" = "on" ] && [ "$ISOK" = "1" ]; then
  880. ISOK=$(checkmd5 ${CACHEPATH}/$1)
  881. if [ "$ISOK" = "0" ]; then
  882. ERROR="md5sum"
  883. echo -e "${NAMEPKG}:\t$ERROR" >> $TMPDIR/error.log
  884. fi
  885. if [ "$CHECKGPG" = "on" ] && [ "$ISOK" = "1" ]; then
  886. ISOK=$(checkmd5 ${CACHEPATH}/$1.asc)
  887. if [ "$ISOK" = "0" ]; then
  888. ERROR="md5sum"
  889. echo -e "${NAMEPKG}.asc:\t$ERROR" >> \
  890. $TMPDIR/error.log
  891. fi
  892. fi
  893. fi
  894.  
  895. # Check the package against its .asc. If you don't like this
  896. # disable GPG checking in /etc/slackpkg/slackpkg.conf
  897. #
  898. if [ "$CHECKGPG" = "on" ] && [ "$ISOK" = "1" ]; then
  899. ISOK=$(checkgpg ${CACHEPATH}/$1)
  900. if [ "$ISOK" = "0" ]; then
  901. ERROR="gpg"
  902. echo -e "${NAMEPKG}:\t$ERROR" >> $TMPDIR/error.log
  903. fi
  904. fi
  905.  
  906. if [ "$ISOK" = "1" ]; then
  907. case $2 in
  908. installpkg)
  909. echo -e "\tInstalling ${1/%.t[blxg]z/}..."
  910. ;;
  911. upgradepkg)
  912. echo -e "\tUpgrading ${1/%.t[blxg]z/}..."
  913. ;;
  914. *)
  915. echo -e "\c"
  916. ;;
  917. esac
  918. ( cd $CACHEPATH && $2 $1 )
  919. else
  920. rm $CACHEPATH/$1 2>/dev/null
  921. echo -e "\tERROR - Package not installed! $ERROR error!"
  922. fi
  923.  
  924. # If DELALL is checked, all downloaded files will be erased
  925. # after installed/upgraded/reinstalled
  926. #
  927. if [ "$DELALL" = "on" ]; then
  928. rm $CACHEPATH/$1 $CACHEPATH/${1}.asc 2>/dev/null
  929. fi
  930. }
  931.  
  932. # Main logic to download and format package list, md5 etc.
  933. #
  934. function checkchangelog()
  935. {
  936. if ! [ -e ${WORKDIR}/ChangeLog.txt ]; then
  937. touch ${WORKDIR}/ChangeLog.txt
  938. fi
  939.  
  940. echo -e "\tDownloading..."
  941. #
  942. # Download ChangeLog.txt first of all and test if it's equal
  943. # or different from our already existent ChangeLog.txt
  944. #
  945. getfile ${SOURCE}ChangeLog.txt $TMPDIR/ChangeLog.txt
  946. if ! grep -q "[a-z]" $TMPDIR/ChangeLog.txt ; then
  947. echo -e "\
  948. \nError downloading from $SOURCE.\n\
  949. Please, check your mirror and try again."
  950. cleanup
  951. fi
  952.  
  953. if diff --brief ${WORKDIR}/ChangeLog.txt $TMPDIR/ChangeLog.txt ; then
  954. return 0
  955. else
  956. return 1
  957. fi
  958. }
  959.  
  960. function updatefilelists()
  961. {
  962. if checkchangelog ; then
  963. echo -e "\
  964. \n\t\tNo changes in ChangeLog.txt between your last update and now.\n\
  965. \t\tDo you really want to download all other files (y/N)? \c"
  966. answer
  967. if [ "$ANSWER" != "Y" ] && [ "$ANSWER" != "y" ]; then
  968. cleanup
  969. fi
  970. fi
  971. echo
  972. cp ${TMPDIR}/ChangeLog.txt ${WORKDIR}/ChangeLog.txt
  973.  
  974. #
  975. # Download MANIFEST, FILELIST.TXT and CHECKSUMS.md5
  976. #
  977.  
  978. # That will be download MANIFEST.bz2 files
  979. #
  980. echo -e "\t\tList of all files"
  981. for i in ${PRIORITY[@]} ; do
  982. getfile ${SOURCE}${i}/MANIFEST.bz2 $TMPDIR/${i}-MANIFEST.bz2 && \
  983. DIRS="$DIRS $i"
  984. done
  985.  
  986. ISOK="1"
  987. echo -e "\t\tChecksums"
  988. getfile ${SOURCE}CHECKSUMS.md5 ${TMPDIR}/CHECKSUMS.md5
  989. getfile ${SOURCE}CHECKSUMS.md5.asc ${TMPDIR}/CHECKSUMS.md5.asc
  990. if ! [ -e "${TMPDIR}/CHECKSUMS.md5" ]; then
  991. echo -e "\
  992. \n\t\tWARNING: Your mirror appears incomplete and is missing the\n\
  993. \t\t CHECKSUMS.md5 file. We recommend you change your mirror\n\
  994. \t\t so that package integrity can be verified against \n\
  995. \t\t CHECKSUMS.md5.\n"
  996. sleep 10
  997. else
  998. if [ "$CHECKGPG" = "on" ]; then
  999. ISOK=$(checkgpg ${TMPDIR}/CHECKSUMS.md5)
  1000. if [ "$ISOK" = "0" ]; then
  1001. rm $TMPDIR/CHECKSUMS.md5
  1002. rm $TMPDIR/CHECKSUMS.md5.asc
  1003. echo -e "\
  1004. \n\t\tERROR: Verification of the gpg signature on CHECKSUMS.md5\n\
  1005. \t\t failed! This could mean that the file is out of date\n\
  1006. \t\t or has been tampered with.\n"
  1007. cleanup
  1008. fi
  1009. elif [ "$SLACKKEY" != "" ]; then
  1010. echo -e "\
  1011. \n\t\tWARNING: Without CHECKGPG, we can't check if this file is\n\
  1012. \t\t signed by:\n\
  1013. \n\t\t $SLACKKEY.\n\
  1014. \n\t\t Enabling CHECKGPG is highly recommended for best\n\
  1015. \t\t security.\n"
  1016. sleep 10
  1017. fi
  1018. fi
  1019.  
  1020. ISOK="1"
  1021. echo -e "\t\tPackage List"
  1022. getfile ${SOURCE}FILELIST.TXT ${TMPDIR}/FILELIST.TXT
  1023. if [ "$CHECKMD5" = "on" ]; then
  1024. CHECKSUMSFILE=${TMPDIR}/CHECKSUMS.md5
  1025. ISOK=$(checkmd5 ${TMPDIR}/FILELIST.TXT)
  1026. fi
  1027. if [ "$ISOK" = "1" ]; then
  1028. if ! [ -e $WORKDIR/LASTUPDATE ]; then
  1029. echo "742868196" > $WORKDIR/LASTUPDATE
  1030. fi
  1031. LASTUPDATE=$(cat $WORKDIR/LASTUPDATE)
  1032. ACTUALDATE=$(date -d "$(head -1 $TMPDIR/FILELIST.TXT)" "+%s")
  1033. if [ $ACTUALDATE -lt $LASTUPDATE ]; then
  1034. echo -e "\
  1035. \n\t\tFILELIST.TXT seems to be older than the last one.\n\
  1036. \t\tDo you really want to continue (y/N)? \c"
  1037. answer
  1038. if [ "$ANSWER" != "Y" ] && [ "$ANSWER" != "y" ]; then
  1039. cleanup
  1040. fi
  1041. echo
  1042. fi
  1043. echo $ACTUALDATE > $WORKDIR/LASTUPDATE
  1044. else
  1045. rm $TMPDIR/FILELIST.TXT
  1046. fi
  1047.  
  1048. if [ -e $TMPDIR/CHECKSUMS.md5 ]; then
  1049. FILELIST="$TMPDIR/CHECKSUMS.md5"
  1050. elif [ -e $TMPDIR/FILELIST.TXT ]; then
  1051. if [ "$ISOK" = "0" ]; then
  1052. echo -e "\
  1053. \n\t\tERROR: CHECKSUMS.md5 signature doesn't match!\n\
  1054. \t\t We strongly recommend that you change your mirror\n\
  1055. \t\t to prevent security problems.\n"
  1056. cleanup
  1057. fi
  1058. sleep 10
  1059. FILELIST="$TMPDIR/FILELIST.TXT"
  1060. else
  1061. echo -e "\
  1062. \n\t\tERROR: No CHECKSUMS.md5 and no FILELIST.TXT.\n\
  1063. \t\t We strongly recommend that you change your mirror\n\
  1064. \t\t to prevent security problems.\n"
  1065. cleanup
  1066. fi
  1067.  
  1068. # Download all PACKAGES.TXT files
  1069. #
  1070. echo -e "\t\tPackage descriptions"
  1071. for i in $DIRS; do
  1072. getfile ${SOURCE}${i}/PACKAGES.TXT $TMPDIR/${i}-PACKAGES.TXT
  1073. done
  1074.  
  1075. # Format FILELIST.TXT
  1076. #
  1077. echo -e "\tFormatting lists to slackpkg style..."
  1078. echo -e "\t\tPackage List: using $( basename $FILELIST ) as source"
  1079. grep "\.t[blxg]z$" $FILELIST| \
  1080. awk -f /usr/libexec/slackpkg/pkglist.awk |\
  1081. sed -e 's/^M//g' > ${TMPDIR}/pkglist
  1082. cp ${TMPDIR}/pkglist ${WORKDIR}/pkglist
  1083.  
  1084. # Create the slackware tree under TEMP directory
  1085. for i in $( cut -f7 -d\ ${WORKDIR}/pkglist | sort -u ) ; do
  1086. if ! [ -d ${TEMP}/${i} ]; then
  1087. mkdir -p ${TEMP}/${i}
  1088. fi
  1089. done
  1090.  
  1091. # Format MANIFEST
  1092. #
  1093.  
  1094. # bunzip and concatenate all MANIFEST files
  1095. #
  1096. MANFILES=""
  1097. for i in $DIRS; do
  1098. bunzip2 -c $TMPDIR/${i}-MANIFEST.bz2 | awk -f /usr/libexec/slackpkg/filelist.awk | \
  1099. gzip > ${TMPDIR}/${i}-filelist.gz
  1100. done
  1101. cp ${TMPDIR}/*-filelist.gz ${WORKDIR}/
  1102.  
  1103. if [ -r ${WORKDIR}/filelist.gz ]; then
  1104. rm ${WORKDIR}/filelist.gz
  1105. ln -s ${WORKDIR}/${MAIN}-filelist.gz ${WORKDIR}/filelist.gz
  1106. fi
  1107.  
  1108. # Concatenate PACKAGE.TXT files
  1109. #
  1110. echo -e "\t\tPackage descriptions"
  1111. for i in $DIRS; do
  1112. cat $TMPDIR/${i}-PACKAGES.TXT >> $TMPDIR/PACKAGES.TXT
  1113. done
  1114. cp $TMPDIR/PACKAGES.TXT ${WORKDIR}/PACKAGES.TXT
  1115.  
  1116. if [ -e $TMPDIR/CHECKSUMS.md5 ]; then
  1117. cp $TMPDIR/CHECKSUMS.md5 $WORKDIR/CHECKSUMS.md5 2>/dev/null
  1118. fi
  1119.  
  1120. if [ -e $TMPDIR/CHECKSUMS.md5.asc ]; then
  1121. cp $TMPDIR/CHECKSUMS.md5.asc \
  1122. $WORKDIR/CHECKSUMS.md5.asc 2>/dev/null
  1123. fi
  1124. }
  1125.  
  1126. function sanity_check() {
  1127. local REVNAME
  1128. local i
  1129. local FILES
  1130. local DOUBLEFILES
  1131. local ANSWER
  1132.  
  1133. touch ${TMPDIR}/waiting
  1134. echo -e "Checking local integrity... \c"
  1135.  
  1136. [ "$SPINNING" = "off" ] || spinning ${TMPDIR}/waiting &
  1137.  
  1138. for i in $(ls -1 /var/log/packages | \
  1139. egrep -- "^.*-(${ARCH}|fw|noarch)-[^-]+-upgraded"); do
  1140. REVNAME=$(echo ${i} | awk -F'-upgraded' '{ print $1 }')
  1141. mv /var/log/packages/${i} /var/log/packages/${REVNAME}
  1142. mv /var/log/scripts/${i} /var/log/scripts/${REVNAME}
  1143. done
  1144.  
  1145. ls -1 /var/log/packages | egrep "^.*-(${ARCH}|fw|noarch)-[^-]+$" | \
  1146. batchcutpkg | sort > $TMPDIR/list1
  1147. cat $TMPDIR/list1 | uniq > $TMPDIR/list2
  1148. FILES="$(diff $TMPDIR/list1 $TMPDIR/list2 | grep '<' | cut -f2 -d\ )"
  1149. if [ "$FILES" != "" ]; then
  1150. for i in $FILES ; do
  1151. grep -qx "${i}" ${CONF}/blacklist && continue
  1152. DOUBLEFILES="$DOUBLEFILES $i"
  1153. done
  1154. unset FILES
  1155. fi
  1156.  
  1157. rm ${TMPDIR}/waiting
  1158. echo -e "DONE"
  1159.  
  1160. if [ "$DOUBLEFILES" != "" ]; then
  1161. echo -e "\
  1162. You have a broken /var/log/packages - with two versions of the same package.\n\
  1163. The list of packages duplicated in your machine are shown below, but don't\n\
  1164. worry about this list - when you select your action, slackpkg will show a\n\
  1165. better list:\n"
  1166. for i in $DOUBLEFILES ; do
  1167. ls -1 /var/log/packages |\
  1168. egrep -i -- "^${i}-[^-]+-(${ARCH}|fw|noarch)-"
  1169. done
  1170. echo -ne "\n\
  1171. You can (B)lacklist, (R)emove, or (I)gnore these packages.\n\
  1172. Select your action (B/R/I): "
  1173. read ANSWER
  1174. echo
  1175. case "$ANSWER" in
  1176. B|b)
  1177. showlist "$DOUBLEFILES" blacklist
  1178. blacklist_pkg
  1179. ;;
  1180. R|r)
  1181. for i in $DOUBLEFILES ; do
  1182. FILE=$(ls -1 /var/log/packages |\
  1183. egrep -i -- "^${i}-[^-]+-(${ARCH}|fw|noarch)-")
  1184. FILES="$FILES $FILE"
  1185. done
  1186. showlist "$FILES" remove
  1187. remove_pkg
  1188. ;;
  1189. *)
  1190. echo -e "\n\
  1191. Okay - slackpkg won't do anything now, but please, do something to fix it.\n"
  1192. cleanup
  1193. ;;
  1194. esac
  1195. fi
  1196. }
  1197.  
  1198. function blacklist_pkg() {
  1199. echo $SHOWLIST | tr ' ' "\n" >> ${CONF}/blacklist
  1200.  
  1201. echo -e "\nPackages added to your blacklist.\n\
  1202. If you want to remove those packages, edit ${CONF}/blacklist.\n"
  1203. }
  1204.  
  1205. function remove_pkg() {
  1206. local i
  1207.  
  1208. for i in $SHOWLIST; do
  1209. echo -e "\nPackage: $i"
  1210. echo -e "\tRemoving... "
  1211. removepkg $i
  1212. done
  1213. }
  1214.  
  1215. function upgrade_pkg() {
  1216. local i
  1217.  
  1218. if [ "$DOWNLOAD_ALL" = "on" ]; then
  1219. OLDDEL="$DELALL"
  1220. DELALL="off"
  1221. for i in $SHOWLIST; do
  1222. getpkg $i true
  1223. done
  1224. DELALL="$OLDDEL"
  1225. fi
  1226. for i in $SHOWLIST; do
  1227. getpkg $i upgradepkg Upgrading
  1228. done
  1229. }
  1230.  
  1231. function install_pkg() {
  1232. local i
  1233.  
  1234. if [ "$DOWNLOAD_ALL" = "on" ]; then
  1235. OLDDEL="$DELALL"
  1236. DELALL="off"
  1237. for i in $SHOWLIST; do
  1238. getpkg $i true
  1239. done
  1240. DELALL="$OLDDEL"
  1241. fi
  1242. for i in $SHOWLIST; do
  1243. getpkg $i installpkg Installing
  1244. done
  1245. }
  1246.  
  1247. #
  1248. # Template related functions
  1249. #
  1250. include_includes() {
  1251. TEMPLATEFILE=$1
  1252. COUNT=$((COUNT + 1))
  1253. TMPFILE=$TMPDIR/$(basename $( echo $TEMPLATEFILE | cut -f1,2 -d. )).$COUNT.tmp
  1254. INCLUDELIST="$( grep "^#include" $TEMPLATEFILE | cut -d\ -f2 )"
  1255. if [ "$INCLUDELIST" != "" ]; then
  1256. for INCLUDE in $INCLUDELIST ; do
  1257. echo "#include $INCLUDE" \
  1258. >> ${TMPFILE/.$COUNT/}.header
  1259. cat $INCLUDE > $TMPFILE
  1260. grep -v "^$" $TEMPLATEFILE | grep -v "^#" >> $TMPFILE
  1261. include_includes $TMPFILE
  1262. done
  1263. else
  1264. echo $TEMPLATEFILE
  1265. return
  1266. fi
  1267. }
  1268.  
  1269. parse_template() {
  1270. if [ "$USE_INCLUDES" = "off" ]; then
  1271. touch $TMPDIR/$1.header
  1272. grep -v "^$" $1 | grep -v "^#" | sort -u > $TMPDIR/$1.tmp
  1273. else
  1274. TMPFILE=$(include_includes $1)
  1275. sort -u $TMPFILE > $TMPDIR/$1.tmp
  1276. if [ -e $TMPDIR/$1.tmp.header ]; then
  1277. sort -u $TMPDIR/$1.tmp.header > $TMPDIR/$1.header
  1278. fi
  1279. rm $TMPDIR/$1.[0-9]*.tmp $TMPDIR/$1.tmp.header 2>/dev/null
  1280. fi
  1281. }
  1282.  
  1283. generate_template() {
  1284. if [ "$USE_INCLUDES" = "on" ]; then
  1285. (
  1286. cd $TEMPLATEDIR
  1287. if [ "$(ls *.template 2>/dev/null)" != "" ]; then
  1288. echo -e "\tParsing actual template files:"
  1289. for i in *.template ; do
  1290. echo -e "\t\t$i"
  1291. parse_template $i
  1292. done
  1293. fi
  1294. )
  1295. fi
  1296.  
  1297. touch $TMPDIR/allheaders
  1298.  
  1299. touch $TMPDIR/waiting
  1300. echo -e "\tGenerating slackware installed package list (this may take a while) \c"
  1301. [ "$SPINNING" = "off" ] || spinning ${TMPDIR}/waiting &
  1302. for i in /var/log/packages/* ; do
  1303. PKGNAME=$( cutpkg $(basename $i))
  1304. grep -q " $PKGNAME " ${WORKDIR}/pkglist && \
  1305. echo $PKGNAME >> $TMPDIR/$TEMPLATE.work
  1306. done
  1307. rm $TMPDIR/waiting
  1308. echo " "
  1309.  
  1310. echo -e "\tGenerating $TEMPLATE "
  1311. for TMPLATE in $( wc -l $TMPDIR/* | sort -r | \
  1312. awk -F/ '/template.tmp/ { print $NF }'); do
  1313. if ! $( grep -q "^#include.*${TMPLATE/.tmp/}" \
  1314. $TMPDIR/allheaders) ; then
  1315. diff -y $TMPDIR/$TEMPLATE.work $TMPDIR/$TMPLATE | \
  1316. awk -vTMPDIR=$TMPDIR \
  1317. '!/</ { print $1 > TMPDIR"/same" }
  1318. /</ { print $1 > TMPDIR"/notsame" }'
  1319. if $( diff -q $TMPDIR/$TMPLATE \
  1320. $TMPDIR/same &>/dev/null ); then
  1321. echo "#include ${TMPLATE/.tmp/}" \
  1322. >> $TMPDIR/$TEMPLATE.header
  1323. cat $TMPDIR/${TMPLATE/.tmp/}.header \
  1324. >> $TMPDIR/allheaders 2>/dev/null
  1325. cat $TMPDIR/same >> $TMPDIR/allfiles
  1326. fi
  1327. fi
  1328. done
  1329.  
  1330. if [ -e $TMPDIR/allfiles ]; then
  1331. sort -u $TMPDIR/allfiles > $TMPDIR/alluniqfiles
  1332. else
  1333. touch $TMPDIR/alluniqfiles
  1334. fi
  1335. if [ -e $TMPDIR/$TEMPLATE.header ]; then
  1336. cat $TMPDIR/$TEMPLATE.header > $TEMPLATEDIR/$TEMPLATE
  1337. fi
  1338. diff $TMPDIR/alluniqfiles $TMPDIR/$TEMPLATE.work |\
  1339. awk '/>/ { print $2 }' >> $TEMPLATEDIR/$TEMPLATE
  1340. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement