2 # Copyright (C) 2016-2018 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 " -x Extract packages for debugging purposes" \
46 " -L Print and exit default directory locations" \
47 " -N Don't read the configuration file" \
48 " -P <DIR> Package directory for (de)installations;" \
49 " only valid for -i, -d, or -u options" \
50 " -t <DIR> Target directory for symbolic links;" \
51 " only valid for -i, -d, or -u options" \
52 " -k Keep (don't delete) srcdir or destdir" \
53 " Keep (don't delete) package directory" \
54 " this is for -b, -d or -u options" \
55 " -p Prune conflicts on package (de)installation" \
56 " -r Use the named directory as the root directory" \
57 " for installing, deleting, or upgrading packages." \
58 " The target directory, package directory will be" \
59 " relative to this specific directory" \
60 " -v Be verbose (a 2nd -v gives more)" \
62 "Options for 'build' mode (-b):" \
63 " -O <DIR> Where the produced packages are written" \
64 " -W <DIR> Where archives, patches, and recipes are expected" \
65 " -Z <DIR> Where (compressed) sources will be found" \
66 " -a Architecture to use [detected]" \
67 " -f Force proceeding with a recipe" \
68 " -j Parallel jobs for the compiler" \
69 " -1 Increment release number (release + 1)" \
70 " -3 Resume skipping completed recipes option" \
71 " -n Don't create a .tlz package" \
74 " -h Display this help and exit" \
75 " -V Output version information" \
77 "Some influential environment variables:" \
78 " TMPDIR Temporary directory for sources" \
79 " QICFLAGS C compiler flags" \
80 " QICXXFLAGS C++ compiler flags" \
81 " QILDFLAGS Linker flags" \
83 "When FILE is -, read standard input." \
90 "$PROGRAM @VERSION@" \
91 "Copyright (C) 2016-2018 Matias Andres Fonzo." \
92 "License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>" \
93 "This is free software: you are free to change and redistribute it." \
94 "There is NO WARRANTY, to the extent permitted by law."
99 printf "%s\n" "$@" 1>&2
108 echo "${PROGRAM}: cannot read ${1}: Permission denied" 1>&2
112 echo "${PROGRAM}: cannot access ${1}: No such file or directory" 1>&2
117 # Portable alternative to the file operator -nt (among shells)
120 if test -n "$(find $1 -prune -newer $2 -print)"
127 # Determine whether $2 matches pattern $1
144 if test $status -ne 0
146 echo "Return status = $status" 1>&2
147 exit ${1-2}; # If not given, defaults to 2
157 is_readable
"$HOME/.qirc" 2> /dev
/null
&& RCFILE
="$HOME/.qirc";
159 echo "Processing \`${RCFILE}' ..."
161 test -f "$RCFILE" ||
{
162 warn
"${RCFILE} is not a regular file."
167 while IFS
='=' read -r variable value
170 \
#* | "") # Ignore commented or blank lines
175 # Set variable name avoiding code execution
176 eval "$variable=\${value}"
187 # A recipe is any valid regular file, the current working directory
188 # has priority over the working tree (or where the recipes reside).
189 # The 'worktree' is the second place where to find a recipe. Also,
190 # we complete the possibility of using the directory name to invoke
191 # a recipe if it contains "recipe" as valid file name.
193 if test ! -f "$recipe"
195 if test -f "${recipe}/recipe"
197 recipe
="${recipe}/recipe"
198 elif test -f "${worktree}/recipes/${recipe}/recipe"
200 recipe
="${worktree}/recipes/${recipe}/recipe"
204 test -f "$recipe" ||
{
205 warn
"\`${recipe}' is not a regular file."
209 # Complain if the file name is not "recipe"
211 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 -r "${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_ignoreqsts" = opt_ignoreqsts
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_ignoreqsts=opt_ignoreqsts
386 readonly opt_ignoreqsts
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 is 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"
586 rm -rf -- "${TMPDIR}/$srcdir" || chkstatus_or_exit
587 echo "removed directory: '${TMPDIR}/${srcdir}'"
589 warn
"The variable 'keep_srcdir' is set:" \
590 "'${TMPDIR}/${srcdir}' will not be deleted."
594 if test -r "$destdir"
596 rm -rf -- "$destdir" || chkstatus_or_exit
597 echo "removed directory: '$destdir'"
601 # Install or update the package if -i or -u was passed
602 if test "$opt_nopkg" != opt_nopkg
604 if test "$opt_install" = opt_install
606 install_mode
"${outdir}/${full_pkgname}.tlz"
607 elif test "$opt_update" = opt_update
609 upgrade_mode
"${outdir}/${full_pkgname}.tlz"
614 echo "All done for ${CWD}/${recipe}."
620 directory
=$
(dirname -- "$1")
621 name
=$
(basename -- "$1")
623 # Perform sanity checks
625 is_readable
"$directory" ||
exit 4
627 # Check again to find out if it is a valid directory
628 test -d "$directory" ||
{
629 warn
"Package directory '$name' does not exist."
633 test "$directory" = .
&& {
634 warn
"Cannot create package on current working directory."
638 test "$name" = "${name%.tlz}" && {
640 "Package format '$name' not supported." \
641 "It should be \`name-version-architecture+release.tlz'"
645 echo "{#} Creating package $name at $directory ..."
647 ( umask 022 ; tar cvf
- .
/* | lzip
-9cvv ) > "${directory}/$name"
650 echo "Package created \"${directory}/${name}\"."
652 echo "${directory}/$name: Creating SHA256 checksum ..."
653 ( cd -- "$directory" && sha256sum
$name > ${name}.sha256
)
655 # Remove used variables
663 echo "<<< Deleting package $rootdir${expunge} from $packagedir ..."
665 # If package is not a fully qualified directory,
666 # prepend it with the value of packagedir.
668 if ! fnmatch
"${packagedir}*" "$expunge"
670 expunge
="${packagedir}/$expunge"
673 # Complain if the package directory does not exist
675 test -d "$rootdir${expunge}" ||
{
676 warn
"Package directory '$rootdir${expunge}' does not exist."
680 # Complain if the package directory cannot be well-read
682 is_readable
"$rootdir${expunge}" ||
exit 4
684 # Remove package from Graft control
686 # Scan for possible conflicts, stop if arise
687 if test "$opt_prune" != opt_prune
689 echo "Checking for possible conflicts ..."
690 if graft
-d -n $graft_r -t "$targetdir" "$expunge" 2>&1 | \
694 " A conflict occurred during uninstallation;" \
695 "Unless the -p option is given, this package will be PRESERVED."
700 # Ignore some signals up to completing the deinstallation
701 trap "" HUP INT QUIT ABRT TERM
703 # Remove objects (files, links or directories) from the target
704 # directory that are in conflict with the package directory
706 echo "Pruning any conflict ..."
707 graft
-p -D -u $graft_r -t "$targetdir" "$expunge"
710 echo "Disabling links ..."
711 graft
-d -D -u $graft_v $graft_r -t "$targetdir" "$expunge"
714 # Delete package directory
715 if test "$opt_keep" != opt_keep
717 echo "Deleting package directory, if present ..."
719 if test -d "${rootdir}$expunge"
721 rm -rf -- "${rootdir}$expunge" || chkstatus_or_exit
722 echo "removed directory: '${rootdir}$expunge'"
726 # Reset given signals
727 trap - HUP INT QUIT ABRT TERM
729 # Remove used variables
735 # Complain if the package cannot be well-read
737 is_readable
"$1" ||
exit 4
739 # Complain if the package does not end in .tlz
741 if ! fnmatch
'*.tlz' "$1"
743 warn
"\`${1}' does not end in .tlz"
747 # Make preparations to install the package
749 echo ">>> Installing package $1 ..."
752 name
=$
(basename -- "$1" .tlz
)
754 echo "Checking tarball integrity ..."
755 tar -tf "$1" > /dev
/null
758 # Create package directory using 'name'
759 if ! test -d "$rootdir${packagedir}/$name"
761 mkdir
-p -- "$rootdir${packagedir}/$name" || chkstatus_or_exit
762 echo "mkdir: created directory '$rootdir${packagedir}/$name'"
765 # Scan for possible conflicts, stop if arise
766 if test "$opt_prune" != opt_prune
768 echo "Checking for possible conflicts ..."
769 if graft
-i -n $graft_r -t "$targetdir" "${packagedir}/$name" 2>&1 | \
773 " A conflict occurred during installation;" \
774 "Unless the -p option is given, this package won't be LINKED."
779 # Ignore some signals up to completing the installation
780 trap "" HUP INT QUIT ABRT TERM
782 echo "Decompressing $1 ..."
783 ( cd -- "$rootdir${packagedir}/$name" && lzip
-cd - |
tar xpf
- ) < "$1"
786 # Transite package to Graft control
788 # Remove objects (files, links or directories) from the target
789 # directory that are in conflict with the package directory
790 echo "Pruning any conflict ..."
791 graft
-p -D -u $graft_r -t "$targetdir" "${packagedir}/$name"
794 echo "Enabling symbolic links ..."
795 graft
-i -P $graft_v $graft_r -t "$targetdir" "${packagedir}/$name"
798 # Avoid unnecessary runs coming from the upgrade_mode(),
799 # this is when the incoming package is **pre-installed**
801 if test "$_isUpgrade" != _isUpgrade.on
803 # Show package description
804 if test -r "$rootdir${packagedir}/${name}/var/lib/qi/${name}.txt"
806 grep '^#' "$rootdir${packagedir}/${name}/var/lib/qi/${name}.txt"
807 elif test -r "${1}.txt"
809 # From external meta file (current directory)
812 warn
"Description file not found for '$name'."
815 # Check and run the post-install script if exist
816 if test -r "$rootdir${packagedir}/${name}/var/lib/qi/${name}.sh"
818 echo "Running post-install script for \`${name}' ..."
820 # Rely on 'targetdir' if 'rootdir' is empty
821 cd -- "${rootdir:-$targetdir}"/ && \
822 .
"$rootdir${packagedir}/${name}/var/lib/qi/${name}.sh"
826 # Check if there are declared packages for replacement
827 if test -r "$rootdir${packagedir}/${name}/var/lib/qi/${name}.replace"
831 for replace
in "$rootdir${packagedir}/$(pkgbase $line)"-*
833 if ! test -e "$replace"
835 warn
"${replace}: Declared package does not exist. (ignored)"
839 replace
="${replace##*/}"
841 # The search for the package to be replaced cannot
842 # be the same to the incoming package, even to the
843 # temporary location coming from the upgrade_mode()
844 if test "$replace" = "$name" ||
test "$replace" = "${PRVLOC##*/}"
849 warn
"WARNING: Replacing package \`${replace}' ..."
851 # Since the links belongs to the new package, only
852 # those which are not in conflict can be deleted.
853 # To complete, we will remove the package directory
855 graft
-d -D -u $graft_r \
856 -t "$targetdir" "$replace" > /dev
/null
2>&1
858 rm -rf -- "$rootdir${packagedir}/$replace"
860 done < "$rootdir${packagedir}/${name}/var/lib/qi/${name}.replace"
865 # Reset given signals
866 trap - HUP INT QUIT ABRT TERM
868 # Remove used variables
873 # Complain if the file cannot be well-read
875 is_readable
"$1" ||
exit 4
877 # Complain if the file does not end in .order
879 if ! fnmatch
'*.order' "$1"
881 warn
"\`${1}' does not end in .order"
885 # Get a clean list of the file while prints its content in reverse order,
886 # lines containing: colons, comments, parentheses, end of line, and blank
887 # lines, are removed. The parentheses are used to insert a reference.
888 # The last `awk' in the pipe: removes nonconsecutive lines, duplicate.
890 '{ gsub( /:|^#(.*)$|\([^)]*)|^$/,"" ); for( i=NF; i > 0; i-- ) print $i }' \
891 "$1" |
awk '!s[$0]++'
896 # Complain if the package is not a regular file
899 warn
"\`${1}' is not a regular file."
904 incoming
=$
(basename -- "$1" .tlz
)
906 # Check for packages declared in the black list only for installation
908 for item
in $blacklist
914 "* The incoming package will be installed instead of being updated." \
915 "* This may be crucial for the correct functioning of \`${PROGRAM}'." \
917 opt_prune
=opt_prune install_mode
"$1"
923 # Prepare the package to install it in a temporary location
925 # Set random directory using packagedir as prefix and 'incoming' as suffix
926 PRVLOC
=$
(mktemp
-dp "$rootdir${packagedir}" ${incoming}.XXXXXXXXXXXX
) ||
exit 2
928 # Pre-install the package in the custom 'packagedir'
930 save_packagedir
="$packagedir"
933 echo "Pre-installing package using temporary location ..."
934 opt_prune
=opt_prune
# Turn on prune operation.
935 _isUpgrade
=_isUpgrade.on install_mode
"$1" > /dev
/null
936 _isUpgrade
=_isUpgrade.off
938 # Restore variable before looking for old packages
939 packagedir
=$save_packagedir
940 unset save_packagedir
942 echo "Looking for installations under the same name ..."
943 for long_name
in "$rootdir${packagedir}/$(pkgbase $incoming)"*
945 found
="${long_name##*/}"
947 # The search for the package to be deleted
948 # cannot be the same to the temporary location
949 test "$long_name" = "$PRVLOC" && continue;
951 fnmatch
"$(pkgbase $found)*" "$incoming" ||
continue;
952 echo "${long_name}: Detected."
954 # A package directory is preserved if -k is given
955 delete_mode
"$found" > /dev
/null
957 unset long_name found
959 # Re-install the package removing the temporary location
962 opt_prune
=opt_prune.off
# Turn off prune operation.
964 echo "Deleting temporary location ..."
965 rm -rf -- "$PRVLOC" || chkstatus_or_exit
966 echo "removed directory: '$PRVLOC'"
969 echo "Successful upgrade to '${incoming}'."
971 # Remove remaining variables
972 unset incoming PRVLOC
977 # Perform sanity checks before package extraction
979 is_readable
"$1" ||
exit 4
982 warn
"\`${1}' is not a regular file."
986 # Preparations to extract the package
988 name
=$
(basename -- "$1" .tlz
)
990 # Set random directory using 'name' as prefix
991 PRVDIR
="${TMPDIR}/${name}.${RANDOM-0}$$"
993 # Trap to remove 'PRVDIR' on disruptions
994 trap "rm -rf -- $PRVDIR" HUP INT ABRT TERM
996 # Create 'PRVDIR' removing access for all but user
997 ( umask 077 ; mkdir
-- $PRVDIR )
998 mkdir
-p -m 700 -- $PRVDIR
1000 echo "Extracting package $name ..."
1001 ( umask 000 ; cd -- $PRVDIR && lzip
-cd - |
tar xpvf
- ) < "$1"
1004 # Try to remove (empty) 'PRVDIR' on failure
1008 echo "$name has been extracted on $PRVDIR"
1010 # Reset given signals
1011 trap - HUP INT ABRT TERM
1013 # Remove used variables
1017 #### Extra functions used in the modes
1021 string
=$
(basename -- "$1" .tlz
)
1023 # Match cases to print the package name.
1025 # We will take into account the four segments removing
1026 # the last two to print the package (long) name
1029 echo "${string%-*-*}"
1045 tar tf
"$file" > /dev
/null
&& \
1049 *.
tar.gz |
*.tgz |
*.
tar.Z
)
1050 gzip -cd "$file" |
tar tf
- > /dev
/null
&& \
1051 gzip -cd "$file" |
tar xpf
-
1054 *.
tar.bz2 |
*.tbz2 |
*.tbz
)
1055 bzip2 -cd "$file" |
tar tf
- > /dev
/null
&& \
1056 bzip2 -cd "$file" |
tar xpf
-
1060 lzip
-cd "$file" |
tar tf
- > /dev
/null
&& \
1061 lzip
-cd "$file" |
tar xpf
-
1065 xz
-cd "$file" |
tar tf
- > /dev
/null
&& \
1066 xz
-cd "$file" |
tar xpf
-
1070 unzip -t "$file" > /dev
/null
&& \
1071 unzip "$file" > /dev
/null
1075 gzip -t "$file" && \
1076 gzip -cd "$file" > "$(basename -- $file .gz)"
1080 gzip -t "$file" && \
1081 gzip -cd "$file" > "$(basename -- $file .Z)"
1085 bzip2 -t "$file" && \
1086 bzip2 -cd "$file" > "$(basename -- $file .bz2)"
1090 lzip
-t "$file" && \
1091 lzip
-cd "$file" > "$(basename -- $file .lz)"
1096 xz
-cd "$file" > "$(basename -- $file .xz)"
1100 warn
"${PROGRAM}: cannot unpack ${file}: Unsupported extension"
1109 # Extract information from the recipe to create the meta file.
1111 # The package description is pre-formatted in 78 columns,
1112 # the '#' character and a space is added as prefix to conform
1113 # 80 columns in total
1116 $(echo "$description" | fold -w 78 | awk '$0="# " $0')
1118 QICFLAGS="$QICFLAGS"
1119 QICXXFLAGS="$QICXXFLAGS"
1120 QILDFLAGS="$QILDFLAGS"
1124 blurb="$(echo "$description" | sed -e '/^$/d;2q')"
1125 homepage="$homepage"
1136 packagedir
=@PACKAGEDIR@
1137 targetdir
=@TARGETDIR@
1138 blacklist
="perl graft musl glibc"
1140 RCFILE
=@SYSCONFDIR@
/qirc
1141 opt_install
=opt_install.off
1142 opt_update
=opt_update.off
1143 opt_force
=opt_force.off
1144 opt_keep
=opt_keep.off
1145 opt_incr_release
=opt_incr_release.off
1146 opt_ignoreqsts
=opt_ignoreqsts.off
1147 opt_nopkg
=opt_nopkg.off
1148 opt_prune
=opt_prune.off
1155 _isUpgrade
=_isUpgrade.off
1156 TMPDIR
="${TMPDIR:=/usr/src/qi/build}"
1157 QICFLAGS
="${QICFLAGS:=-g0 -Os}"
1158 QICXXFLAGS
="${QICXXFLAGS:=$QICFLAGS}"
1159 QILDFLAGS
="${QILDFLAGS:=-s}"
1160 worktree
=/usr
/src
/qi
1161 tardir
=${worktree}/sources
1162 outdir
=/var
/cache
/qi
/packages
1163 netget
="wget -c -w1 -t3 --no-check-certificate"
1164 rsync
="rsync -v -a -L -z -i --progress"
1165 configure_args
="--prefix=@PREFIX@ --libexecdir=@LIBEXECDIR@ --bindir=@BINDIR@ --sbindir=@SBINDIR@ --sysconfdir=@SYSCONFDIR@ --localstatedir=@LOCALSTATEDIR@"
1170 # Store default locations
1171 QI_TARGETDIR
=$targetdir
1172 QI_PACKAGEDIR
=$packagedir
1173 QI_WORKTREE
=$worktree
1179 while getopts :bcdiouxLNP
:t
:fkvO
:W
:Z
:a
:j
:13npr
:hV name
1202 if test "$mode" = build_mode
1204 opt_install
=opt_install
1216 if test "$mode" = build_mode
1218 opt_update
=opt_update
1226 "QI_TARGETDIR=$QI_TARGETDIR" \
1227 "QI_PACKAGEDIR=$QI_PACKAGEDIR" \
1228 "QI_WORKTREE=$QI_WORKTREE" \
1229 "QI_TARDIR=$QI_TARDIR" \
1230 "QI_OUTDIR=$QI_OUTDIR"
1237 packagedir
="$OPTARG"
1249 verbose
=$
(( verbose
+ 1 ))
1267 opt_incr_release
=opt_incr_release
1270 opt_ignoreqsts
=opt_ignoreqsts
1290 warn
"Option '-${OPTARG}' requires an argument"
1295 warn
"Illegal option -- '-${OPTARG}'"
1301 shift $
(( OPTIND
- 1 ))
1309 # Program sanity check
1310 for need
in awk basename bzip2 chmod cp dirname find fold graft
grep \
1311 lzip mkdir mktemp
rm rmdir sed sha256sum stat
tar
1313 if ! type $need 1> /dev
/null
2> /dev
/null
1315 warn
"${PROGRAM}: cannot operate without ${need}(1): Check your PATH"
1321 # Determine verbosity level/flag
1323 if test "$verbose" -gt 1
1328 # Read standard input if FILE is -, or when FILE
1329 # is not connected to a terminal.
1331 if test "$1" = - ||
test ! -t 0
1333 # Unset positional parameters setting $# to zero
1336 # Assign remaining arguments to the positional parameters
1339 set -- "$@" "$input"
1343 # We need at least one operating mode
1350 umask 022; # Remove write permission for group and other.
1352 # Validate 'rootdir' directory
1354 if test -n "$rootdir"
1356 if test -d "$rootdir" && test "$rootdir" != /
1358 # Remove slash from the end
1359 rootdir
="${rootdir%/}"
1361 # A workaround for graft-2.13+. The specified directory is
1362 # relative to the log file, we prepend it inside the rootdir
1364 eval "$(graft -L)" ; GRAFT_LOGFILE
="${GRAFT_LOGFILE:=/var/log/graft}"
1365 mkdir
-p -- "$rootdir$(dirname -- $GRAFT_LOGFILE)" || chkstatus_or_exit
1367 # Compose 'rootdir' and log file option to be used with graft(1)
1368 graft_r
="-r $rootdir -l $GRAFT_LOGFILE"
1370 # Unset variables coming from eval
1371 unset GRAFT_PERL GRAFT_LOGFILE GRAFT_TARGETDIR GRAFT_PACKAGEDIR
1373 warn
"${PROGRAM}: \`${rootdir}' is not a qualified root directory"
1379 # Ensure 'TMPDIR' creation to prefix temporary files
1381 if test ! -d "$TMPDIR"
1383 mkdir
-p -- "$TMPDIR" || chkstatus_or_exit
1387 # Process each package or recipe provided on the command-line