2 # Copyright (C) 2016-2020 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 user-friendly package manager." \
34 "Usage: $PROGRAM [OPTION...] [FILE]..." \
37 " -b Build packages using recipe names" \
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 linked" \
44 " -x Extract a package for debugging purposes" \
47 " -N Do not read the configuration file" \
48 " -P <DIR> Package directory for installations." \
49 " Only valid for -i, -d, or -u options" \
50 " -f This option can force the build of a recipe," \
51 " or force the update of a pre-existing package." \
52 " Only valid for -b, -u options" \
53 " -t <DIR> Target directory for symbolic links." \
54 " Only valid for -i, -d, or -u options" \
55 " -k Keep \`\${srcdir}' or \`\${destdir}' in build mode," \
56 " keep package directory in delete mode." \
57 " Only valid for -b, -d or -u options" \
58 " -p Prune conflicts on package installations" \
59 " -r <DIR> Use the fully qualified named directory as the" \
60 " root directory for all qi operations. The target" \
61 " directory and package directory will be relative to" \
62 " the specified directory, including the log file for" \
64 " -v Be verbose (a 2nd -v gives more)" \
66 "Options for 'build' mode (-b):" \
67 " -O <DIR> Where the packages produced are written" \
68 " -W <DIR> Where archives, patches, and recipes are expected" \
69 " -Z <DIR> Where (compressed) sources will be found" \
70 " -a Architecture to use [detected]" \
71 " -j Parallel jobs for the compiler" \
72 " -1 Increment release number (\`\${release}' + 1)" \
73 " -n Don't create a .tlz package" \
74 " -S Selects the option to skip completed recipes" \
76 "Informative options:" \
77 " -L Print default directory locations" \
78 " -h Display this help and exit" \
79 " -V Output version information" \
81 "Some influential environment variables:" \
82 " TMPDIR Temporary directory for sources" \
83 " QICFLAGS C compiler flags" \
84 " QICXXFLAGS C++ compiler flags" \
85 " QILDFLAGS Linker flags" \
87 "When FILE is -, read standard input." \
94 "$PROGRAM @VERSION@" \
95 "Copyright (C) 2016-2020 Matias Andres Fonzo." \
96 "License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>" \
97 "This is free software: you are free to change and redistribute it." \
98 "There is NO WARRANTY, to the extent permitted by law."
103 printf "%s\n" "$@" 1>&2
112 echo "${PROGRAM}: cannot read ${1}: Permission denied" 1>&2
116 echo "${PROGRAM}: cannot access ${1}: No such file or directory" 1>&2
121 # Portable alternative to the file operator -nt (among shells)
124 if test -n "$(find $1 -prune -newer $2 -print)"
131 # Determine whether $2 matches pattern $1
148 if test $status -ne 0
150 echo "^ Return status = $status" 1>&2
151 exit ${1-2}; # If not given, defaults to 2
161 is_readable
"$HOME/.qirc" 2> /dev
/null
&& RCFILE
="$HOME/.qirc";
163 echo "Processing \`${RCFILE}' ..."
165 test -f "$RCFILE" ||
{
166 warn
"${RCFILE} is not a regular file."
171 while IFS
='=' read -r variable value
174 \
#* | "") # Ignore commented or blank lines
179 # Set variable name avoiding code execution
180 eval "$variable=\${value}"
191 # A recipe is any valid regular file. Qi sets priorities for reading a
192 # recipe, the order in which qi looks for a recipe is:
194 # 1. Current working directory.
196 # 2. If the specified path name does not contain "recipe" as the last
197 # component. Qi will complete it by adding "recipe" to the path
200 # 3. If the recipe is not in the current working directory, it will be
201 # searched under '${worktree}/recipes'. The last component will be
202 # completed adding "recipe" to the specified path name.
204 if test ! -f "$recipe"
206 if test -f "${recipe}/recipe"
208 recipe
="${recipe}/recipe"
209 elif test -f "${worktree}/recipes/${recipe}/recipe"
211 recipe
="${worktree}/recipes/${recipe}/recipe"
215 test -f "$recipe" ||
{
216 warn
"\`${recipe}' is not a regular file."
220 # Complain if the file name is not "recipe"
222 if test "${recipe##*/}" != recipe
224 warn
"\`${recipe}' is not a valid recipe name."
228 # Start preparations to import the recipe
230 # Get working directory and base name of the recipe
232 CWD
=$
(dirname -- "$recipe")
233 recipe
=$
(basename -- "$recipe")
235 # Check readability for load the recipe on success
237 is_readable
"${CWD}/$recipe" ||
exit 4
239 # Find target architecture if 'arch' is not set
242 arch
="$( ${CC:-cc} -dumpmachine 2> /dev/null )" || arch
=unknown
243 arch
="${arch%%-*}" # Get the rid of target triplet.
246 # Re-create external directories
247 mkdir
-p -- "${worktree}/archive" \
248 "${worktree}/patches" \
249 "${worktree}/recipes" \
252 # Variables treatment for the current and next recipe.
254 # Unset special variables that can only be predefined on
255 # the recipe and not coming from ${sysconfdir}/qirc
257 unset srcdir destdir pkgname pkgversion program version release \
258 fetch description homepage license replace full_pkgname \
259 CFLAGS CXXFLAGS LDFLAGS
261 # The following variables must be saved and restored
262 save_arch
="${save_arch:=$arch}"
263 save_jobs
="${save_jobs:=$jobs}"
264 save_outdir
="${save_outdir:=$outdir}"
265 save_opt_nopkg
="${save_opt_nopkg:=$opt_nopkg}"
267 # Reset variable values in case of return
271 opt_nopkg
=$save_opt_nopkg
273 # The following variables cannot be redefined on the recipe
274 readonly worktree netget rsync
278 echo "{@} Building from ${CWD}/$recipe ..."
282 # Check for required variables
283 if test -z "$program"
285 warn
"${recipe}: The variable 'program' is not defined."
288 if test -z "$version"
290 warn
"${recipe}: The variable 'version' is not defined."
293 if test -z "$release"
295 warn
"${recipe}: The variable 'release' is not defined."
299 # Pre-settings before to start building
301 # Increment the release number if the option was given
302 if test "$opt_incr_release" = opt_incr_release
304 release
=$
(( $release + 1 ))
307 # Allow the dot as definition for 'tardir'
308 if test "$tardir" = .
313 # Set default values for the following special variables
315 pkgname
="${pkgname:=$program}"
316 pkgversion
="${pkgversion:=$version}"
317 srcdir
="${srcdir:=${program}-$version}"
318 destdir
="${destdir:=${TMPDIR}/package-$pkgname}"
320 # Complete package name adding 'pkgversion-arch+release'
321 full_pkgname
="${full_pkgname:=$pkgname-${pkgversion}-${arch}+${release}}"
323 # If a package is going to be created, the existence of a
324 # previous build will be detected and reported. Under normal
325 # conditions the recipe is built as long as it is newer than
326 # the produced package, if not, we warn to the user about it.
327 # Rebuilding the package is possible (through the force ;-)
329 if test "$opt_nopkg" != opt_nopkg
&& \
330 { test "$opt_force" != opt_force
&& \
331 test -e "${outdir}/${full_pkgname}.tlz" ; }
333 if is_newer "${CWD}/$recipe" "${outdir}/${full_pkgname}.tlz
"
337 "The recipe is
more RECENT than the detected package
:" \
339 "$
( stat
-c "%y %n" "${CWD}/$recipe" )" \
340 "$
( stat
-c "%y %n" "${outdir}/${full_pkgname}.tlz" )" \
342 " This recipe will be processed ...
" \
344 elif test -e "${CWD}/post-install
" && \
345 is_newer "${CWD}/post-install
" "${CWD}/$recipe"
349 "The post-install
script is
more RECENT than the recipe
:" \
351 "$
( stat
-c "%y %n" "${CWD}/post-install" )" \
352 "$
( stat
-c "%y %n" "${CWD}/$recipe" )" \
354 " The recipe will be re-processed ...
" \
356 touch "${CWD}/$recipe"
357 elif test "$opt_skipqsts" = opt_skipqsts
359 warn "Recipe
for '${full_pkgname}.tlz': Ignored.
" ""
364 "This recipe ALREADY produced a package
:" \
365 "$
( stat
-c "%y %n" "${outdir}/${full_pkgname}.tlz" )" \
367 "The recipe is still OLDER than the produced package
:" \
368 "$
( stat
-c "%y %n" "${CWD}/$recipe" )" \
370 " Probably nothing has changed.
" \
373 # In non-interactive mode, the user is asked about
374 # rebuilding the package. In interactive mode,
375 # the user need to pass the option explicitly
379 "Do you want to rebuild this package?
" \
381 "2) No
, skip it
[default
]" \
382 "3) Resume
, skipping completed recipes
" \
383 "Enter an option number
:" > /dev/tty
384 IFS= read -r ANSWER < /dev/tty || exit 2;
387 echo "$ANSWER" > /dev/tty
392 echo "Building UNPROCESSED
/MODIFIED recipes ...
" > /dev/tty
394 opt_skipqsts=opt_skipqsts
395 readonly opt_skipqsts
400 echo "Recipe
for '${full_pkgname}.tlz': Cancelled.
" > /dev/tty
406 warn "Use the
-f option to reprocess
${CWD}/$recipe.
" ""
412 # Fetch remote sources
414 echo "Fetching remote sources
if needed ...
"
419 _source="${origin##*/}"
421 echo "Looking
for \"$_source\" ...
"
423 echo "Verifying checksum
file \"${_source}.sha256
\" from
'${tardir}'"
424 if test -e "${tardir}/${_source}.sha256
"
426 ( cd -- "$tardir" && sha256sum - ) < "${tardir}/${_source}.sha256
"
430 warn "${_source}.sha256
: Checksum
file does not exist
, yet.
"
433 # Download source or resume if allowed
435 if test ! -e "${tardir}/$_source"
437 warn " Can
't find $_source in ${tardir};" \
438 "attempting to get it from ${origin%/*} ..."
444 cd -- "$tardir" && $rsync $origin || exit $?
445 sha256sum $_source > ${_source}.sha256
446 ); chkstatus_or_exit 10
450 cd -- "$tardir" && $netget $origin || exit $?
451 sha256sum $_source > ${_source}.sha256
452 ); chkstatus_or_exit 10
455 warn "${PROGRAM}: Unrecognized protocol for ${origin}."
461 warn "The variable 'fetch
' is empty."
464 # Prepare special directories for build the source,
465 # the destination and the output of the package
467 echo "Preparing directories ..."
469 if test -d "${TMPDIR}/$srcdir" && test -z "$keep_srcdir"
471 rm -rf -- "${TMPDIR}/$srcdir" || chkstatus_or_exit
472 echo "removed directory: '${TMPDIR}/$srcdir'"
475 if test -d "$destdir"
477 rm -rf -- "$destdir" || chkstatus_or_exit
478 echo "removed directory: '$destdir'"
480 mkdir -p -- "$destdir" || chkstatus_or_exit
481 echo "mkdir: created directory '$destdir'"
483 if test ! -d "$outdir"
485 mkdir -p -- "$outdir" || chkstatus_or_exit
486 echo "mkdir: created directory '$outdir'"
489 echo "Entering to 'TMPDIR
': $TMPDIR ..."
490 cd -- "$TMPDIR" || chkstatus_or_exit
492 # Set trap before to run the build() function in order
493 # to catch the return status, exit code 2 if fails
495 trap 'chkstatus_or_exit
2' EXIT HUP INT QUIT ABRT TERM
497 # Determine if the debugging indicators of the shell should be
498 # retained, assuming that it has been previously passed
500 _xtrace_flag=_xtrace_flag_is_set ;;
503 echo "Running build() ..."
507 # Turn off possible shell flags coming from the recipe
510 if test "${_xtrace_flag:+$_xtrace_flag}" != _xtrace_flag_is_set
515 # Reset given signals
516 trap - EXIT HUP INT QUIT ABRT TERM
518 # If 'destdir
' is empty, the package won't be created
519 if rmdir -- "$destdir" 2> /dev
/null
521 warn
"The package \"${full_pkgname}.tlz\" won't be created. 'destdir' is empty."
525 # Create (make) the package
527 if test "$opt_nopkg" != opt_nopkg
529 # Edit the recipe when 'release' is incremented
530 if test "$opt_incr_release" = opt_incr_release
532 echo ",s/^\(release\)=.*/\1=${release}/"$
'\nw' | \
533 ed
"${CWD}/$recipe" || chkstatus_or_exit
536 mkdir
-p -- "${destdir}/var/lib/qi" || chkstatus_or_exit
538 # Include a recipe copy into the package
539 cp -p "${CWD}/$recipe" \
540 "${destdir}/var/lib/qi/${full_pkgname}.recipe" && \
541 chmod 644 "${destdir}/var/lib/qi/${full_pkgname}.recipe" || chkstatus_or_exit
543 # Detect post-install script for inclusion
545 if test -f "${CWD}/post-install"
547 echo "${CWD}/post-install: Detected."
548 cp -p "${CWD}/post-install" \
549 "${destdir}/var/lib/qi/${full_pkgname}.sh" && \
550 chmod 644 "${destdir}/var/lib/qi/${full_pkgname}.sh" || chkstatus_or_exit
553 # Detect declared package names for later replacement
555 if test -n "$replace"
558 "The following package names has been declared for replacement:" \
561 rm -f "${destdir}/var/lib/qi/${full_pkgname}.replace"
564 echo "$replace" >> "${destdir}/var/lib/qi/${full_pkgname}.replace"
569 # Create meta file for package information
570 echo "Creating meta file ${full_pkgname}.tlz.txt ..."
571 do_meta
> "${outdir}/${full_pkgname}.tlz.txt" || chkstatus_or_exit
573 # Make a copy of it for the database
574 cp -p "${outdir}/${full_pkgname}.tlz.txt" \
575 "${destdir}/var/lib/qi/${full_pkgname}.txt" || chkstatus_or_exit
577 # Produce the package
578 cd -- "$destdir" && create_mode
"${outdir}/${full_pkgname}.tlz"
581 # Back to the current working directory
582 cd -- "$CWD" || chkstatus_or_exit
584 # Delete 'srcdir' or 'destdir' if -k was not given
585 if test "$opt_keep" != opt_keep
587 echo "Deleting temporary directories ..."
589 srcdir
="${srcdir%%/*}" # Directory name without parents.
591 if test -r "${TMPDIR}/$srcdir"
593 if test -z "$keep_srcdir"
596 cd -- "$TMPDIR" && rm -rf -- "$srcdir" && \
597 echo "removed directory: '${TMPDIR}/${srcdir}'"
600 warn
"The variable 'keep_srcdir' has been set;" \
601 "'${TMPDIR}/${srcdir}' will not be deleted."
605 if test -r "$destdir"
607 rm -rf -- "$destdir" || chkstatus_or_exit
608 echo "removed directory: '$destdir'"
612 # Install or update the package if -i or -u was passed
613 if test "$opt_nopkg" != opt_nopkg
615 if test "$opt_install" = opt_install
617 install_mode
"${outdir}/${full_pkgname}.tlz"
618 elif test "$opt_update" = opt_update
620 upgrade_mode
"${outdir}/${full_pkgname}.tlz"
625 echo "All done for ${CWD}/${recipe}."
631 directory
=$
(dirname -- "$1")
633 # Perform sanity checks
635 if ! fnmatch
'/?*' "$directory"
637 warn
"${PROGRAM}: Output directory \`${directory}' is not fully qualified"
640 is_readable
"$directory" ||
exit 4
642 name
=$
(basename -- "$1")
644 if test "$name" = "${name%.tlz}"
646 warn
"Package format '$name' not supported." \
647 "It should be \"name-version-architecture+release.tlz\""
651 echo "{#} Creating package $name ..."
653 ( umask 022 ; tarlz
--solid -9 -cvf - * ) > "${directory}/$name"
656 ( cd -- "$directory" && sha256sum
$name > ${name}.sha256
)
659 echo "Package created on \`${directory}/${name}'."
662 # Remove used variables
668 expunge
="${packagedir}/$(basename -- $1 .tlz)"
670 echo "{<} Deleting package $rootdir${expunge} ..."
672 # Complain if the package directory does not exist
674 test -d "$rootdir${expunge}" ||
{
675 warn
"Package directory '$rootdir${expunge}' does not exist."
679 # Complain if the package directory cannot be well-read
681 is_readable
"$rootdir${expunge}" ||
exit 4
683 # Remove package from Graft control
685 # Scan for possible conflicts, stop if arise
686 if test "$opt_prune" != opt_prune
688 echo "Checking for possible conflicts ..."
689 if graft
-d -n $graft_r -t "$targetdir" "$expunge" 2>&1 | \
693 " A conflict occurred during uninstallation;" \
694 "Unless the -p option is given, this package will be PRESERVED."
699 # Ignore some signals up to completing the deinstallation
700 trap "" HUP INT QUIT ABRT TERM
702 # Remove objects (files, links or directories) from the target
703 # directory that are in conflict with the package directory
705 echo "Pruning any conflict ..."
706 graft
-p -D -u $graft_r -t "$targetdir" "$expunge"
709 echo "Disabling links ..."
710 graft
-d -D -u $graft_v $graft_r -t "$targetdir" "$expunge"
713 # Delete package directory
714 if test "$opt_keep" != opt_keep
716 echo "Deleting package directory, if it exists as such ..."
718 if test -d "${rootdir}$expunge"
720 rm -rf -- "${rootdir}$expunge" || chkstatus_or_exit
721 echo "removed directory: '${rootdir}$expunge'"
725 # Reset given signals
726 trap - HUP INT QUIT ABRT TERM
728 # Remove used variables
734 # Complain if the package cannot be well-read
736 is_readable
"$1" ||
exit 4
738 # Complain if the package does not end in .tlz
740 if ! fnmatch
'*.tlz' "$1"
742 warn
"\`${1}' does not end in .tlz"
746 # Make preparations to install the package
748 echo "{>} Installing package $1 ..."
751 name
=$
(basename -- "$1" .tlz
)
753 echo "Checking tarball integrity ..."
754 tarlz
-tf "$1" > /dev
/null
757 # Create package directory using 'name'
758 if ! test -d "$rootdir${packagedir}/$name"
760 mkdir
-p -- "$rootdir${packagedir}/$name" || chkstatus_or_exit
761 echo "mkdir: created directory '$rootdir${packagedir}/$name'"
764 # Scan for possible conflicts, stop if arise
765 if test "$opt_prune" != opt_prune
767 echo "Checking for possible conflicts ..."
768 if graft
-i -n $graft_r -t "$targetdir" "${packagedir}/$name" 2>&1 | \
772 " A conflict occurred during installation;" \
773 "Unless the -p option is given, this package won't be LINKED."
778 # Ignore some signals up to completing the installation
779 trap "" HUP INT QUIT ABRT TERM
781 echo "Decompressing $1 ..."
782 ( cd -- "$rootdir${packagedir}/$name" && tarlz
-xf - ) < "$1"
785 # Transite package to Graft control
787 # Remove objects (files, links or directories) from the target
788 # directory that are in conflict with the package directory
789 echo "Pruning any conflict ..."
790 graft
-p -D -u $graft_r -t "$targetdir" "${packagedir}/$name"
793 echo "Enabling symbolic links ..."
794 graft
-i -P $graft_v $graft_r -t "$targetdir" "${packagedir}/$name"
797 # Avoid unnecessary runs coming from the upgrade_mode(),
798 # this is when the incoming package is **pre-installed**
800 if test "$_isUpgrade" != _isUpgrade.on
802 # Show package description
803 if test -r "$rootdir${packagedir}/${name}/var/lib/qi/${name}.txt"
805 grep '^#' "$rootdir${packagedir}/${name}/var/lib/qi/${name}.txt"
806 elif test -r "${1}.txt"
808 # From external meta file (current directory)
811 warn
"Description file not found for '$name'."
814 # Check and run the post-install script if exist
815 if test -r "$rootdir${packagedir}/${name}/var/lib/qi/${name}.sh"
817 echo "Running post-install script for \`${name}' ..."
819 # Rely on 'targetdir' if 'rootdir' is empty
820 cd -- "${rootdir:-$targetdir}"/ && \
821 .
"$rootdir${packagedir}/${name}/var/lib/qi/${name}.sh"
825 # Check if there are declared packages for replacement
826 if test -r "$rootdir${packagedir}/${name}/var/lib/qi/${name}.replace"
830 for replace
in "$rootdir${packagedir}/$(pkgbase $line)"-*
832 if ! test -e "$replace"
834 warn
"${replace}: Declared package does not exist. (ignored)"
838 replace
="${replace##*/}"
840 # The search for the package to be replaced cannot
841 # be the same to the incoming package, even to the
842 # temporary location coming from the upgrade_mode()
843 if test "$replace" = "$name" ||
test "$replace" = "${PRVLOC##*/}"
848 warn
"WARNING: Replacing package \`${replace}' ..."
850 # Since the links belongs to the new package, only
851 # those which are not in conflict can be deleted.
852 # To complete, we will remove the package directory
854 graft
-d -D -u $graft_r \
855 -t "$targetdir" "$replace" > /dev
/null
2>&1
857 rm -rf -- "$rootdir${packagedir}/$replace"
859 done < "$rootdir${packagedir}/${name}/var/lib/qi/${name}.replace"
864 # Reset given signals
865 trap - HUP INT QUIT ABRT TERM
867 # Remove used variables
872 # Complain if the file cannot be well-read
874 is_readable
"$1" ||
exit 4
876 # Complain if the file does not end in .order
878 if ! fnmatch
'*.order' "$1"
880 warn
"\`${1}' does not end in .order"
884 # Get a clean list of the file while printing its contents in reverse
885 # order. The last `awk 'in the pipeline eliminates the non-consecutive
886 # lines, the duplicates. Blank lines, colons and parentheses are
887 # simply ignored, comment lines beginning with '#' are allowed
890 '{ gsub( /:|^#(.*)$|\([^)]*)|^$/,"" ); for( i=NF; i > 0; i-- ) print $i }' \
891 "$1" |
awk '!s[$0]++'
896 # Complain if the package does not end in .tlz
898 if ! fnmatch
'*.tlz' "$1"
900 warn
"\`${1}' does not end in .tlz"
905 incoming
=$
(basename -- "$1" .tlz
)
907 echo "{^} Upgrading to $incoming ..."
909 # Check packages in the blacklist for installation
911 echo "Checking blacklist ..."
912 for item
in $blacklist
916 if test ! -e "$rootdir${packagedir}/$incoming"
920 " The package declared in the blacklist will be" \
921 "installed instead of being updated ..." \
923 opt_prune
=opt_prune install_mode
"$1"
927 if is_newer
"$1" "$rootdir${packagedir}/$incoming"
931 "Incoming package is more RECENT than the installed package:" \
933 "$( stat -c "%y
%n
" "$1" )" \
934 "$( stat -c "%y
%n
" "$rootdir${packagedir}/$incoming" )" \
936 " The package declared in the blacklist will be" \
937 " installed as part of the upgrade process ..." \
939 opt_prune
=opt_prune install_mode
"$1"
940 touch "$rootdir${packagedir}/$incoming"
945 "Blacklisted package is already up-to-date:" \
947 "$( stat -c "%y
%n
" "$rootdir${packagedir}/$incoming" )" \
948 "$( stat -c "%y
%n
" "$1" )" \
957 # Check package pre-existence
958 if test "$opt_force" != opt_force
&& \
959 test -e "$rootdir${packagedir}/$incoming"
963 " The package to be updated already exist;" \
964 "Unless the -f option is given, this package won't be UPGRADED."
968 # Prepare the package to install it in a temporary location
970 # Set random directory using packagedir as prefix and 'incoming' as suffix
971 PRVLOC
=$
(mktemp
-dp "$rootdir${packagedir}" ${incoming}.XXXXXXXXXXXX
) ||
exit 2
973 # Pre-install the package in the custom 'packagedir'
975 save_packagedir
="$rootdir${packagedir}"
978 echo "Pre-installing package in a temporary location ..."
979 opt_prune
=opt_prune
# Turn on prune operation.
980 _isUpgrade
=_isUpgrade.on install_mode
"$1" > /dev
/null
981 _isUpgrade
=_isUpgrade.off
983 # Restore variable before looking for old packages
984 packagedir
=$save_packagedir
985 unset save_packagedir
987 echo "Looking for installations under the same name ..."
988 for long_name
in "$rootdir${packagedir}/$(pkgbase $incoming)"*
990 found
="${long_name##*/}"
992 # The search for the package to be deleted
993 # cannot be the same to the temporary location
994 test "$long_name" = "$PRVLOC" && continue;
996 fnmatch
"$(pkgbase $found)*" "$incoming" ||
continue;
997 echo "${long_name}: Detected."
999 # A package directory is preserved if -k is given
1000 delete_mode
"$found" > /dev
/null
1002 unset long_name found
1004 # Re-install the package removing the temporary location
1007 opt_prune
=opt_prune.off
# Turn off prune operation.
1009 echo "Deleting temporary location ..."
1010 rm -rf -- "$PRVLOC" || chkstatus_or_exit
1011 echo "removed directory: '$PRVLOC'"
1014 echo "Successful upgrade to '${incoming}'."
1016 # Remove remaining variables
1017 unset incoming PRVLOC
1022 # Complain if the package cannot be well-read
1024 is_readable
"$1" ||
exit 4
1026 # Complain if the package does not end in .tlz
1028 if ! fnmatch
'*.tlz' "$1"
1030 warn
"\`${1}' does not end in .tlz"
1034 # List content of files excluding directories
1037 tarlz
-tvvf "$1" |
awk '!/^drwx/'
1046 # Perform sanity checks before package extraction
1048 is_readable
"$1" ||
exit 4
1051 warn
"\`${1}' is not a regular file."
1055 # Preparations to extract the package
1057 name
=$
(basename -- "$1" .tlz
)
1059 # Set random directory using 'name' as prefix
1060 PRVDIR
="${TMPDIR}/${name}.${RANDOM-0}$$"
1062 # Trap to remove 'PRVDIR' on disruptions
1063 trap "rm -rf -- $PRVDIR" HUP INT ABRT TERM
1065 # Create 'PRVDIR' removing access for all but user
1066 ( umask 077 ; mkdir
-- $PRVDIR )
1067 mkdir
-p -m 700 -- $PRVDIR
1069 echo "Extracting package $name ..."
1070 ( umask 000 ; cd -- $PRVDIR && tarlz
-xvf - ) < "$1"
1073 # Try to remove (empty) 'PRVDIR' on failure
1077 echo "$name has been extracted on $PRVDIR"
1079 # Reset given signals
1080 trap - HUP INT ABRT TERM
1082 # Remove used variables
1086 #### Extra functions used in the modes
1090 string
=$
(basename -- "$1" .tlz
)
1092 # Match cases to print the package name.
1094 # We will take into account the four segments removing
1095 # the last two to print the package (long) name
1098 echo "${string%-*-*}"
1114 tar -tf "$file" > /dev
/null
&& \
1118 *.
tar.gz |
*.tgz |
*.
tar.Z
)
1119 gzip -cd "$file" |
tar -tf - > /dev
/null
&& \
1120 gzip -cd "$file" |
tar -xpf -
1123 *.
tar.bz2 |
*.tbz2 |
*.tbz
)
1124 bzip2 -cd "$file" |
tar -tf - > /dev
/null
&& \
1125 bzip2 -cd "$file" |
tar -xpf -
1129 lzip
-cd "$file" |
tar -tf - > /dev
/null
&& \
1130 lzip
-cd "$file" |
tar -xpf -
1134 xz
-cd "$file" |
tar -tf - > /dev
/null
&& \
1135 xz
-cd "$file" |
tar -xpf -
1139 unzip -t "$file" > /dev
/null
&& \
1140 unzip "$file" > /dev
/null
1144 gzip -t "$file" && \
1145 gzip -cd "$file" > "$(basename -- $file .gz)"
1149 gzip -t "$file" && \
1150 gzip -cd "$file" > "$(basename -- $file .Z)"
1154 bzip2 -t "$file" && \
1155 bzip2 -cd "$file" > "$(basename -- $file .bz2)"
1159 lzip
-t "$file" && \
1160 lzip
-cd "$file" > "$(basename -- $file .lz)"
1165 xz
-cd "$file" > "$(basename -- $file .xz)"
1169 warn
"${PROGRAM}: cannot unpack ${file}: Unsupported extension"
1178 # Extract information from the recipe to create the meta file.
1180 # The package description is pre-formatted in 78 columns,
1181 # the '#' character and a space is added as prefix to conform
1182 # 80 columns in total
1185 $(echo "$description" | fold -w 78 | awk '$0="# " $0')
1187 QICFLAGS="$QICFLAGS"
1188 QICXXFLAGS="$QICXXFLAGS"
1189 QILDFLAGS="$QILDFLAGS"
1191 pkgversion=$pkgversion
1194 blurb="$(echo "$description" | sed -e '/^$/d;2q')"
1195 homepage="$homepage"
1206 packagedir
=@PACKAGEDIR@
1207 targetdir
=@TARGETDIR@
1208 blacklist
="perl5 graft tarlz plzip musl glibc"
1210 RCFILE
=@SYSCONFDIR@
/qirc
1211 opt_install
=opt_install.off
1212 opt_update
=opt_update.off
1213 opt_force
=opt_force.off
1214 opt_keep
=opt_keep.off
1215 opt_incr_release
=opt_incr_release.off
1216 opt_skipqsts
=opt_skipqsts.off
1217 opt_nopkg
=opt_nopkg.off
1218 opt_prune
=opt_prune.off
1225 _isUpgrade
=_isUpgrade.off
1226 TMPDIR
="${TMPDIR:=/usr/src/qi/build}"
1227 QICFLAGS
="${QICFLAGS:=-g0 -Os}"
1228 QICXXFLAGS
="${QICXXFLAGS:=$QICFLAGS}"
1229 QILDFLAGS
="${QILDFLAGS:=-s}"
1230 worktree
=/usr
/src
/qi
1231 tardir
=${worktree}/sources
1232 outdir
=/var
/cache
/qi
/packages
1233 netget
="wget -c -w1 -t3 --no-check-certificate"
1234 rsync
="rsync -v -a -L -z -i --progress"
1235 configure_args
="--prefix=@PREFIX@ --libexecdir=@LIBEXECDIR@ --bindir=@BINDIR@ --sbindir=@SBINDIR@ --sysconfdir=@SYSCONFDIR@ --localstatedir=@LOCALSTATEDIR@"
1240 # Store (default) directory locations
1241 QI_TARGETDIR
=$targetdir
1242 QI_PACKAGEDIR
=$packagedir
1243 QI_WORKTREE
=$worktree
1249 while getopts :bcdiouwxLNP
:t
:fkvO
:W
:Z
:a
:j
:1nSpr
:hV name
1272 if test "$mode" = build_mode
1274 opt_install
=opt_install
1286 if test "$mode" = build_mode
1288 opt_update
=opt_update
1299 "QI_TARGETDIR=$QI_TARGETDIR" \
1300 "QI_PACKAGEDIR=$QI_PACKAGEDIR" \
1301 "QI_WORKTREE=$QI_WORKTREE" \
1302 "QI_TARDIR=$QI_TARDIR" \
1303 "QI_OUTDIR=$QI_OUTDIR"
1310 packagedir
="$OPTARG"
1322 verbose
=$
(( verbose
+ 1 ))
1340 opt_incr_release
=opt_incr_release
1346 opt_skipqsts
=opt_skipqsts
1363 warn
"Option '-${OPTARG}' requires an argument"
1368 warn
"Illegal option -- '-${OPTARG}'"
1374 shift $
(( OPTIND
- 1 ))
1382 # Program sanity check
1383 for need
in awk basename chmod cp dirname find fold graft
grep \
1384 mkdir mktemp
rm rmdir sed sha256sum stat tarlz
1386 if ! type $need > /dev
/null
1388 warn
"${PROGRAM}: Prerequisite \`${need}' not found in PATH"
1394 # Determine verbosity level/flag
1396 if test "$verbose" -gt 1
1401 # Read standard input if FILE is -, or when
1402 # FILE is not connected to a terminal.
1404 if test "$1" = - ||
test ! -t 0
1406 # Unset positional parameters setting $# to zero
1409 # Assign remaining arguments to the positional parameters
1412 set -- "$@" "$input"
1416 # We need at least one operating mode
1423 umask 022; # Remove write permission for group and other.
1425 # Validate 'packagedir' and 'targetdir' as canonical directories
1427 # The single slash '/' does not qualify here
1428 if ! fnmatch
'/?*' "$packagedir"
1430 warn
"${PROGRAM}: Package directory \`${packagedir}' is not fully qualified"
1433 if test ! -d "$packagedir"
1435 warn
"${PROGRAM}: Package directory \`${packagedir}' does not exist"
1439 # The single slash '/' is valid here
1440 if ! fnmatch
'/*' "$targetdir"
1442 warn
"${PROGRAM}: Target directory \`${targetdir}' is not fully qualified"
1445 if test ! -d "$targetdir"
1447 warn
"${PROGRAM}: Target directory \`${targetdir}' does not exist"
1451 # Validate 'rootdir' directory
1453 if test -n "$rootdir"
1455 if test -d "$rootdir" && test "$rootdir" != /
1457 # Remove slash from the end
1458 rootdir
="${rootdir%/}"
1460 # A workaround for graft-2.13+. The specified directory is
1461 # relative to the log file, we prepend it inside the rootdir
1463 eval "$(graft -L)" ; GRAFT_LOGFILE
="${GRAFT_LOGFILE:=/var/log/graft}"
1464 mkdir
-p -- "$rootdir$(dirname -- $GRAFT_LOGFILE)" || chkstatus_or_exit
1466 # Compose 'rootdir' and log file option to be used with graft(1)
1467 graft_r
="-r $rootdir -l $GRAFT_LOGFILE"
1469 # Unset variables coming from eval
1470 unset GRAFT_PERL GRAFT_LOGFILE GRAFT_TARGETDIR GRAFT_PACKAGEDIR
1472 warn
"${PROGRAM}: Root directory \`${rootdir}' is not fully qualified"
1478 # Ensure 'TMPDIR' creation to prefix temporary files
1480 if test ! -d "$TMPDIR"
1482 mkdir
-p -- "$TMPDIR" || chkstatus_or_exit
1486 # Process each package or recipe provided on the command-line