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 echo "Running build() ..."
489 build ; set +e ; unset build
491 # Reset given signals
492 trap - EXIT HUP INT QUIT ABRT TERM
494 # If 'destdir
' is empty, the package won't be created
495 if rmdir -- "$destdir" 2> /dev
/null
497 warn
"The package \"${full_pkgname}.tlz\" won't be created. 'destdir' is empty."
501 # Create (make) the package
503 if test "$opt_nopkg" != opt_nopkg
505 # Edit the recipe when 'release' is incremented
506 if test "$opt_incr_release" = opt_incr_release
508 echo ",s/^\(release\)=.*/\1=${release}/"$
'\nw' | \
509 ed
"${CWD}/$recipe" || chkstatus_or_exit
512 mkdir
-p -- "${destdir}/var/lib/qi" || chkstatus_or_exit
514 # Include a recipe copy into the package
515 cp -p "${CWD}/$recipe" \
516 "${destdir}/var/lib/qi/${full_pkgname}.recipe" && \
517 chmod 644 "${destdir}/var/lib/qi/${full_pkgname}.recipe" || chkstatus_or_exit
519 # Detect post-install script for inclusion
521 if test -f "${CWD}/post-install"
523 echo "${CWD}/post-install: Detected."
524 cp -p "${CWD}/post-install" \
525 "${destdir}/var/lib/qi/${full_pkgname}.sh" && \
526 chmod 644 "${destdir}/var/lib/qi/${full_pkgname}.sh" || chkstatus_or_exit
529 # Detect declared package names for later replacement
531 if test -n "$replace"
534 "The following package names has been declared for replacement:" \
537 rm -f "${destdir}/var/lib/qi/${full_pkgname}.replace"
540 echo "$replace" >> "${destdir}/var/lib/qi/${full_pkgname}.replace"
545 # Create meta file for the package information
546 echo "Creating meta file ${full_pkgname}.tlz.txt ..."
547 do_meta
> "${outdir}/${full_pkgname}.tlz.txt" || chkstatus_or_exit
549 # Make a copy of it for the database
550 cp -p "${outdir}/${full_pkgname}.tlz.txt" \
551 "${destdir}/var/lib/qi/${full_pkgname}.txt" || chkstatus_or_exit
553 # Produce the package
554 cd -- "$destdir" && create_mode
"${outdir}/${full_pkgname}.tlz"
557 # Back to the current working directory
558 cd -- "$CWD" || chkstatus_or_exit
560 # Delete 'srcdir' or 'destdir' if -k is not given
561 if test "$opt_keep" != opt_keep
563 echo "Deleting temporary directories ..."
565 srcdir
="${srcdir%%/*}" # Directory name without parents.
567 if test -r "${TMPDIR}/$srcdir"
569 if test -z "$keep_srcdir"
571 rm -rf -- "${TMPDIR}/$srcdir" || chkstatus_or_exit
572 echo "removed directory: '${TMPDIR}/${srcdir}'"
574 warn
"The variable 'keep_srcdir' is set:" \
575 "'${TMPDIR}/${srcdir}' will not be deleted."
579 if test -r "$destdir"
581 rm -rf -- "$destdir" || chkstatus_or_exit
582 echo "removed directory: '$destdir'"
586 # Install or update the package if -i or -u was passed
587 if test "$opt_nopkg" != opt_nopkg
589 if test "$opt_install" = opt_install
591 install_mode
"${outdir}/${full_pkgname}.tlz"
592 elif test "$opt_update" = opt_update
594 upgrade_mode
"${outdir}/${full_pkgname}.tlz"
599 echo "All done for ${CWD}/${recipe}."
605 directory
=$
(dirname -- "$1")
606 name
=$
(basename -- "$1")
608 # Perform sanity checks
610 is_readable
"$directory" ||
exit 4
612 # Check again to find out if it is a valid directory
613 test -d "$directory" ||
{
614 warn
"Package directory '$name' does not exist."
618 test "$directory" = .
&& {
619 warn
"Cannot create package on current working directory."
623 test "$name" = "${name%.tlz}" && {
625 "Package format '$name' not supported." \
626 "It should be \`name-version-architecture+release.tlz'"
630 echo "{#} Creating package $name at $directory ..."
632 ( umask 022 ; tar cvf
- .
/* | lzip
-9cvv ) > "${directory}/$name"
635 echo "Package created \"${directory}/${name}\"."
637 echo "${directory}/$name: Creating SHA256 checksum ..."
638 ( cd -- "$directory" && sha256sum
$name > ${name}.sha256
)
640 # Remove used variables
648 echo "<<< Deleting package $rootdir${expunge} from $packagedir ..."
650 # If package is not a fully qualified directory,
651 # prepend it with the value of packagedir.
653 if ! fnmatch
"${packagedir}*" "$expunge"
655 expunge
="${packagedir}/$expunge"
658 # Complain if the package directory does not exist
660 test -d "$rootdir${expunge}" ||
{
661 warn
"Package directory '$rootdir${expunge}' does not exist."
665 # Complain if the package directory cannot be well-read
667 is_readable
"$rootdir${expunge}" ||
exit 4
669 # Ignore some signals up to completing the deinstallation
670 trap "" HUP QUIT ABRT TERM
672 # To catch and report on interruptions (e.g Ctrl+C),
673 # Note: SIGINT is allowed for cancel packages.
674 trap 'chkstatus_or_exit 2' INT
676 # Remove package from Graft control
678 # Scan for possible conflicts, stop if arise
679 if test "$opt_prune" != opt_prune
681 echo "Checking for possible conflicts ..."
682 if graft
-d -n $graft_r -t "$targetdir" "$expunge" 2>&1 | \
686 " A conflict occurred during uninstallation;" \
687 "Unless the -p option is given, this package will be PRESERVED."
692 # Remove objects (files, links or directories) from the target
693 # directory that are in conflict with the package directory
695 echo "Pruning any conflict ..."
696 graft
-p -D -u $graft_r -t "$targetdir" "$expunge"
699 echo "Disabling links ..."
700 graft
-d -D -u $graft_v $graft_r -t "$targetdir" "$expunge"
703 # Delete package directory
704 if test "$opt_keep" != opt_keep
706 echo "Deleting package directory, if present ..."
708 if test -d "${rootdir}$expunge"
710 rm -rf -- "${rootdir}$expunge" || chkstatus_or_exit
711 echo "removed directory: '${rootdir}$expunge'"
715 # Reset given signals
716 trap - HUP INT QUIT ABRT TERM
718 # Remove used variables
724 # Complain if the package cannot be well-read
726 is_readable
"$1" ||
exit 4
728 # Complain if the package does not end in .tlz
730 if ! fnmatch
'*.tlz' "$1"
732 warn
"\`${1}' does not end in .tlz"
736 # Make preparations to install the package
738 echo ">>> Installing package $1 ..."
741 name
=$
(basename -- "$1" .tlz
)
743 echo "Checking tarball integrity ..."
744 tar -tf "$1" > /dev
/null
747 # Create package directory using 'name'
748 if ! test -d "$rootdir${packagedir}/$name"
750 mkdir
-p -- "$rootdir${packagedir}/$name" || chkstatus_or_exit
751 echo "mkdir: created directory '$rootdir${packagedir}/$name'"
754 # Scan for possible conflicts, stop if arise
755 if test "$opt_prune" != opt_prune
757 echo "Checking for possible conflicts ..."
758 if graft
-i -n $graft_r -t "$targetdir" "${packagedir}/$name" 2>&1 | \
762 " A conflict occurred during installation;" \
763 "Unless the -p option is given, this package won't be LINKED."
768 # Ignore some signals up to completing the installation
769 trap "" HUP INT QUIT ABRT TERM
771 echo "Decompressing $1 ..."
772 ( cd -- "$rootdir${packagedir}/$name" && lzip
-cd - |
tar xpf
- ) < "$1"
775 # Transite package to Graft control
777 # Remove objects (files, links or directories) from the target
778 # directory that are in conflict with the package directory
779 echo "Pruning any conflict ..."
780 graft
-p -D -u $graft_r -t "$targetdir" "${packagedir}/$name"
783 echo "Enabling symbolic links ..."
784 graft
-i -P $graft_v $graft_r -t "$targetdir" "${packagedir}/$name"
787 # Avoid unnecessary runs coming from the upgrade_mode(),
788 # this is when the incoming package is **pre-installed**
790 if test "$_isUpgrade" != _isUpgrade.on
792 # Show package description
793 if test -r "$rootdir${packagedir}/${name}/var/lib/qi/${name}.txt"
795 grep '^#' "$rootdir${packagedir}/${name}/var/lib/qi/${name}.txt"
796 elif test -r "${1}.txt"
798 # From external meta file (current directory)
801 warn
"Description file not found for '$name'."
804 # Check and run the post-install script if exist
805 if test -r "$rootdir${packagedir}/${name}/var/lib/qi/${name}.sh"
807 echo "Running post-install script for \`${name}' ..."
809 # Rely on 'targetdir' if 'rootdir' is empty
810 cd -- "${rootdir:-$targetdir}"/ && \
811 .
"$rootdir${packagedir}/${name}/var/lib/qi/${name}.sh"
815 # Check if there are declared packages for replacement
816 if test -r "$rootdir${packagedir}/${name}/var/lib/qi/${name}.replace"
820 for replace
in "$rootdir${packagedir}/$(pkgbase $line)"-*
822 if ! test -e "$replace"
824 warn
"${replace}: Declared package does not exist. (ignored)"
828 replace
="${replace##*/}"
830 # The search for the package to be replaced cannot
831 # be the same to the incoming package, even to the
832 # temporary location coming from the upgrade_mode()
833 if test "$replace" = "$name" ||
test "$replace" = "${PRVLOC##*/}"
838 warn
"WARNING: Replacing package \`${replace}' ..."
840 # Since the links belongs to the new package, only
841 # those which are not in conflict can be deleted.
842 # To complete, we will remove the package directory
844 graft
-d -D -u $graft_r \
845 -t "$targetdir" "$replace" > /dev
/null
2>&1
847 rm -rf -- "$rootdir${packagedir}/$replace"
849 done < "$rootdir${packagedir}/${name}/var/lib/qi/${name}.replace"
854 # Reset given signals
855 trap - HUP INT QUIT ABRT TERM
857 # Remove used variables
862 # Complain if the file cannot be well-read
864 is_readable
"$1" ||
exit 4
866 # Complain if the file does not end in .order
868 if ! fnmatch
'*.order' "$1"
870 warn
"\`${1}' does not end in .order"
874 # Get a clean list of the file while prints its content in reverse order,
875 # lines containing: colons, comments, parentheses, end of line, and blank
876 # lines, are removed. The parentheses are used to insert a reference.
877 # The last `awk' in the pipe: removes nonconsecutive lines, duplicate.
879 '{ gsub( /:|^#(.*)$|\([^)]*)|^$/,"" ); for( i=NF; i > 0; i-- ) print $i }' \
880 "$1" |
awk '!s[$0]++'
885 # Complain if the package is not a regular file
888 warn
"\`${1}' is not a regular file."
893 incoming
=$
(basename -- "$1" .tlz
)
895 # Check for packages declared in the black list only for installation
897 for item
in $blacklist
903 "* The incoming package will be installed instead of being updated." \
904 "* This may be crucial for the correct functioning of \`${PROGRAM}'." \
906 opt_prune
=opt_prune install_mode
"$1"
912 # Prepare the package to install it in a temporary location
914 # Set random directory using packagedir as prefix and 'incoming' as suffix
915 PRVLOC
=$
(mktemp
-dp "$rootdir${packagedir}" ${incoming}.XXXXXXXXXXXX
) ||
exit 2
917 # Pre-install the package in the custom 'packagedir'
919 save_packagedir
="$packagedir"
922 echo "Pre-installing package using temporary location ..."
923 opt_prune
=opt_prune
# Turn on prune operation.
924 _isUpgrade
=_isUpgrade.on install_mode
"$1" > /dev
/null
925 _isUpgrade
=_isUpgrade.off
927 # Restore variable before looking for old packages
928 packagedir
=$save_packagedir
929 unset save_packagedir
931 echo "Looking for installations under the same name ..."
932 for long_name
in "$rootdir${packagedir}/$(pkgbase $incoming)"*
934 found
="${long_name##*/}"
936 # The search for the package to be deleted
937 # cannot be the same to the temporary location
938 test "$long_name" = "$PRVLOC" && continue;
940 fnmatch
"$(pkgbase $found)*" "$incoming" ||
continue;
941 echo "${long_name}: Detected."
943 # A package directory is preserved if -k is given
944 delete_mode
"$found" > /dev
/null
946 unset long_name found
948 # Re-install the package removing the temporary location
951 opt_prune
=opt_prune.off
# Turn off prune operation.
953 echo "Deleting temporary location ..."
954 rm -rf -- "$PRVLOC" || chkstatus_or_exit
955 echo "removed directory: '$PRVLOC'"
958 echo "Successful upgrade to '${incoming}'."
960 # Remove remaining variables
961 unset incoming PRVLOC
966 # Perform sanity checks before package extraction
968 is_readable
"$1" ||
exit 4
971 warn
"\`${1}' is not a regular file."
975 # Preparations to extract the package
977 name
=$
(basename -- "$1" .tlz
)
979 # Set random directory using 'name' as prefix
980 PRVDIR
="${TMPDIR}/${name}.${RANDOM-0}$$"
982 # Trap to remove 'PRVDIR' on disruptions
983 trap "rm -rf -- $PRVDIR" HUP INT ABRT TERM
985 # Create 'PRVDIR' removing access for all but user
986 ( umask 077 ; mkdir
-- $PRVDIR )
987 mkdir
-p -m 700 -- $PRVDIR
989 echo "Extracting package $name ..."
990 ( umask 000 ; cd -- $PRVDIR && lzip
-cd - |
tar xpvf
- ) < "$1"
993 # Try to remove (empty) 'PRVDIR' on failure
997 echo "$name has been extracted on $PRVDIR"
999 # Reset given signals
1000 trap - HUP INT ABRT TERM
1002 # Remove used variables
1006 #### Extra functions used in the modes
1010 string
=$
(basename -- "$1" .tlz
)
1012 # Take and count the dashes only
1014 dashes
=$
(echo "$string" |
tr -cd '-')
1017 # Match cases to print the package name
1024 # NAME_[-LONG]-VERSION-ARCH+release
1025 echo "${string%-*-*}"
1038 tar tf
"$file" > /dev
/null
&& \
1042 *.
tar.gz |
*.tgz |
*.
tar.Z
)
1043 gzip -cd "$file" |
tar tf
- > /dev
/null
&& \
1044 gzip -cd "$file" |
tar xpf
-
1047 *.
tar.bz2 |
*.tbz2 |
*.tbz
)
1048 bzip2 -cd "$file" |
tar tf
- > /dev
/null
&& \
1049 bzip2 -cd "$file" |
tar xpf
-
1053 lzip
-cd "$file" |
tar tf
- > /dev
/null
&& \
1054 lzip
-cd "$file" |
tar xpf
-
1058 xz
-cd "$file" |
tar tf
- > /dev
/null
&& \
1059 xz
-cd "$file" |
tar xpf
-
1063 unzip -t "$file" > /dev
/null
&& \
1064 unzip "$file" > /dev
/null
1068 gzip -t "$file" && \
1069 gzip -cd "$file" > "$(basename -- $file .gz)"
1073 gzip -t "$file" && \
1074 gzip -cd "$file" > "$(basename -- $file .Z)"
1078 bzip2 -t "$file" && \
1079 bzip2 -cd "$file" > "$(basename -- $file .bz2)"
1083 lzip
-t "$file" && \
1084 lzip
-cd "$file" > "$(basename -- $file .lz)"
1089 xz
-cd "$file" > "$(basename -- $file .xz)"
1093 warn
"${PROGRAM}: cannot unpack ${file}: Unsupported extension"
1102 # Extract information from the recipe to create the meta file.
1104 # The package description is pre-formatted in 78 columns,
1105 # the '#' character and a space is added as prefix to conform
1106 # 80 columns in total
1109 $(echo "$description" | fold -w 78 | awk '$0="# " $0')
1111 QICFLAGS="$QICFLAGS"
1112 QICXXFLAGS="$QICXXFLAGS"
1113 QILDFLAGS="$QILDFLAGS"
1117 blurb="$(echo "$description" | sed -e '/^$/d;2q')"
1118 homepage="$homepage"
1129 packagedir
=@PACKAGEDIR@
1130 targetdir
=@TARGETDIR@
1131 blacklist
="perl graft musl glibc"
1133 RCFILE
=@SYSCONFDIR@
/qirc
1134 opt_install
=opt_install.off
1135 opt_update
=opt_update.off
1136 opt_force
=opt_force.off
1137 opt_keep
=opt_keep.off
1138 opt_incr_release
=opt_incr_release.off
1139 opt_ignoreqsts
=opt_ignoreqsts.off
1140 opt_nopkg
=opt_nopkg.off
1141 opt_prune
=opt_prune.off
1148 _isUpgrade
=_isUpgrade.off
1149 TMPDIR
="${TMPDIR:=/usr/src/qi/build}"
1150 QICFLAGS
="${QICFLAGS:=-g0 -Os}"
1151 QICXXFLAGS
="${QICXXFLAGS:=$QICFLAGS}"
1152 QILDFLAGS
="${QILDFLAGS:=-s}"
1153 worktree
=/usr
/src
/qi
1154 tardir
=${worktree}/sources
1155 outdir
=/var
/cache
/qi
/packages
1156 netget
="wget -c -w1 -t3 --no-check-certificate"
1157 rsync
="rsync -v -a -L -z -i --progress"
1158 configure_args
="--prefix=@PREFIX@ --libexecdir=@LIBEXECDIR@ --bindir=@BINDIR@ --sbindir=@SBINDIR@ --sysconfdir=@SYSCONFDIR@ --localstatedir=@LOCALSTATEDIR@"
1163 # Store default locations
1164 QI_TARGETDIR
=$targetdir
1165 QI_PACKAGEDIR
=$packagedir
1166 QI_WORKTREE
=$worktree
1172 while getopts :bcdiouxLNP
:t
:fkvO
:W
:Z
:a
:j
:13npr
:hV name
1195 if test "$mode" = build_mode
1197 opt_install
=opt_install
1209 if test "$mode" = build_mode
1211 opt_update
=opt_update
1219 "QI_TARGETDIR=$QI_TARGETDIR" \
1220 "QI_PACKAGEDIR=$QI_PACKAGEDIR" \
1221 "QI_WORKTREE=$QI_WORKTREE" \
1222 "QI_TARDIR=$QI_TARDIR" \
1223 "QI_OUTDIR=$QI_OUTDIR"
1230 packagedir
="$OPTARG"
1242 verbose
=$
(( verbose
+ 1 ))
1260 opt_incr_release
=opt_incr_release
1263 opt_ignoreqsts
=opt_ignoreqsts
1283 warn
"Option '-${OPTARG}' requires an argument"
1288 warn
"Illegal option -- '-${OPTARG}'"
1294 shift $
(( OPTIND
- 1 ))
1302 # Program sanity check
1303 for need
in awk basename bzip2 chmod cp dirname find fold graft
grep \
1304 lzip mkdir mktemp
rm rmdir sed sha256sum stat
tar tr
1306 if ! type $need 1> /dev
/null
2> /dev
/null
1308 warn
"${PROGRAM}: cannot operate without ${need}(1): Check your PATH"
1314 # Determine verbosity level/flag
1316 if test "$verbose" -gt 1
1321 # Read standard input if FILE is -, or when FILE
1322 # is not connected to a terminal.
1324 if test "$1" = - ||
test ! -t 0
1326 # Unset positional parameters setting $# to zero
1329 # Assign remaining arguments to the positional parameters
1332 set -- "$@" "$input"
1336 # We need at least one operating mode
1343 umask 022; # Remove write permission for group and other.
1345 # Validate 'rootdir' directory
1347 if test -n "$rootdir"
1349 if test -d "$rootdir" && test "$rootdir" != /
1351 # Remove slash from the end
1352 rootdir
="${rootdir%/}"
1354 # A workaround for graft-2.13+. The specified directory is
1355 # relative to the log file, we prepend it inside the rootdir
1357 eval "$(graft -L)" ; GRAFT_LOGFILE
="${GRAFT_LOGFILE:=/var/log/graft}"
1358 mkdir
-p -- "$rootdir$(dirname -- $GRAFT_LOGFILE)" || chkstatus_or_exit
1360 # Compose 'rootdir' and log file option to be used with graft(1)
1361 graft_r
="-r $rootdir -l $GRAFT_LOGFILE"
1363 # Unset variables coming from eval
1364 unset GRAFT_PERL GRAFT_LOGFILE GRAFT_TARGETDIR GRAFT_PACKAGEDIR
1366 warn
"${PROGRAM}: \`${rootdir}' is not a qualified root directory"
1372 # Ensure 'TMPDIR' creation to prefix temporary files
1374 if test ! -d "$TMPDIR"
1376 mkdir
-p -- "$TMPDIR" || chkstatus_or_exit
1380 # Process each package or recipe provided on the command-line