2 # Copyright (C) 2016-2019 Matias Fonzo <selk@dragora.org>
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # 0 = Successful completion
19 # 1 = Minor common errors (e.g: help usage, support not available)
20 # 2 = Command execution error
21 # 3 = Integrity check error for compressed files
22 # 4 = File empty, not regular, or expected
23 # 5 = Empty or not defined variable
24 # 6 = Package already installed
25 # 10 = Network manager error
32 "Qi - A practical and user-friendly package manager." \
34 "Usage: $PROGRAM [OPTION...] [FILE]..." \
37 " -b Build packages using recipes" \
38 " -c Create .tlz package from directory" \
39 " -d Delete packages" \
40 " -i Install packages" \
41 " -o Resolve build order through .order files" \
42 " -u Update packages (implies -i, -d with -p)" \
43 " -w Warn about files that will be installed" \
44 " -x Extract packages for debugging purposes" \
47 " -L Print default directory locations" \
48 " -N Don't read the configuration file" \
49 " -P <DIR> Package directory for (de)installations;" \
50 " (only valid for -i, -d, or -u options)" \
51 " -f Force package upgrade" \
52 " Force build a recipe" \
53 " -t <DIR> Target directory for symbolic links" \
54 " (only valid for -i, -d, or -u options)" \
55 " -k Keep (don't delete) srcdir or destdir" \
56 " Keep (don't delete) package directory" \
57 " (only valid for -b, -d or -u options)" \
58 " -p Prune conflicts on package (de)installation" \
59 " -r Use the named directory as the root directory" \
60 " for installing, deleting, or upgrading packages." \
61 " The target directory, package directory will be" \
62 " relative to this specific directory" \
63 " -v Be verbose (a 2nd -v gives more)" \
65 "Options for 'build' mode (-b):" \
66 " -O <DIR> Where the produced packages are written" \
67 " -W <DIR> Where archives, patches, and recipes are expected" \
68 " -Z <DIR> Where (compressed) sources will be found" \
69 " -a Architecture to use [detected]" \
70 " -j Parallel jobs for the compiler" \
71 " -1 Increment release number (release + 1)" \
72 " -n Don't create a .tlz package" \
73 " -S Selects the option to skip completed recipes" \
75 "Informative options:" \
76 " -h Display this help and exit" \
77 " -V Output version information" \
79 "Some influential environment variables:" \
80 " TMPDIR Temporary directory for sources" \
81 " QICFLAGS C compiler flags" \
82 " QICXXFLAGS C++ compiler flags" \
83 " QILDFLAGS Linker flags" \
85 "When FILE is -, read standard input." \
92 "$PROGRAM @VERSION@" \
93 "Copyright (C) 2016-2019 Matias Andres Fonzo." \
94 "License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>" \
95 "This is free software: you are free to change and redistribute it." \
96 "There is NO WARRANTY, to the extent permitted by law."
101 printf "%s\n" "$@" 1>&2
110 echo "${PROGRAM}: cannot read ${1}: Permission denied" 1>&2
114 echo "${PROGRAM}: cannot access ${1}: No such file or directory" 1>&2
119 # Portable alternative to the file operator -nt (among shells)
122 if test -n "$(find $1 -prune -newer $2 -print)"
129 # Determine whether $2 matches pattern $1
146 if test $status -ne 0
148 echo "Return status = $status" 1>&2
149 exit ${1-2}; # If not given, defaults to 2
159 is_readable
"$HOME/.qirc" 2> /dev
/null
&& RCFILE
="$HOME/.qirc";
161 echo "Processing \`${RCFILE}' ..."
163 test -f "$RCFILE" ||
{
164 warn
"${RCFILE} is not a regular file."
169 while IFS
='=' read -r variable value
172 \
#* | "") # Ignore commented or blank lines
177 # Set variable name avoiding code execution
178 eval "$variable=\${value}"
189 # A recipe is any valid regular file, the current working directory
190 # has priority over the working tree (or where the recipes reside).
191 # The 'worktree' is the second place where to find a recipe. Also,
192 # we complete the possibility of using the directory name to invoke
193 # a recipe if it contains "recipe" as valid file name.
195 if test ! -f "$recipe"
197 if test -f "${recipe}/recipe"
199 recipe
="${recipe}/recipe"
200 elif test -f "${worktree}/recipes/${recipe}/recipe"
202 recipe
="${worktree}/recipes/${recipe}/recipe"
206 test -f "$recipe" ||
{
207 warn
"\`${recipe}' is not a regular file."
211 # Complain if the file name is not "recipe"
213 if test "${recipe##*/}" != recipe
215 warn
"\`${recipe}' is not a valid recipe name."
219 # Start preparations to import the recipe
221 # Separate the directory name from the file name,
222 # getting its absolute path and base name
224 CWD
=$
(CDPATH
= cd -P -- $
(dirname -- "$recipe") && printf "$PWD")
225 recipe
=$
(basename -- "$recipe")
227 # Check readability for load the recipe on success
229 is_readable
"${CWD}/$recipe" ||
exit 4
231 # Find target architecture if 'arch' is not set
234 arch
=$
(${CC:-cc} -dumpmachine 2> /dev
/null
) || arch
=unknown
235 arch
="${arch%%-*}" # Get the rid of target triplet.
238 # Re-create external directories
239 mkdir
-p -- "${worktree}/archive" \
240 "${worktree}/patches" \
241 "${worktree}/recipes" \
244 # Variables treatment for the current and next recipe.
246 # Unset special variables that can only be predefined on
247 # the recipe and not coming from ${sysconfdir}/qirc
249 unset srcdir destdir pkgname pkgversion program version release \
250 fetch description homepage license replace full_pkgname \
251 CFLAGS CXXFLAGS LDFLAGS
253 # The following variables must be saved and restored
254 save_arch
="${save_arch:=$arch}"
255 save_jobs
="${save_jobs:=$jobs}"
256 save_outdir
="${save_outdir:=$outdir}"
257 save_opt_nopkg
="${save_opt_nopkg:=$opt_nopkg}"
259 # Reset variable values in case of return
263 opt_nopkg
=$save_opt_nopkg
265 # The following variables cannot be redefined on the recipe
266 readonly worktree netget rsync
270 echo "{@} Building from ${CWD}/$recipe ..."
273 # Check for required variables
274 if test -z "$program"
276 warn
"${recipe}: The variable 'program' is not defined."
279 if test -z "$version"
281 warn
"${recipe}: The variable 'version' is not defined."
284 if test -z "$release"
286 warn
"${recipe}: The variable 'release' is not defined."
290 # Pre-settings before to start building
292 # Increment the release number if the option was given
293 if test "$opt_incr_release" = opt_incr_release
295 release
=$
(( release
+ 1 ))
298 # Allow the dot as definition for 'tardir'
299 if test "$tardir" = .
304 # Set default values for the following special variables
306 pkgname
="${pkgname:=$program}"
307 pkgversion
="${pkgversion:=$version}"
308 srcdir
="${srcdir:=${program}-$version}"
309 destdir
="${destdir:=${TMPDIR}/package-$pkgname}"
311 # Complete package name adding 'pkgversion-arch+release'
312 full_pkgname
="${full_pkgname:=$pkgname-${pkgversion}-${arch}+${release}}"
314 # If a package is going to be created, the existence of a
315 # previous build will be detected and reported. Under normal
316 # conditions the recipe is built as long as it is newer than
317 # the produced package, if not, we warn to the user about it.
318 # Rebuilding the package is possible (through the force ;-)
320 if test "$opt_nopkg" != opt_nopkg
&& \
321 { test "$opt_force" != opt_force
&& \
322 test -e "${outdir}/${full_pkgname}.tlz" ; }
324 if is_newer "${CWD}/$recipe" "${outdir}/${full_pkgname}.tlz
"
328 "The recipe is
more RECENT than the detected package
:" \
330 "$
( stat
-c "%y %n" "${CWD}/$recipe" )" \
331 "$
( stat
-c "%y %n" "${outdir}/${full_pkgname}.tlz" )" \
333 " This recipe will be processed ...
" \
335 elif test -e "${CWD}/post-install
" && \
336 is_newer "${CWD}/post-install
" "${CWD}/$recipe"
340 "The post-install
script is
more RECENT than the recipe
:" \
342 "$
( stat
-c "%y %n" "${CWD}/post-install" )" \
343 "$
( stat
-c "%y %n" "${CWD}/$recipe" )" \
345 " The recipe will be re-processed ...
" \
347 touch "${CWD}/$recipe"
348 elif test "$opt_skipqsts" = opt_skipqsts
350 warn "Recipe
for '${full_pkgname}.tlz': Ignored.
" ""
355 "This recipe ALREADY produced a package
:" \
356 "$
( stat
-c "%y %n" "${outdir}/${full_pkgname}.tlz" )" \
358 "The recipe is still OLDER than the produced package
:" \
359 "$
( stat
-c "%y %n" "${CWD}/$recipe" )" \
361 " Probably nothing has changed.
" \
364 # In non-interactive mode, the user is asked about
365 # rebuilding the package. In interactive mode,
366 # the user need to pass the option explicitly
370 "Do you want to rebuild this package?
\n" \
371 "1) Yes
, built it
\n" \
372 "2) No
, skipt it
[default
]\n" \
373 "3) Resume
, skipping completed recipes
\n" \
374 "Choose an option number
: " > /dev/tty
375 IFS= read -r ANSWER < /dev/tty || exit 2;
378 echo "$ANSWER" > /dev/tty
383 echo "Building UNPROCESSED
/MODIFIED recipes ...
" > /dev/tty
385 opt_skipqsts=opt_skipqsts
386 readonly opt_skipqsts
391 echo "Recipe
for '${full_pkgname}.tlz': Cancelled.
" > /dev/tty
397 warn "Use the
-f option to re-process
${CWD}/$recipe.
" ""
403 # Fetch remote sources
405 echo "Fetching remote sources
if needed ...
"
410 _source="${origin##*/}"
412 echo "Looking
for \"$_source\" ...
"
414 echo "Verifying checksum
file \"${_source}.sha256
\" from
'${tardir}'"
415 if test -e "${tardir}/${_source}.sha256
"
417 ( cd -- "$tardir" && sha256sum - ) < "${tardir}/${_source}.sha256
"
421 warn "${_source}.sha256
: Checksum
file does not exist
, yet.
"
424 # Download source or resume if allowed
426 if test ! -e "${tardir}/$_source"
428 warn " Can
't find $_source in ${tardir};" \
429 "attempting to get it from ${origin%/*} ..."
435 cd -- "$tardir" && $rsync $origin || exit $?
436 sha256sum $_source > ${_source}.sha256
437 ); chkstatus_or_exit 10
441 cd -- "$tardir" && $netget $origin || exit $?
442 sha256sum $_source > ${_source}.sha256
443 ); chkstatus_or_exit 10
446 warn "${PROGRAM}: Unrecognized protocol for ${origin}."
452 warn "The variable 'fetch
' is empty."
455 # Prepare special directories for build the source,
456 # the destination and the output of the package
458 echo "Preparing directories ..."
460 if test -d "${TMPDIR}/$srcdir" && test -z "$keep_srcdir"
462 rm -rf -- "${TMPDIR}/$srcdir" || chkstatus_or_exit
463 echo "removed directory: '${TMPDIR}/$srcdir'"
466 if test -d "$destdir"
468 rm -rf -- "$destdir" || chkstatus_or_exit
469 echo "removed directory: '$destdir'"
471 mkdir -p -- "$destdir" || chkstatus_or_exit
472 echo "mkdir: created directory '$destdir'"
474 if test ! -d "$outdir"
476 mkdir -p -- "$outdir" || chkstatus_or_exit
477 echo "mkdir: created directory '$outdir'"
480 echo "Entering to 'TMPDIR
': $TMPDIR ..."
481 cd -- "$TMPDIR" || chkstatus_or_exit
483 # Set trap before to run the build() function in order
484 # to catch the return status, exit code 2 if fails
486 trap 'chkstatus_or_exit
2' EXIT HUP INT QUIT ABRT TERM
488 # Determine if the debugging indicators of the shell should be
489 # retained, assuming that it has been previously passed
491 _xtrace_flag_is_set=xtrace_flag_is_set ;;
494 echo "Running build() ..."
498 # Turn off possible shell flags coming from the recipe
501 if test "$_xtrace_flag_is_set" != xtrace_flag_is_set
506 # Reset given signals
507 trap - EXIT HUP INT QUIT ABRT TERM
509 # If 'destdir
' is empty, the package won't be created
510 if rmdir -- "$destdir" 2> /dev
/null
512 warn
"The package \"${full_pkgname}.tlz\" won't be created. 'destdir' is empty."
516 # Create (make) the package
518 if test "$opt_nopkg" != opt_nopkg
520 # Edit the recipe when 'release' is incremented
521 if test "$opt_incr_release" = opt_incr_release
523 echo ",s/^\(release\)=.*/\1=${release}/"$
'\nw' | \
524 ed
"${CWD}/$recipe" || chkstatus_or_exit
527 mkdir
-p -- "${destdir}/var/lib/qi" || chkstatus_or_exit
529 # Include a recipe copy into the package
530 cp -p "${CWD}/$recipe" \
531 "${destdir}/var/lib/qi/${full_pkgname}.recipe" && \
532 chmod 644 "${destdir}/var/lib/qi/${full_pkgname}.recipe" || chkstatus_or_exit
534 # Detect post-install script for inclusion
536 if test -f "${CWD}/post-install"
538 echo "${CWD}/post-install: Detected."
539 cp -p "${CWD}/post-install" \
540 "${destdir}/var/lib/qi/${full_pkgname}.sh" && \
541 chmod 644 "${destdir}/var/lib/qi/${full_pkgname}.sh" || chkstatus_or_exit
544 # Detect declared package names for later replacement
546 if test -n "$replace"
549 "The following package names has been declared for replacement:" \
552 rm -f "${destdir}/var/lib/qi/${full_pkgname}.replace"
555 echo "$replace" >> "${destdir}/var/lib/qi/${full_pkgname}.replace"
560 # Create meta file for the package information
561 echo "Creating meta file ${full_pkgname}.tlz.txt ..."
562 do_meta
> "${outdir}/${full_pkgname}.tlz.txt" || chkstatus_or_exit
564 # Make a copy of it for the database
565 cp -p "${outdir}/${full_pkgname}.tlz.txt" \
566 "${destdir}/var/lib/qi/${full_pkgname}.txt" || chkstatus_or_exit
568 # Produce the package
569 cd -- "$destdir" && create_mode
"${outdir}/${full_pkgname}.tlz"
572 # Back to the current working directory
573 cd -- "$CWD" || chkstatus_or_exit
575 # Delete 'srcdir' or 'destdir' if -k was not given
576 if test "$opt_keep" != opt_keep
578 echo "Deleting temporary directories ..."
580 srcdir
="${srcdir%%/*}" # Directory name without parents.
582 if test -r "${TMPDIR}/$srcdir"
584 if test -z "$keep_srcdir"
587 cd -- "$TMPDIR" && rm -rf -- "$srcdir" && \
588 echo "removed directory: '${TMPDIR}/${srcdir}'"
591 warn
"The variable 'keep_srcdir' has been set;" \
592 "'${TMPDIR}/${srcdir}' will not be deleted."
596 if test -r "$destdir"
598 rm -rf -- "$destdir" || chkstatus_or_exit
599 echo "removed directory: '$destdir'"
603 # Install or update the package if -i or -u was passed
604 if test "$opt_nopkg" != opt_nopkg
606 if test "$opt_install" = opt_install
608 install_mode
"${outdir}/${full_pkgname}.tlz"
609 elif test "$opt_update" = opt_update
611 upgrade_mode
"${outdir}/${full_pkgname}.tlz"
616 echo "All done for ${CWD}/${recipe}."
622 directory
=$
(dirname -- "$1")
623 name
=$
(basename -- "$1")
625 # Perform sanity checks
627 is_readable
"$directory" ||
exit 4
629 # Check again to find out if it is a valid directory
630 test -d "$directory" ||
{
631 warn
"Package directory '$name' does not exist."
635 test "$directory" = .
&& {
636 warn
"Cannot create package on current working directory."
640 test "$name" = "${name%.tlz}" && {
642 "Package format '$name' not supported." \
643 "It should be \`name-version-architecture+release.tlz'"
647 echo "{#} Creating package $name ..."
649 ( umask 022 ; tarlz
--solid -9 -cvf - * ) > "${directory}/$name"
652 ( cd -- "$directory" && sha256sum
$name > ${name}.sha256
)
655 echo "Package created \`${directory}/${name}'."
658 # Remove used variables
664 expunge
="${packagedir}/$(basename -- $1 .tlz)"
666 echo "{<} Deleting package $rootdir${expunge} ..."
668 # Complain if the package directory does not exist
670 test -d "$rootdir${expunge}" ||
{
671 warn
"Package directory '$rootdir${expunge}' does not exist."
675 # Complain if the package directory cannot be well-read
677 is_readable
"$rootdir${expunge}" ||
exit 4
679 # Remove package from Graft control
681 # Scan for possible conflicts, stop if arise
682 if test "$opt_prune" != opt_prune
684 echo "Checking for possible conflicts ..."
685 if graft
-d -n $graft_r -t "$targetdir" "$expunge" 2>&1 | \
689 " A conflict occurred during uninstallation;" \
690 "Unless the -p option is given, this package will be PRESERVED."
695 # Ignore some signals up to completing the deinstallation
696 trap "" HUP INT QUIT ABRT TERM
698 # Remove objects (files, links or directories) from the target
699 # directory that are in conflict with the package directory
701 echo "Pruning any conflict ..."
702 graft
-p -D -u $graft_r -t "$targetdir" "$expunge"
705 echo "Disabling links ..."
706 graft
-d -D -u $graft_v $graft_r -t "$targetdir" "$expunge"
709 # Delete package directory
710 if test "$opt_keep" != opt_keep
712 echo "Deleting package directory, if it exists as such ..."
714 if test -d "${rootdir}$expunge"
716 rm -rf -- "${rootdir}$expunge" || chkstatus_or_exit
717 echo "removed directory: '${rootdir}$expunge'"
721 # Reset given signals
722 trap - HUP INT QUIT ABRT TERM
724 # Remove used variables
730 # Complain if the package cannot be well-read
732 is_readable
"$1" ||
exit 4
734 # Complain if the package does not end in .tlz
736 if ! fnmatch
'*.tlz' "$1"
738 warn
"\`${1}' does not end in .tlz"
742 # Make preparations to install the package
744 echo "{>} Installing package $1 ..."
747 name
=$
(basename -- "$1" .tlz
)
749 echo "Checking tarball integrity ..."
750 tarlz
-tf "$1" > /dev
/null
753 # Create package directory using 'name'
754 if ! test -d "$rootdir${packagedir}/$name"
756 mkdir
-p -- "$rootdir${packagedir}/$name" || chkstatus_or_exit
757 echo "mkdir: created directory '$rootdir${packagedir}/$name'"
760 # Scan for possible conflicts, stop if arise
761 if test "$opt_prune" != opt_prune
763 echo "Checking for possible conflicts ..."
764 if graft
-i -n $graft_r -t "$targetdir" "${packagedir}/$name" 2>&1 | \
768 " A conflict occurred during installation;" \
769 "Unless the -p option is given, this package won't be LINKED."
774 # Ignore some signals up to completing the installation
775 trap "" HUP INT QUIT ABRT TERM
777 echo "Decompressing $1 ..."
778 ( cd -- "$rootdir${packagedir}/$name" && tarlz
-xf - ) < "$1"
781 # Transite package to Graft control
783 # Remove objects (files, links or directories) from the target
784 # directory that are in conflict with the package directory
785 echo "Pruning any conflict ..."
786 graft
-p -D -u $graft_r -t "$targetdir" "${packagedir}/$name"
789 echo "Enabling symbolic links ..."
790 graft
-i -P $graft_v $graft_r -t "$targetdir" "${packagedir}/$name"
793 # Avoid unnecessary runs coming from the upgrade_mode(),
794 # this is when the incoming package is **pre-installed**
796 if test "$_isUpgrade" != _isUpgrade.on
798 # Show package description
799 if test -r "$rootdir${packagedir}/${name}/var/lib/qi/${name}.txt"
801 grep '^#' "$rootdir${packagedir}/${name}/var/lib/qi/${name}.txt"
802 elif test -r "${1}.txt"
804 # From external meta file (current directory)
807 warn
"Description file not found for '$name'."
810 # Check and run the post-install script if exist
811 if test -r "$rootdir${packagedir}/${name}/var/lib/qi/${name}.sh"
813 echo "Running post-install script for \`${name}' ..."
815 # Rely on 'targetdir' if 'rootdir' is empty
816 cd -- "${rootdir:-$targetdir}"/ && \
817 .
"$rootdir${packagedir}/${name}/var/lib/qi/${name}.sh"
821 # Check if there are declared packages for replacement
822 if test -r "$rootdir${packagedir}/${name}/var/lib/qi/${name}.replace"
826 for replace
in "$rootdir${packagedir}/$(pkgbase $line)"-*
828 if ! test -e "$replace"
830 warn
"${replace}: Declared package does not exist. (ignored)"
834 replace
="${replace##*/}"
836 # The search for the package to be replaced cannot
837 # be the same to the incoming package, even to the
838 # temporary location coming from the upgrade_mode()
839 if test "$replace" = "$name" ||
test "$replace" = "${PRVLOC##*/}"
844 warn
"WARNING: Replacing package \`${replace}' ..."
846 # Since the links belongs to the new package, only
847 # those which are not in conflict can be deleted.
848 # To complete, we will remove the package directory
850 graft
-d -D -u $graft_r \
851 -t "$targetdir" "$replace" > /dev
/null
2>&1
853 rm -rf -- "$rootdir${packagedir}/$replace"
855 done < "$rootdir${packagedir}/${name}/var/lib/qi/${name}.replace"
860 # Reset given signals
861 trap - HUP INT QUIT ABRT TERM
863 # Remove used variables
868 # Complain if the file cannot be well-read
870 is_readable
"$1" ||
exit 4
872 # Complain if the file does not end in .order
874 if ! fnmatch
'*.order' "$1"
876 warn
"\`${1}' does not end in .order"
880 # Get a clean list of the file while prints its content in reverse order,
881 # lines containing: colons, comments, parentheses, end of line, and blank
882 # lines, are removed. The parentheses are used to insert a reference.
883 # The last `awk' in the pipe: removes nonconsecutive lines, duplicate.
885 '{ gsub( /:|^#(.*)$|\([^)]*)|^$/,"" ); for( i=NF; i > 0; i-- ) print $i }' \
886 "$1" |
awk '!s[$0]++'
891 # Complain if the package does not end in .tlz
893 if ! fnmatch
'*.tlz' "$1"
895 warn
"\`${1}' does not end in .tlz"
900 incoming
=$
(basename -- "$1" .tlz
)
902 echo "{^} Upgrading to $incoming ..."
904 # Check packages in the blacklist for installation
906 echo "Checking blacklist ..."
907 for item
in $blacklist
911 if test ! -e "$rootdir${packagedir}/$incoming"
915 " The package declared in the blacklist will be" \
916 "installed instead of being updated ..." \
918 opt_prune
=opt_prune install_mode
"$1"
922 if is_newer
"$1" "$rootdir${packagedir}/$incoming"
926 "Incoming package is more RECENT than the installed package:" \
928 "$( stat -c "%y
%n
" "$1" )" \
929 "$( stat -c "%y
%n
" "$rootdir${packagedir}/$incoming" )" \
931 " The package declared in the blacklist will be" \
932 " installed as part of the upgrade process ..." \
934 opt_prune
=opt_prune install_mode
"$1"
935 touch "$rootdir${packagedir}/$incoming"
940 "Blacklisted package is already up-to-date:" \
942 "$( stat -c "%y
%n
" "$rootdir${packagedir}/$incoming" )" \
943 "$( stat -c "%y
%n
" "$1" )" \
952 # Check package pre-existence
953 if test "$opt_force" != opt_force
&& \
954 test -e "$rootdir${packagedir}/$incoming"
958 " The package to be updated already exist;" \
959 "Unless the -f option is given, this package won't be UPGRADED."
963 # Prepare the package to install it in a temporary location
965 # Set random directory using packagedir as prefix and 'incoming' as suffix
966 PRVLOC
=$
(mktemp
-dp "$rootdir${packagedir}" ${incoming}.XXXXXXXXXXXX
) ||
exit 2
968 # Pre-install the package in the custom 'packagedir'
970 save_packagedir
="$rootdir${packagedir}"
973 echo "Pre-installing package in a temporary location ..."
974 opt_prune
=opt_prune
# Turn on prune operation.
975 _isUpgrade
=_isUpgrade.on install_mode
"$1" > /dev
/null
976 _isUpgrade
=_isUpgrade.off
978 # Restore variable before looking for old packages
979 packagedir
=$save_packagedir
980 unset save_packagedir
982 echo "Looking for installations under the same name ..."
983 for long_name
in "$rootdir${packagedir}/$(pkgbase $incoming)"*
985 found
="${long_name##*/}"
987 # The search for the package to be deleted
988 # cannot be the same to the temporary location
989 test "$long_name" = "$PRVLOC" && continue;
991 fnmatch
"$(pkgbase $found)*" "$incoming" ||
continue;
992 echo "${long_name}: Detected."
994 # A package directory is preserved if -k is given
995 delete_mode
"$found" > /dev
/null
997 unset long_name found
999 # Re-install the package removing the temporary location
1002 opt_prune
=opt_prune.off
# Turn off prune operation.
1004 echo "Deleting temporary location ..."
1005 rm -rf -- "$PRVLOC" || chkstatus_or_exit
1006 echo "removed directory: '$PRVLOC'"
1009 echo "Successful upgrade to '${incoming}'."
1011 # Remove remaining variables
1012 unset incoming PRVLOC
1017 # Complain if the package cannot be well-read
1019 is_readable
"$1" ||
exit 4
1021 # Complain if the package does not end in .tlz
1023 if ! fnmatch
'*.tlz' "$1"
1025 warn
"\`${1}' does not end in .tlz"
1029 # List content of files excluding directories
1032 tarlz
-tvvf "$1" |
awk '!/^drwx/'
1041 # Perform sanity checks before package extraction
1043 is_readable
"$1" ||
exit 4
1046 warn
"\`${1}' is not a regular file."
1050 # Preparations to extract the package
1052 name
=$
(basename -- "$1" .tlz
)
1054 # Set random directory using 'name' as prefix
1055 PRVDIR
="${TMPDIR}/${name}.${RANDOM-0}$$"
1057 # Trap to remove 'PRVDIR' on disruptions
1058 trap "rm -rf -- $PRVDIR" HUP INT ABRT TERM
1060 # Create 'PRVDIR' removing access for all but user
1061 ( umask 077 ; mkdir
-- $PRVDIR )
1062 mkdir
-p -m 700 -- $PRVDIR
1064 echo "Extracting package $name ..."
1065 ( umask 000 ; cd -- $PRVDIR && tarlz
-xvf - ) < "$1"
1068 # Try to remove (empty) 'PRVDIR' on failure
1072 echo "$name has been extracted on $PRVDIR"
1074 # Reset given signals
1075 trap - HUP INT ABRT TERM
1077 # Remove used variables
1081 #### Extra functions used in the modes
1085 string
=$
(basename -- "$1" .tlz
)
1087 # Match cases to print the package name.
1089 # We will take into account the four segments removing
1090 # the last two to print the package (long) name
1093 echo "${string%-*-*}"
1109 tar -tf "$file" > /dev
/null
&& \
1113 *.
tar.gz |
*.tgz |
*.
tar.Z
)
1114 gzip -cd "$file" |
tar -tf - > /dev
/null
&& \
1115 gzip -cd "$file" |
tar -xpf -
1118 *.
tar.bz2 |
*.tbz2 |
*.tbz
)
1119 bzip2 -cd "$file" |
tar -tf - > /dev
/null
&& \
1120 bzip2 -cd "$file" |
tar -xpf -
1124 tarlz
-tf "$file" > /dev
/null
&& \
1129 xz
-cd "$file" |
tar -tf - > /dev
/null
&& \
1130 xz
-cd "$file" |
tar -xpf -
1134 unzip -t "$file" > /dev
/null
&& \
1135 unzip "$file" > /dev
/null
1139 gzip -t "$file" && \
1140 gzip -cd "$file" > "$(basename -- $file .gz)"
1144 gzip -t "$file" && \
1145 gzip -cd "$file" > "$(basename -- $file .Z)"
1149 bzip2 -t "$file" && \
1150 bzip2 -cd "$file" > "$(basename -- $file .bz2)"
1154 lzip
-t "$file" && \
1155 lzip
-cd "$file" > "$(basename -- $file .lz)"
1160 xz
-cd "$file" > "$(basename -- $file .xz)"
1164 warn
"${PROGRAM}: cannot unpack ${file}: Unsupported extension"
1173 # Extract information from the recipe to create the meta file.
1175 # The package description is pre-formatted in 78 columns,
1176 # the '#' character and a space is added as prefix to conform
1177 # 80 columns in total
1180 $(echo "$description" | fold -w 78 | awk '$0="# " $0')
1182 QICFLAGS="$QICFLAGS"
1183 QICXXFLAGS="$QICXXFLAGS"
1184 QILDFLAGS="$QILDFLAGS"
1188 blurb="$(echo "$description" | sed -e '/^$/d;2q')"
1189 homepage="$homepage"
1200 packagedir
=@PACKAGEDIR@
1201 targetdir
=@TARGETDIR@
1202 blacklist
="perl graft tarlz plzip musl glibc"
1204 RCFILE
=@SYSCONFDIR@
/qirc
1205 opt_install
=opt_install.off
1206 opt_update
=opt_update.off
1207 opt_force
=opt_force.off
1208 opt_keep
=opt_keep.off
1209 opt_incr_release
=opt_incr_release.off
1210 opt_skipqsts
=opt_skipqsts.off
1211 opt_nopkg
=opt_nopkg.off
1212 opt_prune
=opt_prune.off
1219 _isUpgrade
=_isUpgrade.off
1220 TMPDIR
="${TMPDIR:=/usr/src/qi/build}"
1221 QICFLAGS
="${QICFLAGS:=-g0 -Os}"
1222 QICXXFLAGS
="${QICXXFLAGS:=$QICFLAGS}"
1223 QILDFLAGS
="${QILDFLAGS:=-s}"
1224 worktree
=/usr
/src
/qi
1225 tardir
=${worktree}/sources
1226 outdir
=/var
/cache
/qi
/packages
1227 netget
="wget -c -w1 -t3 --no-check-certificate"
1228 rsync
="rsync -v -a -L -z -i --progress"
1229 configure_args
="--prefix=@PREFIX@ --libexecdir=@LIBEXECDIR@ --bindir=@BINDIR@ --sbindir=@SBINDIR@ --sysconfdir=@SYSCONFDIR@ --localstatedir=@LOCALSTATEDIR@"
1234 # Store (default) directory locations
1235 QI_TARGETDIR
=$targetdir
1236 QI_PACKAGEDIR
=$packagedir
1237 QI_WORKTREE
=$worktree
1243 while getopts :bcdiouwxLNP
:t
:fkvO
:W
:Z
:a
:j
:1nSpr
:hV name
1266 if test "$mode" = build_mode
1268 opt_install
=opt_install
1280 if test "$mode" = build_mode
1282 opt_update
=opt_update
1293 "QI_TARGETDIR=$QI_TARGETDIR" \
1294 "QI_PACKAGEDIR=$QI_PACKAGEDIR" \
1295 "QI_WORKTREE=$QI_WORKTREE" \
1296 "QI_TARDIR=$QI_TARDIR" \
1297 "QI_OUTDIR=$QI_OUTDIR"
1304 packagedir
="$OPTARG"
1316 verbose
=$
(( verbose
+ 1 ))
1334 opt_incr_release
=opt_incr_release
1340 opt_skipqsts
=opt_skipqsts
1357 warn
"Option '-${OPTARG}' requires an argument"
1362 warn
"Illegal option -- '-${OPTARG}'"
1368 shift $
(( OPTIND
- 1 ))
1376 # Program sanity check
1377 for need
in awk basename chmod cp dirname find fold graft
grep \
1378 mkdir mktemp
rm rmdir sed sha256sum stat tarlz
1380 if ! type $need 1> /dev
/null
2> /dev
/null
1382 warn
"${PROGRAM}: cannot operate without ${need}(1): Check your PATH"
1388 # Determine verbosity level/flag
1390 if test "$verbose" -gt 1
1395 # Read standard input if FILE is -, or when FILE
1396 # is not connected to a terminal.
1398 if test "$1" = - ||
test ! -t 0
1400 # Unset positional parameters setting $# to zero
1403 # Assign remaining arguments to the positional parameters
1406 set -- "$@" "$input"
1410 # We need at least one operating mode
1417 umask 022; # Remove write permission for group and other.
1419 # Validate 'rootdir' directory
1421 if test -n "$rootdir"
1423 if test -d "$rootdir" && test "$rootdir" != /
1425 # Remove slash from the end
1426 rootdir
="${rootdir%/}"
1428 # A workaround for graft-2.13+. The specified directory is
1429 # relative to the log file, we prepend it inside the rootdir
1431 eval "$(graft -L)" ; GRAFT_LOGFILE
="${GRAFT_LOGFILE:=/var/log/graft}"
1432 mkdir
-p -- "$rootdir$(dirname -- $GRAFT_LOGFILE)" || chkstatus_or_exit
1434 # Compose 'rootdir' and log file option to be used with graft(1)
1435 graft_r
="-r $rootdir -l $GRAFT_LOGFILE"
1437 # Unset variables coming from eval
1438 unset GRAFT_PERL GRAFT_LOGFILE GRAFT_TARGETDIR GRAFT_PACKAGEDIR
1440 warn
"${PROGRAM}: \`${rootdir}' is not a qualified root directory"
1446 # Ensure 'TMPDIR' creation to prefix temporary files
1448 if test ! -d "$TMPDIR"
1450 mkdir
-p -- "$TMPDIR" || chkstatus_or_exit
1454 # Process each package or recipe provided on the command-line