paketci 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  1. #!/bin/bash
  2. #
  3. # pkgutils
  4. #
  5. # Copyright (c) 2000-2005 Per Liden
  6. # Copyright (c) 2006-2007 by CRUX team (http://crux.nu)
  7. #
  8. # This program is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation; either version 2 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with this program; if not, write to the Free Software
  20. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  21. # USA.
  22. #
  23. info() {
  24. echo "=======> $1"
  25. }
  26. warning() {
  27. info "WARNING: $1" >&2
  28. }
  29. error() {
  30. info "ERROR: $1" >&2
  31. }
  32. get_filename() {
  33. local FILE="`echo $1 | sed 's|^.*://.*/||g'`"
  34. if [ "$FILE" != "$1" ]; then
  35. FILE="$PKGMK_SOURCE_DIR/$FILE"
  36. fi
  37. echo $FILE
  38. }
  39. get_basename() {
  40. local FILE="`echo $1 | sed 's|^.*://.*/||g'`"
  41. echo $FILE
  42. }
  43. check_pkgfile() {
  44. if [ "`type -t build`" != "function" ]; then
  45. error "Function 'build' not specified in $PKGMK_PKGFILE."
  46. exit 1
  47. fi
  48. }
  49. check_directory() {
  50. if [ ! -d $1 ]; then
  51. error "Directory '$1' does not exist."
  52. exit 1
  53. # elif [ ! -w $1 ]; then
  54. # error "Directory '$1' not writable."
  55. # exit 1
  56. elif [ ! -x $1 ] || [ ! -r $1 ]; then
  57. error "Directory '$1' not readable."
  58. exit 1
  59. fi
  60. }
  61. download_file() {
  62. info "Downloading '$1'."
  63. if [ ! "`type -p wget`" ]; then
  64. error "Command 'wget' not found."
  65. exit 1
  66. fi
  67. LOCAL_FILENAME=`get_filename $1`
  68. LOCAL_FILENAME_PARTIAL="$LOCAL_FILENAME.partial"
  69. DOWNLOAD_OPTS="--passive-ftp --no-directories --tries=3 --waitretry=3 \
  70. --directory-prefix=$PKGMK_SOURCE_DIR \
  71. --output-document=$LOCAL_FILENAME_PARTIAL"
  72. if [ -f "$LOCAL_FILENAME_PARTIAL" ]; then
  73. info "Partial download found, trying to resume"
  74. RESUME_CMD="-c"
  75. fi
  76. error=1
  77. BASENAME=`get_basename $1`
  78. for REPO in ${PKGMK_SOURCE_MIRRORS[@]}; do
  79. REPO="`echo $REPO | sed 's|/$||'`"
  80. wget $RESUME_CMD $DOWNLOAD_OPTS $REPO/$BASENAME
  81. error=$?
  82. if [ $error == 0 ]; then
  83. break
  84. fi
  85. done
  86. if [ $error != 0 ]; then
  87. while true; do
  88. wget $RESUME_CMD $DOWNLOAD_OPTS $1
  89. error=$?
  90. if [ $error != 0 ] && [ "$RESUME_CMD" ]; then
  91. info "Partial download failed, restarting"
  92. rm -f "$LOCAL_FILENAME_PARTIAL"
  93. RESUME_CMD=""
  94. else
  95. break
  96. fi
  97. done
  98. fi
  99. if [ $error != 0 ]; then
  100. error "Downloading '$1' failed."
  101. exit 1
  102. fi
  103. mv -f "$LOCAL_FILENAME_PARTIAL" "$LOCAL_FILENAME"
  104. }
  105. download_source() {
  106. local FILE LOCAL_FILENAME
  107. for FILE in ${source[@]}; do
  108. LOCAL_FILENAME=`get_filename $FILE`
  109. if [ ! -e $LOCAL_FILENAME ]; then
  110. if [ "$LOCAL_FILENAME" = "$FILE" ]; then
  111. error "Source file '$LOCAL_FILENAME' not found (can not be downloaded, URL not specified)."
  112. exit 1
  113. else
  114. if [ "$PKGMK_DOWNLOAD" = "yes" ]; then
  115. download_file $FILE
  116. else
  117. error "Source file '$LOCAL_FILENAME' not found (use option -d to download)."
  118. exit 1
  119. fi
  120. fi
  121. fi
  122. done
  123. }
  124. unpack_source() {
  125. local FILE LOCAL_FILENAME COMMAND
  126. for FILE in ${source[@]}; do
  127. LOCAL_FILENAME=`get_filename $FILE`
  128. case $LOCAL_FILENAME in
  129. *.tar.gz|*.tar.Z|*.tgz|*.tar.bz2|*.tbz2|*.tar.xz|*.txz|*.tar.lzma|*.zip|*.rpm)
  130. COMMAND="tar -p -o -C $SRC -xf $LOCAL_FILENAME" ;;
  131. *)
  132. COMMAND="cp $LOCAL_FILENAME $SRC" ;;
  133. esac
  134. echo "$COMMAND"
  135. $COMMAND
  136. if [ $? != 0 ]; then
  137. if [ "$PKGMK_KEEP_WORK" = "no" ]; then
  138. rm -rf $PKGMK_WORK_DIR
  139. fi
  140. error " '$TARGET' derlenmesi basarisiz"
  141. exit 1
  142. fi
  143. done
  144. }
  145. make_md5sum() {
  146. local FILE LOCAL_FILENAMES
  147. if [ "$source" ]; then
  148. for FILE in ${source[@]}; do
  149. LOCAL_FILENAMES="$LOCAL_FILENAMES `get_filename $FILE`"
  150. done
  151. md5sum $LOCAL_FILENAMES | sed -e 's| .*/| |' | sort -k 2
  152. fi
  153. }
  154. make_footprint() {
  155. pkginfo --footprint $TARGET | \
  156. sed "s|\tlib/modules/`uname -r`/|\tlib/modules/<kernel-version>/|g" | \
  157. sort -k 3
  158. }
  159. check_md5sum() {
  160. local FILE="$PKGMK_WORK_DIR/.tmp"
  161. cd $PKGMK_ROOT
  162. if [ -f $PKGMK_MD5SUM ]; then
  163. make_md5sum > $FILE.md5sum
  164. sort -k 2 $PKGMK_MD5SUM > $FILE.md5sum.orig
  165. diff -w -t -U 0 $FILE.md5sum.orig $FILE.md5sum | \
  166. sed '/^@@/d' | \
  167. sed '/^+++/d' | \
  168. sed '/^---/d' | \
  169. sed 's/^+/NEW /g' | \
  170. sed 's/^-/MISSING /g' > $FILE.md5sum.diff
  171. if [ -s $FILE.md5sum.diff ]; then
  172. error "Md5sum mismatch found:"
  173. cat $FILE.md5sum.diff >&2
  174. if [ "$PKGMK_KEEP_WORK" = "no" ]; then
  175. rm -rf $PKGMK_WORK_DIR
  176. fi
  177. if [ "$PKGMK_CHECK_MD5SUM" = "yes" ]; then
  178. error "Md5sum not ok."
  179. exit 1
  180. fi
  181. error "Building '$TARGET' failed."
  182. exit 1
  183. fi
  184. else
  185. if [ "$PKGMK_CHECK_MD5SUM" = "yes" ]; then
  186. if [ "$PKGMK_KEEP_WORK" = "no" ]; then
  187. rm -rf $PKGMK_WORK_DIR
  188. fi
  189. info "Md5sum not found."
  190. exit 1
  191. fi
  192. warning "Md5sum not found, creating new."
  193. make_md5sum > $PKGMK_MD5SUM
  194. fi
  195. if [ "$PKGMK_CHECK_MD5SUM" = "yes" ]; then
  196. if [ "$PKGMK_KEEP_WORK" = "no" ]; then
  197. rm -rf $PKGMK_WORK_DIR
  198. fi
  199. info "Md5sum ok."
  200. exit 0
  201. fi
  202. }
  203. strip_files() {
  204. local FILE FILTER
  205. cd $PKG
  206. if [ -f $PKGMK_ROOT/$PKGMK_NOSTRIP ]; then
  207. FILTER="grep -v -f $PKGMK_ROOT/$PKGMK_NOSTRIP"
  208. else
  209. FILTER="cat"
  210. fi
  211. find . -type f -printf "%P\n" | $FILTER | while read FILE; do
  212. case $(file -b "$FILE") in
  213. *ELF*executable*not\ stripped)
  214. strip --strip-all "$FILE"
  215. ;;
  216. *ELF*shared\ object*not\ stripped)
  217. strip --strip-unneeded "$FILE"
  218. ;;
  219. current\ ar\ archive)
  220. strip --strip-debug "$FILE"
  221. esac
  222. done
  223. }
  224. compress_manpages() {
  225. local FILE DIR TARGET
  226. cd $PKG
  227. find . -type f -path "*/man/man*/*" | while read FILE; do
  228. if [ "$FILE" = "${FILE%%.gz}" ]; then
  229. gzip -9 "$FILE"
  230. fi
  231. done
  232. find . -type l -path "*/man/man*/*" | while read FILE; do
  233. TARGET=`readlink -n "$FILE"`
  234. TARGET="${TARGET##*/}"
  235. TARGET="${TARGET%%.gz}.gz"
  236. rm -f "$FILE"
  237. FILE="${FILE%%.gz}.gz"
  238. DIR=`dirname "$FILE"`
  239. if [ -e "$DIR/$TARGET" ]; then
  240. ln -sf "$TARGET" "$FILE"
  241. fi
  242. done
  243. }
  244. check_footprint() {
  245. local FILE="$PKGMK_WORK_DIR/.tmp"
  246. cd $PKGMK_ROOT
  247. if [ -f $TARGET ]; then
  248. make_footprint > $FILE.footprint
  249. if [ -f $PKGMK_FOOTPRINT ]; then
  250. sort -k 3 $PKGMK_FOOTPRINT > $FILE.footprint.orig
  251. diff -w -t -U 0 $FILE.footprint.orig $FILE.footprint | \
  252. sed '/^@@/d' | \
  253. sed '/^+++/d' | \
  254. sed '/^---/d' | \
  255. sed 's/^+/NEW /g' | \
  256. sed 's/^-/MISSING /g' > $FILE.footprint.diff
  257. if [ -s $FILE.footprint.diff ]; then
  258. error "Footprint mismatch found:"
  259. cat $FILE.footprint.diff >&2
  260. BUILD_SUCCESSFUL="no"
  261. fi
  262. else
  263. warning "Footprint not found, creating new."
  264. mv $FILE.footprint $PKGMK_FOOTPRINT
  265. fi
  266. else
  267. error "Package '$TARGET' was not found."
  268. BUILD_SUCCESSFUL="no"
  269. fi
  270. }
  271. build_package() {
  272. local BUILD_SUCCESSFUL="no"
  273. export PKG="/"
  274. export SRC="$PKGMK_WORK_DIR/src"
  275. umask 022
  276. cd $PKGMK_ROOT
  277. rm -rf $PKGMK_WORK_DIR
  278. mkdir -p $SRC
  279. info "Building '$TARGET'."
  280. if [ "$PKGMK_DOWNLOAD" = "yes" ]; then
  281. download_source
  282. fi
  283. unpack_source
  284. cd $SRC
  285. (set -e -x ; build)
  286. # cd $PKG
  287. if [ $? = 0 ]; then
  288. BUILD_SUCCESSFUL="yes"
  289. fi
  290. if [ "$PKGMK_KEEP_WORK" = "no" ]; then
  291. rm -rf $PKGMK_WORK_DIR
  292. fi
  293. if [ "$BUILD_SUCCESSFUL" = "yes" ]; then
  294. info " '$TARGET' derleme basarili"
  295. else
  296. if [ -f $TARGET ]; then
  297. touch -r $PKGMK_ROOT/$PKGMK_PKGFILE $TARGET &> /dev/null
  298. fi
  299. error " '$TARGET' derleme basarisiz"
  300. exit 1
  301. fi
  302. }
  303. install_package() {
  304. local COMMAND
  305. info "Installing '$TARGET'."
  306. if [ "$PKGMK_INSTALL" = "install" ]; then
  307. COMMAND="pkgadd $TARGET"
  308. else
  309. COMMAND="pkgadd -u $TARGET"
  310. fi
  311. cd $PKGMK_ROOT
  312. echo "$COMMAND"
  313. $COMMAND
  314. if [ $? = 0 ]; then
  315. info "Installing '$TARGET' succeeded."
  316. else
  317. error "Installing '$TARGET' failed."
  318. exit 1
  319. fi
  320. }
  321. recursive() {
  322. local ARGS FILE DIR
  323. ARGS=`echo "$@" | sed -e "s/--recursive//g" -e "s/-r//g"`
  324. for FILE in `find $PKGMK_ROOT -name $PKGMK_PKGFILE | sort`; do
  325. DIR="`dirname $FILE`/"
  326. if [ -d $DIR ]; then
  327. info "Entering directory '$DIR'."
  328. (cd $DIR && $PKGMK_COMMAND $ARGS)
  329. info "Leaving directory '$DIR'."
  330. fi
  331. done
  332. }
  333. clean() {
  334. local FILE LOCAL_FILENAME
  335. if [ -f $TARGET ]; then
  336. info "Removing $TARGET"
  337. rm -f $TARGET
  338. fi
  339. for FILE in ${source[@]}; do
  340. LOCAL_FILENAME=`get_filename $FILE`
  341. if [ -e $LOCAL_FILENAME ] && [ "$LOCAL_FILENAME" != "$FILE" ]; then
  342. info "Removing $LOCAL_FILENAME"
  343. rm -f $LOCAL_FILENAME
  344. fi
  345. done
  346. }
  347. update_footprint() {
  348. if [ ! -f $TARGET ]; then
  349. error "Unable to update footprint. File '$TARGET' not found."
  350. exit 1
  351. fi
  352. make_footprint > $PKGMK_FOOTPRINT
  353. touch $TARGET
  354. info "Footprint updated."
  355. }
  356. build_needed() {
  357. local FILE RESULT
  358. RESULT="yes"
  359. if [ -f $TARGET ]; then
  360. RESULT="no"
  361. for FILE in $PKGMK_PKGFILE ${source[@]}; do
  362. FILE=`get_filename $FILE`
  363. if [ ! -e $FILE ] || [ ! $TARGET -nt $FILE ]; then
  364. RESULT="yes"
  365. break
  366. fi
  367. done
  368. fi
  369. echo $RESULT
  370. }
  371. interrupted() {
  372. echo ""
  373. error "Interrupted."
  374. if [ "$PKGMK_KEEP_WORK" = "no" ]; then
  375. rm -rf $PKGMK_WORK_DIR
  376. fi
  377. exit 1
  378. }
  379. print_help() {
  380. echo "usage: `basename $PKGMK_COMMAND` [options]"
  381. echo "options:"
  382. echo " -i, --install build and install package"
  383. echo " -u, --upgrade build and install package (as upgrade)"
  384. echo " -r, --recursive search for and build packages recursively"
  385. echo " -d, --download download missing source file(s)"
  386. echo " -do, --download-only do not build, only download missing source file(s)"
  387. echo " -utd, --up-to-date do not build, only check if package is up to date"
  388. echo " -uf, --update-footprint update footprint using result from last build"
  389. echo " -if, --ignore-footprint build package without checking footprint"
  390. echo " -um, --update-md5sum update md5sum"
  391. echo " -im, --ignore-md5sum build package without checking md5sum"
  392. echo " -cm, --check-md5sum do not build, only check md5sum"
  393. echo " -ns, --no-strip do not strip executable binaries or libraries"
  394. echo " -f, --force build package even if it appears to be up to date"
  395. echo " -c, --clean remove package and downloaded files"
  396. echo " -kw, --keep-work keep temporary working directory"
  397. echo " -cf, --config-file <file> use alternative configuration file"
  398. echo " -v, --version print version and exit "
  399. echo " -h, --help print help and exit"
  400. }
  401. remove_locale() {
  402. cd $PKG/usr/share
  403. if [ -d locale/fr ]; then
  404. mv locale/fr fr
  405. fi
  406. rm -rf locale
  407. if [ -d fr ]; then
  408. mkdir locale
  409. mv fr locale/
  410. fi
  411. }
  412. parse_options() {
  413. while [ "$1" ]; do
  414. case $1 in
  415. -i|--install)
  416. PKGMK_INSTALL="install" ;;
  417. -u|--upgrade)
  418. PKGMK_INSTALL="upgrade" ;;
  419. -r|--recursive)
  420. PKGMK_RECURSIVE="yes" ;;
  421. -d|--download)
  422. PKGMK_DOWNLOAD="yes" ;;
  423. -do|--download-only)
  424. PKGMK_DOWNLOAD="yes"
  425. PKGMK_DOWNLOAD_ONLY="yes" ;;
  426. -utd|--up-to-date)
  427. PKGMK_UP_TO_DATE="yes" ;;
  428. -uf|--update-footprint)
  429. PKGMK_UPDATE_FOOTPRINT="yes" ;;
  430. -if|--ignore-footprint)
  431. PKGMK_IGNORE_FOOTPRINT="yes" ;;
  432. -um|--update-md5sum)
  433. PKGMK_UPDATE_MD5SUM="yes" ;;
  434. -im|--ignore-md5sum)
  435. PKGMK_IGNORE_MD5SUM="yes" ;;
  436. -cm|--check-md5sum)
  437. PKGMK_CHECK_MD5SUM="yes" ;;
  438. -ns|--no-strip)
  439. PKGMK_NO_STRIP="yes" ;;
  440. -f|--force)
  441. PKGMK_FORCE="yes" ;;
  442. -c|--clean)
  443. PKGMK_CLEAN="yes" ;;
  444. -kw|--keep-work)
  445. PKGMK_KEEP_WORK="yes" ;;
  446. -kl|--keep-locale)
  447. PKGMK_KEEP_LOCALE="yes" ;;
  448. -cf|--config-file)
  449. if [ ! "$2" ]; then
  450. echo "`basename $PKGMK_COMMAND`: option $1 requires an argument"
  451. exit 1
  452. fi
  453. PKGMK_CONFFILE="$2"
  454. shift ;;
  455. -v|--version)
  456. echo "`basename $PKGMK_COMMAND` (pkgutils) $PKGMK_VERSION"
  457. exit 0 ;;
  458. -h|--help)
  459. print_help
  460. exit 0 ;;
  461. *)
  462. echo "`basename $PKGMK_COMMAND`: invalid option $1"
  463. exit 1 ;;
  464. esac
  465. shift
  466. done
  467. }
  468. main() {
  469. local FILE TARGET
  470. parse_options "$@"
  471. if [ "$PKGMK_RECURSIVE" = "yes" ]; then
  472. recursive "$@"
  473. exit 0
  474. fi
  475. for FILE in $PKGMK_CONFFILE $PKGMK_PKGFILE ; do
  476. if [ ! -f $FILE ]; then
  477. error "File '$FILE' not found."
  478. exit 1
  479. fi
  480. . $FILE
  481. done
  482. check_directory "$PKGMK_SOURCE_DIR"
  483. check_directory "$PKGMK_PACKAGE_DIR"
  484. check_directory "`dirname $PKGMK_WORK_DIR`"
  485. check_pkgfile
  486. TARGET="$PKGMK_PACKAGE_DIR/$PKGMK_PKGFILE"
  487. if [ "$PKGMK_CLEAN" = "yes" ]; then
  488. clean
  489. exit 0
  490. fi
  491. build_package
  492. exit 0
  493. }
  494. trap "interrupted" SIGHUP SIGINT SIGQUIT SIGTERM
  495. export LC_ALL=POSIX
  496. readonly PKGMK_VERSION="5.32.0"
  497. readonly PKGMK_COMMAND="$0"
  498. readonly PKGMK_ROOT="$PWD"
  499. PKGMK_CONFFILE="paketci.conf"
  500. PKGMK_PKGFILE="talimat"
  501. PKGMK_FOOTPRINT=".footprint"
  502. PKGMK_MD5SUM=".md5sum"
  503. PKGMK_NOSTRIP=".nostrip"
  504. PKGMK_SOURCE_MIRRORS=()
  505. PKGMK_SOURCE_DIR="/mnt/lfs/sources"
  506. PKGMK_PACKAGE_DIR="$PWD"
  507. PKGMK_WORK_DIR="/tmp/work"
  508. PKGMK_RECURSIVE="no"
  509. PKGMK_DOWNLOAD="no"
  510. PKGMK_DOWNLOAD_ONLY="no"
  511. PKGMK_UP_TO_DATE="no"
  512. PKGMK_UPDATE_FOOTPRINT="no"
  513. PKGMK_IGNORE_FOOTPRINT="no"
  514. PKGMK_FORCE="no"
  515. PKGMK_KEEP_WORK="no"
  516. PKGMK_UPDATE_MD5SUM="no"
  517. PKGMK_IGNORE_MD5SUM="yes"
  518. PKGMK_CHECK_MD5SUM="no"
  519. PKGMK_NO_STRIP="no"
  520. PKGMK_CLEAN="no"
  521. PKGMK_KEEP_LOCALE="no"
  522. main "$@"
  523. # End of file