EVERYTHING FROM THE OTHER REPO

This commit is contained in:
2026-07-29 03:36:26 +03:00
parent 6777ea96db
commit 92a6ae42f5
4426 changed files with 1696506 additions and 2 deletions
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
+278
View File
@@ -0,0 +1,278 @@
#!/bin/sh -
#
# bashbug - create a bug report and mail it to the bug address
#
# The bug address depends on the release status of the shell. Versions
# with status `devel', `alpha', `beta', or `rc' mail bug reports to
# chet.ramey@case.edu and, optionally, to bash-testers@cwru.edu.
# Other versions send mail to bug-bash@gnu.org.
#
# Copyright (C) 1996-2021 Free Software Foundation, Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# configuration section:
# these variables are filled in by the make target in Makefile
#
MACHINE="arm"
OS="linux-gnueabihf"
CC="gcc"
CFLAGS="-g -O2 -Werror=implicit-function-declaration -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -Wall"
RELEASE="5.2"
PATCHLEVEL="37"
RELSTATUS="release"
MACHTYPE="arm-unknown-linux-gnueabihf"
PATH=/bin:/usr/bin:/usr/local/bin:$PATH
export PATH
# Check if TMPDIR is set, default to /tmp
: ${TMPDIR:=/tmp}
#Securely create a temporary directory for the temporary files
TEMPDIR=$TMPDIR/bbug.$$
(umask 077 && mkdir "$TEMPDIR") || {
echo "$0: could not create temporary directory" >&2
exit 1
}
TEMPFILE1=$TEMPDIR/bbug1
TEMPFILE2=$TEMPDIR/bbug2
USAGE="Usage: $0 [--help] [--version] [bug-report-email-address]"
VERSTR="GNU bashbug, version ${RELEASE}.${PATCHLEVEL}-${RELSTATUS}"
do_help= do_version=
while [ $# -gt 0 ]; do
case "$1" in
--help) shift ; do_help=y ;;
--version) shift ; do_version=y ;;
--) shift ; break ;;
-*) echo "bashbug: ${1}: invalid option" >&2
echo "$USAGE" >&2
exit 2 ;;
*) break ;;
esac
done
if [ -n "$do_version" ]; then
echo "${VERSTR}"
exit 0
fi
if [ -n "$do_help" ]; then
echo "${VERSTR}"
echo "${USAGE}"
echo
cat << HERE_EOF
Bashbug is used to send mail to the Bash maintainers
for when Bash doesn't behave like you'd like, or expect.
Bashbug will start up your editor (as defined by the shell's
EDITOR environment variable) with a preformatted bug report
template for you to fill in. The report will be mailed to the
bug-bash mailing list by default. See the manual for details.
If you invoke bashbug by accident, just quit your editor without
saving any changes to the template, and no bug report will be sent.
HERE_EOF
exit 0
fi
# Figure out how to echo a string without a trailing newline
N=`echo 'hi there\c'`
case "$N" in
*c) n=-n c= ;;
*) n= c='\c' ;;
esac
BASHTESTERS="bash-testers@cwru.edu"
case "$RELSTATUS" in
alpha*|beta*|devel*|rc*) BUGBASH=chet.ramey@case.edu ;;
*) BUGBASH=bug-bash@gnu.org ;;
esac
case "$RELSTATUS" in
alpha*|beta*|devel*|rc*)
echo "$0: This is a testing release. Would you like your bug report"
echo "$0: to be sent to the bash-testers mailing list?"
echo $n "$0: Send to bash-testers? $c"
read ans
case "$ans" in
y*|Y*) BUGBASH="${BUGBASH},${BASHTESTERS}" ;;
esac ;;
esac
BUGADDR="${1-$BUGBASH}"
if [ -z "$DEFEDITOR" ] && [ -z "$EDITOR" ]; then
if [ -x /usr/bin/editor ]; then
DEFEDITOR=editor
elif [ -x /usr/local/bin/ce ]; then
DEFEDITOR=ce
elif [ -x /usr/local/bin/emacs ]; then
DEFEDITOR=emacs
elif [ -x /usr/contrib/bin/emacs ]; then
DEFEDITOR=emacs
elif [ -x /usr/bin/emacs ]; then
DEFEDITOR=emacs
elif [ -x /usr/bin/xemacs ]; then
DEFEDITOR=xemacs
elif [ -x /usr/bin/vim; then
DEFEDITOR=vim
elif [ -x /usr/bin/gvim; then
DEFEDITOR=gvim
elif [ -x /usr/bin/nano ]; then
DEFEDITOR=nano
elif [ -x /usr/contrib/bin/jove ]; then
DEFEDITOR=jove
elif [ -x /usr/local/bin/jove ]; then
DEFEDITOR=jove
elif [ -x /usr/bin/vi ]; then
DEFEDITOR=vi
else
echo "$0: No default editor found: attempting to use vi" >&2
DEFEDITOR=vi
fi
fi
: ${EDITOR=$DEFEDITOR}
: ${USER=${LOGNAME-`whoami`}}
trap 'rm -rf "$TEMPDIR"; exit 1' 1 2 3 13 15
trap 'rm -rf "$TEMPDIR"' 0
UN=
if (uname) >/dev/null 2>&1; then
UN=`uname -a`
fi
if [ -f /usr/lib/sendmail ] ; then
RMAIL="/usr/lib/sendmail"
SMARGS="-i -t"
elif [ -f /usr/sbin/sendmail ] ; then
RMAIL="/usr/sbin/sendmail"
SMARGS="-i -t"
else
RMAIL=rmail
SMARGS="$BUGADDR"
fi
INITIAL_SUBJECT='[50 character or so descriptive subject here (for reference)]'
cat > "$TEMPFILE1" <<EOF
From: ${USER}
To: ${BUGADDR}
Subject: ${INITIAL_SUBJECT}
Configuration Information [Automatically generated, do not change]:
Machine: $MACHINE
OS: $OS
Compiler: $CC
Compilation CFLAGS: $CFLAGS
uname output: $UN
Machine Type: $MACHTYPE
Bash Version: $RELEASE
Patch Level: $PATCHLEVEL
Release Status: $RELSTATUS
Description:
[Detailed description of the problem, suggestion, or complaint.]
Repeat-By:
[Describe the sequence of events that causes the problem
to occur.]
Fix:
[Description of how to fix the problem. If you don't know a
fix for the problem, don't include this section.]
EOF
cp "$TEMPFILE1" "$TEMPFILE2"
chmod u+w "$TEMPFILE1"
trap '' 2 # ignore interrupts while in editor
edstat=1
while [ $edstat -ne 0 ]; do
$EDITOR "$TEMPFILE1"
edstat=$?
if [ $edstat -ne 0 ]; then
echo "$0: editor \`$EDITOR' exited with nonzero status."
echo "$0: Perhaps it was interrupted."
echo "$0: Type \`y' to give up, and lose your bug report;"
echo "$0: type \`n' to re-enter the editor."
echo $n "$0: Do you want to give up? $c"
read ans
case "$ans" in
[Yy]*) exit 1 ;;
esac
continue
fi
# find the subject from the temp file and see if it's been changed
CURR_SUB=`grep '^Subject: ' "$TEMPFILE1" | sed 's|^Subject:[ ]*||' | sed 1q`
case "$CURR_SUB" in
"${INITIAL_SUBJECT}")
echo
echo "$0: You have not changed the subject from the default."
echo "$0: Please use a more descriptive subject header."
echo "$0: Type \`y' to give up, and lose your bug report;"
echo "$0: type \`n' to re-enter the editor."
echo $n "$0: Do you want to give up? $c"
read ans
case "$ans" in
[Yy]*) exit 1 ;;
esac
echo "$0: The editor will be restarted in five seconds."
sleep 5
edstat=1
;;
esac
done
trap 'rm -rf "$TEMPDIR"; exit 1' 2 # restore trap on SIGINT
if cmp -s "$TEMPFILE1" "$TEMPFILE2"
then
echo "File not changed, no bug report submitted."
exit
fi
echo $n "Send bug report to ${BUGADDR}? [y/n] $c"
read ans
case "$ans" in
[Nn]*) exit 0 ;;
esac
${RMAIL} $SMARGS < "$TEMPFILE1" || {
cat "$TEMPFILE1" >> $HOME/dead.bashbug
echo "$0: mail to ${BUGADDR} failed: report saved in $HOME/dead.bashbug" >&2
echo "$0: please send it manually to ${BUGADDR}" >&2
}
exit 0
+1
View File
@@ -0,0 +1 @@
tic
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
+691
View File
@@ -0,0 +1,691 @@
#!/usr/bin/perl
# vim:ts=4:sw=4:expandtab
# © 2013-2014 Michael Stapelberg <stapelberg@debian.org>
#
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# * Neither the name of Michael Stapelberg nor the
# names of contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
# .
# THIS SOFTWARE IS PROVIDED BY Michael Stapelberg ''AS IS'' AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL Michael Stapelberg BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=head1 NAME
deb-systemd-helper - subset of systemctl for machines not running systemd
=head1 SYNOPSIS
B<deb-systemd-helper> enable | disable | purge | mask | unmask | is-enabled | was-enabled | debian-installed | update-state | reenable S<I<unit file> ...>
=head1 DESCRIPTION
B<deb-systemd-helper> is a Debian-specific helper script which re-implements
the enable, disable, is-enabled and reenable commands from systemctl.
The "enable" action will only be performed once (when first installing the
package). On the first "enable", a state file is created which will be deleted
upon "purge".
The "mask" action will keep state on whether the service was enabled/disabled
before and will properly return to that state on "unmask".
The "was-enabled" action is not present in systemctl, but is required in Debian
so that we can figure out whether a service was enabled before we installed an
updated service file. See http://bugs.debian.org/717603 for details.
The "debian-installed" action is also not present in systemctl. It returns 0 if
the state file of at least one of the given units is present.
The "update-state" action is also not present in systemctl. It updates
B<deb-systemd-helper>'s state file, removing obsolete entries (e.g. service
files that are no longer shipped by the package) and adding new entries (e.g.
new service files shipped by the package) without enabling them.
B<deb-systemd-helper> is intended to be used from maintscripts to enable
systemd unit files. It is specifically NOT intended to be used interactively by
users. Instead, users should run systemd and use systemctl, or not bother about
the systemd enabled state in case they are not running systemd.
=head1 ENVIRONMENT
=over 4
=item B<_DEB_SYSTEMD_HELPER_DEBUG>
If you export _DEB_SYSTEMD_HELPER_DEBUG=1, deb-systemd-helper will print debug
messages to stderr (thus visible in dpkg runs). Please include these when
filing a bugreport.
=item B<DPKG_ROOT>
Instead of working on the filesystem root /, perform all operations on a chroot
system in the directory given by DPKG_ROOT.
=back
=cut
use strict;
use warnings;
use File::Path qw(make_path); # in core since Perl 5.001
use File::Basename; # in core since Perl 5
use File::Temp qw(tempfile); # in core since Perl 5.6.1
use Getopt::Long; # in core since Perl 5
# Make Data::Dumper::Dumper available if present (not present on systems that
# only have perl-base, not perl).
eval { require Data::Dumper; } or *Data::Dumper::Dumper = sub { "no Data::Dumper" };
my $dpkg_root = $ENV{DPKG_ROOT} // '';
use constant {
SYSTEM_INSTANCE_ENABLED_STATE_DIR => '/var/lib/systemd/deb-systemd-helper-enabled',
USER_INSTANCE_ENABLED_STATE_DIR => '/var/lib/systemd/deb-systemd-user-helper-enabled',
SYSTEM_INSTANCE_MASKED_STATE_DIR => '/var/lib/systemd/deb-systemd-helper-masked',
USER_INSTANCE_MASKED_STATE_DIR => '/var/lib/systemd/deb-systemd-user-helper-masked',
};
my $quiet = 0;
my $instance = 'system';
my $enabled_state_dir = $dpkg_root . SYSTEM_INSTANCE_ENABLED_STATE_DIR;
my $masked_state_dir = $dpkg_root . SYSTEM_INSTANCE_MASKED_STATE_DIR;
# Globals are bad, but in this specific case, it really makes things much
# easier to write and understand.
my $changed_sth;
my $has_systemctl = -x "$dpkg_root/bin/systemctl" || -x "$dpkg_root/usr/bin/systemctl";
sub assertdpkgroot {
my ($path, $msg) = @_;
if (length $ENV{DPKG_ROOT}) {
if ($path !~ /^\Q$dpkg_root\E/) {
error("doesn't start with dpkg_root: $path $msg");
}
if ($path =~ /^\Q$dpkg_root$dpkg_root\E/) {
error("double dpkg_root: $path $msg");
}
}
}
sub assertnotdpkgroot {
my ($path, $msg) = @_;
if (length $ENV{DPKG_ROOT}) {
if ($path =~ /^\Q$dpkg_root\E/) {
error("starts with dpkg_root: $path $msg");
}
}
}
sub error {
print STDERR "$0: error: @_\n";
exit (1);
}
sub debug {
my ($msg) = @_;
return if !defined($ENV{_DEB_SYSTEMD_HELPER_DEBUG}) || $ENV{_DEB_SYSTEMD_HELPER_DEBUG} != 1;
print STDERR "(deb-systemd-helper DEBUG) $msg\n";
}
sub is_purge {
return (defined($ENV{_DEB_SYSTEMD_HELPER_PURGE}) && $ENV{_DEB_SYSTEMD_HELPER_PURGE} == 1)
}
sub find_unit {
my ($scriptname) = @_;
my $service_path = $scriptname;
if (-f "$dpkg_root/etc/systemd/$instance/$scriptname") {
$service_path = "/etc/systemd/$instance/$scriptname";
} elsif (-f "$dpkg_root/lib/systemd/$instance/$scriptname") {
$service_path = "/lib/systemd/$instance/$scriptname";
} elsif (-f "$dpkg_root/usr/lib/systemd/$instance/$scriptname") {
$service_path = "/usr/lib/systemd/$instance/$scriptname";
}
return $service_path;
}
sub dsh_state_path {
my ($scriptname) = @_;
return $enabled_state_dir . '/' . basename($scriptname) . '.dsh-also';
}
sub state_file_entries {
my ($dsh_state) = @_;
debug "Reading state file $dsh_state";
my @entries;
if (open(my $fh, '<', $dsh_state)) {
@entries = map { chomp; "$dpkg_root$_" } <$fh>;
close($fh);
}
return @entries;
}
# Writes $service_link into $dsh_state unless its already in there.
sub record_in_statefile {
my ($dsh_state, $service_link) = @_;
assertdpkgroot($dsh_state, "record_in_statefile");
assertnotdpkgroot($service_link, "record_in_statefile");
# Appending a newline makes the following code simpler; we can skip
# chomp()ing and appending newlines in every print.
$service_link .= "\n";
make_path(dirname($dsh_state));
my $line_exists;
my ($outfh, $tmpname) = tempfile('.stateXXXXX',
DIR => dirname($dsh_state),
SUFFIX => '.tmp',
UNLINK => 0);
chmod(0644, $tmpname);
if (-e $dsh_state) {
open(my $infh, '<', $dsh_state) or error("unable to read from $dsh_state");
while (<$infh>) {
$line_exists = 1 if $_ eq $service_link;
print $outfh $_;
}
close($infh);
}
print $outfh $service_link unless $line_exists;
close($outfh) or error("unable to close $tmpname");
debug "Renaming temp file $tmpname to state file $dsh_state";
rename($tmpname, $dsh_state) or
error("Unable to move $tmpname to $dsh_state");
}
# Gets the transitive closure of links, i.e. all links that need to be created
# when enabling this service file. Not straight-forward because service files
# can refer to other service files using Also=.
sub get_link_closure {
my ($scriptname, $service_path, @visited) = @_;
assertnotdpkgroot($service_path, "get_link_closure");
my @links;
my @wants_dirs;
my $unit_name = basename($service_path);
my $wanted_target = $unit_name;
# The keys parsed from the unit file below can only have unit names
# as values. Since unit names can't have whitespace in systemd,
# simply use split and strip any leading/trailing quotes. See
# systemd-escape(1) for examples of valid unit names.
open my $fh, '<', "$dpkg_root$service_path" or error("unable to read $dpkg_root$service_path");
while (my $line = <$fh>) {
chomp($line);
my $service_link;
if ($line =~ /^\s*(WantedBy|RequiredBy)=(.+)$/i) {
for my $value (split(/\s+/, $2)) {
$value =~ s/^(["'])(.*)\g1$/$2/;
my $wants_dir = "/etc/systemd/$instance/$value";
$wants_dir .= '.wants' if $1 eq 'WantedBy';
$wants_dir .= '.requires' if $1 eq 'RequiredBy';
push @wants_dirs, "$wants_dir/";
}
}
if ($line =~ /^\s*Also=(.+)$/i) {
for my $value (split(/\s+/, $1)) {
$value =~ s/^(["'])(.*)\g1$/$2/;
if ($value ne $unit_name and not grep $_ eq $value, @visited) {
# We can end up in an infinite recursion, so remember what units we
# already processed to break it
push @visited, $value;
push @links, get_link_closure($value, find_unit($value), @visited);
}
}
}
if ($line =~ /^\s*Alias=(.+)$/i) {
for my $value (split(/\s+/, $1)) {
$value =~ s/^(["'])(.*)\g1$/$2/;
if ($value ne $unit_name) {
push @links, { dest => $service_path, src => "/etc/systemd/$instance/$1" };
}
}
}
if ($line =~ /^\s*DefaultInstance=\s*(["']?+)(.+)\g1\s*$/i) {
$wanted_target = $2;
$wanted_target = $unit_name =~ s/^(.*\@)(\.\w+)$/$1$wanted_target$2/r;
}
}
close($fh);
for my $wants_dir (@wants_dirs) {
push @links, { dest => $service_path, src => $wants_dir . $wanted_target };
}
return @links;
}
sub all_links_installed {
my ($scriptname, $service_path) = @_;
my @links = get_link_closure($scriptname, $service_path);
foreach my $link (@links) {
assertnotdpkgroot($link->{src}, "all_links_installed");
}
my @missing_links = grep { ! -l "$dpkg_root$_->{src}" } @links;
return (@missing_links == 0);
}
sub no_link_installed {
my ($scriptname, $service_path) = @_;
my @links = get_link_closure($scriptname, $service_path);
foreach my $link (@links) {
assertnotdpkgroot($link->{src}, "all_links_installed");
}
my @existing_links = grep { -l "$dpkg_root$_->{src}" } @links;
return (@existing_links == 0);
}
sub enable {
my ($scriptname, $service_path) = @_;
if ($has_systemctl) {
# We use 'systemctl preset' on the initial installation only.
# On upgrade, we manually add the missing symlinks only if the
# service already has some links installed. Using 'systemctl
# preset' allows administrators and downstreams to alter the
# enable policy using systemd-native tools.
my $create_links = 0;
if (debian_installed($scriptname)) {
$create_links = 1 unless no_link_installed($scriptname, $service_path);
} else {
debug "Using systemctl preset to enable $scriptname";
my $systemd_root = '/';
if ($dpkg_root ne '') {
$systemd_root = $dpkg_root;
}
system("systemctl",
"--root=$systemd_root",
$instance eq "user" ? "--global" : "--system",
"--preset-mode=enable-only",
"preset", $scriptname) == 0
or error("systemctl preset failed on $scriptname: $!");
}
make_systemd_links($scriptname, $service_path, create_links => $create_links);
} else {
# We create all the symlinks ourselves
make_systemd_links($scriptname, $service_path);
}
}
sub make_systemd_links {
my ($scriptname, $service_path, %opts) = @_;
$opts{'create_links'} //= 1;
my $dsh_state = dsh_state_path($scriptname);
my @links = get_link_closure($scriptname, $service_path);
for my $link (@links) {
my $service_path = $link->{dest};
my $service_link = $link->{src};
record_in_statefile($dsh_state, $service_link);
my $statefile = $service_link;
$statefile =~ s,^/etc/systemd/$instance/,$enabled_state_dir/,;
$service_link = "$dpkg_root$service_link";
assertdpkgroot($statefile, "make_systemd_links");
assertdpkgroot($service_link, "make_systemd_links");
assertnotdpkgroot($service_path, "make_systemd_links");
next if -e $statefile;
if ($opts{'create_links'} && ! -l $service_link) {
make_path(dirname($service_link));
symlink($service_path, $service_link) or
error("unable to link $service_link to $service_path: $!");
$changed_sth = 1;
}
# Store the fact that we ran enable for this service_path,
# so that we can skip enable the next time.
# This allows us to call deb-systemd-helper unconditionally
# and still only enable unit files on the initial installation
# of a package.
make_path(dirname($statefile));
open(my $fh, '>>', $statefile) or error("Failed to create/touch $statefile");
close($fh) or error("Failed to create/touch $statefile");
}
}
# In contrary to make_systemd_links(), which only modifies the state file in an
# append-only fashion, update_state() can also remove entries from the state
# file.
#
# The distinction is important because update_state() should only be called
# when the unit file(s) are guaranteed to be on-disk, e.g. on package updates,
# but not on package removals.
sub update_state {
my ($scriptname, $service_path) = @_;
my $dsh_state = dsh_state_path($scriptname);
my @links = get_link_closure($scriptname, $service_path);
assertdpkgroot($dsh_state, "update_state");
debug "Old state file contents: " .
Data::Dumper::Dumper([ state_file_entries($dsh_state) ]);
make_path(dirname($dsh_state));
my ($outfh, $tmpname) = tempfile('.stateXXXXX',
DIR => dirname($dsh_state),
SUFFIX => '.tmp',
UNLINK => 0);
chmod(0644, $tmpname);
for my $link (@links) {
assertnotdpkgroot($link->{src}, "update_state");
print $outfh $link->{src} . "\n";
}
close($outfh) or error("Failed to close $tmpname");
debug "Renaming temp file $tmpname to state file $dsh_state";
rename($tmpname, $dsh_state) or
error("Unable to move $tmpname to $dsh_state");
debug "New state file contents: " .
Data::Dumper::Dumper([ state_file_entries($dsh_state) ]);
}
sub was_enabled {
my ($scriptname) = @_;
my @entries = state_file_entries(dsh_state_path($scriptname));
debug "Contents: " . Data::Dumper::Dumper(\@entries);
for my $link (@entries) {
assertdpkgroot($link, "was_enabled");
if (! -l $link) {
debug "Link $link is missing, considering $scriptname was-disabled.";
return 0;
}
}
debug "All links present, considering $scriptname was-enabled.";
return 1;
}
sub debian_installed {
my ($scriptname) = @_;
return -f dsh_state_path($scriptname);
}
sub remove_links {
my ($service_path) = @_;
my $dsh_state = dsh_state_path($service_path);
my @entries = state_file_entries($dsh_state);
debug "Contents: " . Data::Dumper::Dumper(\@entries);
assertdpkgroot($dsh_state, "remove_links");
assertnotdpkgroot($service_path, "remove_links");
if (is_purge()) {
unlink($dsh_state) if -e $dsh_state;
}
# Also disable all the units which were enabled when this one was enabled.
for my $link (@entries) {
# Delete the corresponding state file:
# • Always when purging
# • If the user did not disable (= link still exists) the service.
# If we dont do this, the link will be deleted a few lines down,
# but not re-created when re-installing the package.
assertdpkgroot($link, "remove_links");
if (is_purge() || -l $link) {
my $link_state = $link;
$link_state =~ s,^\Q$dpkg_root\E/etc/systemd/$instance/,$enabled_state_dir/,;
unlink($link_state);
}
next unless -l $link;
unlink($link) or
print STDERR "$0: unable to remove '$link': $!\n";
$changed_sth = 1;
}
# Read $service_path, recurse for all Also= units.
# This might not work when $service_path was already deleted,
# i.e. after apt-get remove. In this case we just return
# silently in order to not confuse the user about whether
# disabling actually worked or not — the case is handled by
# dh_installsystemd generating an appropriate disable
# command by parsing the service file at debhelper-time.
open(my $fh, '<', "$dpkg_root$service_path") or return;
while (my $line = <$fh>) {
chomp($line);
my $service_link;
if ($line =~ /^\s*Also=(.+)$/i) {
remove_links(find_unit($1));
}
}
close($fh);
}
# Recursively deletes a directory structure, if all (!) components are empty,
# e.g. to clean up after purging.
sub rmdir_if_empty {
my ($dir) = @_;
debug "rmdir_if_empty $dir";
rmdir_if_empty($_) for (grep { -d } <$dir/*>);
if (!rmdir($dir)) {
debug "rmdir($dir) failed ($!)";
}
}
sub mask_service {
my ($scriptname, $service_path) = @_;
my $mask_link = "$dpkg_root/etc/systemd/$instance/" . basename($service_path);
if (-e $mask_link) {
# If the link already exists, dont do anything.
return if -l $mask_link && readlink($mask_link) eq '/dev/null';
# If the file already exists, the user most likely copied the .service
# file to /etc/ to change it in some way. In this case we dont need to
# mask the .service in the first place, since it will not be removed by
# dpkg.
debug "$mask_link already exists, not masking.";
return;
}
make_path(dirname($mask_link));
# clean up after possible leftovers from Alias= to self (LP#1439793)
unlink($mask_link);
symlink('/dev/null', $mask_link) or
error("unable to link $mask_link to /dev/null: $!");
$changed_sth = 1;
my $statefile = $mask_link;
$statefile =~ s,^\Q$dpkg_root\E/etc/systemd/$instance/,$masked_state_dir/,;
# Store the fact that we masked this service, so that we can unmask it on
# installation time. We cannot unconditionally unmask because that would
# interfere with the users decision to mask a service.
make_path(dirname($statefile));
open(my $fh, '>>', $statefile) or error("Failed to create/touch $statefile");
close($fh) or error("Failed to create/touch $statefile");
}
sub unmask_service {
my ($scriptname, $service_path) = @_;
my $mask_link = "$dpkg_root/etc/systemd/$instance/" . basename($service_path);
# Not masked? Nothing to do.
return unless -e $mask_link;
if (! -l $mask_link || readlink($mask_link) ne '/dev/null') {
debug "Not unmasking $mask_link because it is not a link to /dev/null";
return;
}
my $statefile = $mask_link;
$statefile =~ s,^\Q$dpkg_root\E/etc/systemd/$instance/,$masked_state_dir/,;
if (! -e $statefile) {
debug "Not unmasking $mask_link because the state file $statefile does not exist";
return;
}
unlink($mask_link) or
error("unable to remove $mask_link: $!");
$changed_sth = 1;
unlink($statefile);
}
my $result = GetOptions(
"quiet" => \$quiet,
"user" => sub { $instance = 'user'; },
"system" => sub { $instance = 'system'; }, # default
);
if ($instance eq 'user') {
debug "is user unit = yes";
$enabled_state_dir = $dpkg_root . USER_INSTANCE_ENABLED_STATE_DIR;
$masked_state_dir = $dpkg_root . USER_INSTANCE_MASKED_STATE_DIR;
}
my $action = shift;
if (!defined($action)) {
# Called without arguments. Explain that this script should not be run interactively.
print "$0 is a program which should be called by dpkg maintscripts only.\n";
print "Please do not run it interactively, ever. Also see the manpage deb-systemd-helper(1).\n";
exit 0;
}
if (!$ENV{DPKG_MAINTSCRIPT_PACKAGE}) {
print STDERR "$0 was not called from dpkg. Exiting.\n";
exit 1;
}
if ($action eq 'purge') {
$ENV{_DEB_SYSTEMD_HELPER_PURGE} = 1;
$action = 'disable';
}
debug "is purge = " . (is_purge() ? "yes" : "no");
my $rc = 0;
if ($action eq 'is-enabled' ||
$action eq 'was-enabled' ||
$action eq 'debian-installed') {
$rc = 1;
}
for my $scriptname (@ARGV) {
my $service_path = find_unit($scriptname);
debug "action = $action, scriptname = $scriptname, service_path = $service_path";
if ($action eq 'is-enabled') {
my $enabled = all_links_installed($scriptname, $service_path);
print STDERR ($enabled ? "enabled\n" : "disabled\n") unless $quiet;
$rc = 0 if $enabled;
}
# was-enabled is the same as is-enabled, but only considers links recorded
# in the state file. This is useful after package upgrades, to determine
# whether the unit file was enabled before upgrading, even if the unit file
# has changed and is not entirely enabled currently (due to a new Alias=
# line for example).
#
# If all machines were running systemd, this issue would not be present
# because is-enabled would query systemd, which would not have picked up
# the new unit file yet.
if ($action eq 'was-enabled') {
my $enabled = was_enabled($scriptname);
print STDERR ($enabled ? "enabled\n" : "disabled\n") unless $quiet;
$rc = 0 if $enabled;
}
if ($action eq 'update-state') {
update_state($scriptname, $service_path);
}
if ($action eq 'debian-installed') {
$rc = 0 if debian_installed($scriptname);
}
if ($action eq 'reenable') {
remove_links($service_path);
make_systemd_links($scriptname, $service_path);
}
if ($action eq 'disable') {
remove_links($service_path);
# Clean up the state dir if its empty, or at least clean up all empty
# subdirectories. Necessary to cleanly pass a piuparts run.
rmdir_if_empty($dpkg_root . SYSTEM_INSTANCE_ENABLED_STATE_DIR);
rmdir_if_empty($dpkg_root . USER_INSTANCE_ENABLED_STATE_DIR);
# Same with directories below /etc/systemd, where we create symlinks.
# If systemd is not installed (and no other package shipping service
# files), this would make piuparts fail, too.
rmdir_if_empty($_) for (grep { -d } <$dpkg_root/etc/systemd/system/*>);
rmdir_if_empty($_) for (grep { -d } <$dpkg_root/etc/systemd/user/*>);
}
if ($action eq 'enable') {
enable($scriptname, $service_path);
}
if ($action eq 'mask') {
mask_service($scriptname, $service_path);
}
if ($action eq 'unmask') {
unmask_service($scriptname, $service_path);
# Clean up the state dir if its empty, or at least clean up all empty
# subdirectories. Necessary to cleanly pass a piuparts run.
rmdir_if_empty($dpkg_root . SYSTEM_INSTANCE_MASKED_STATE_DIR);
rmdir_if_empty($dpkg_root . USER_INSTANCE_MASKED_STATE_DIR);
}
}
# If we changed anything and this machine is running systemd, tell
# systemd to reload so that it will immediately pick up our
# changes.
if (!length $ENV{DPKG_ROOT} && $changed_sth && $instance eq 'system' && -d "/run/systemd/system") {
system("systemctl", "daemon-reload");
}
exit $rc;
=head1 AUTHOR
Michael Stapelberg <stapelberg@debian.org>
=cut
+187
View File
@@ -0,0 +1,187 @@
#!/usr/bin/perl
# vim:ts=4:sw=4:expandtab
# © 2013 Michael Stapelberg <stapelberg@debian.org>
#
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# * Neither the name of Michael Stapelberg nor the
# names of contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
# .
# THIS SOFTWARE IS PROVIDED BY Michael Stapelberg ''AS IS'' AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL Michael Stapelberg BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=head1 NAME
deb-systemd-invoke - wrapper around systemctl, respecting policy-rc.d
=head1 SYNOPSIS
B<deb-systemd-invoke> [B<--user>] start|stop|restart S<I<unit file> ...>
B<deb-systemd-invoke> [B<--user>] [B<--no-dbus>] daemon-reload|daemon-reexec
=head1 DESCRIPTION
B<deb-systemd-invoke> is a Debian-specific helper script which asks
/usr/sbin/policy-rc.d before performing a systemctl call.
B<deb-systemd-invoke> is intended to be used from maintscripts to manage
systemd unit files. It is specifically NOT intended to be used interactively by
users. Instead, users should run systemd and use systemctl, or not bother about
the systemd enabled state in case they are not running systemd.
=cut
use strict;
use warnings;
use Getopt::Long; # in core since Perl 5
if (@ARGV < 2) {
print STDERR "Syntax: $0 <action> [<unit file> [<unit file> ...]]\n";
exit 1;
}
my $is_system = 1;
my $use_dbus = 1;
my @instances = ();
my $result = GetOptions(
"user" => sub { $is_system = 0; },
"system" => sub { $is_system = 1; }, # default
"no-dbus" => sub { $use_dbus = 0; },
);
my $policyhelper = '/usr/sbin/policy-rc.d';
if (length $ENV{DPKG_ROOT}) {
$policyhelper = $ENV{DPKG_ROOT} . $policyhelper;
}
my @units = @ARGV;
my $action = shift @units;
if (-x $policyhelper) {
for my $unit (@units) {
system(qq|$policyhelper $unit "$action"|);
# 0 or 104 means run
# 101 means do not run
my $exitcode = ($? >> 8);
if ($exitcode == 101) {
print STDERR "$policyhelper returned 101, not running '" . join(' ', @ARGV) . "'\n";
exit 0;
} elsif ($exitcode != 104 && $exitcode != 0) {
print STDERR "deb-systemd-invoke only supports $policyhelper return codes 0, 101, and 104!\n";
print STDERR "Got return code $exitcode, ignoring.\n";
}
}
}
if (!$is_system) {
# '--machine <ID>@' was added in v250 and v249.10, before that we can't talk to arbitrary user instances
my $systemctl_version = `systemctl --version --quiet | sed -n -r "s/systemd ([0-9]+) \\(.*/\\1/p"`;
chomp ($systemctl_version);
if (system('dpkg', '--compare-versions', $systemctl_version, 'ge', '249') != 0) {
print STDERR "systemctl version $systemctl_version does not support acting on user instance, skipping\n";
exit 0;
}
# Each user instance of the manager has a corresponding user@<id<.service unit.
# Get the full list of IDs, so that we can talk to each user instance to start/stop
# user units.
@instances = `systemctl --no-legend --quiet list-units 'user@*' | sed -n -r 's/.*user@([0-9]+).service.*/\\1/p'`;
} else {
push @instances, 'system';
}
# If the job is disabled and is not currently running, the job is not started or restarted.
# However, if the job is disabled but has been forced into the running state, we *do* stop
# and restart it since this is expected behaviour for the admin who forced the start.
# We don't autostart static units either.
if ($action eq "start" || $action eq "restart") {
my $global_exit_code = 0;
my @start_units = ();
for my $instance (@instances) {
my @instance_args = ();
if ($instance eq 'system') {
push @instance_args, '--system';
} else {
chomp ($instance);
push @instance_args, '--user', '--machine', "$instance@";
}
for my $unit (@units) {
my $unit_installed = 0;
my $enabled_output = `systemctl @instance_args is-enabled -- '$unit'`;
# matching enabled and enabled-runtime as an installed non static unit
if ($enabled_output =~ /enabled/) {
$unit_installed = 1;
}
system('systemctl', @instance_args, '--quiet', 'is-active', '--', $unit);
my $unit_active = $?>>8 == 0 ? 1 : 0;
if (!$unit_installed && $action eq "start") {
print STDERR "$unit is a disabled or a static unit, not starting it.\n";
} elsif (!$unit_installed && !$unit_active && $action eq "restart") {
print STDERR "$unit is a disabled or a static unit not running, not starting it.\n";
}
else {
push @start_units, $unit;
}
}
if (@start_units) {
system('systemctl', '--quiet', @instance_args, $action, @start_units) == 0 or die("Could not execute systemctl: $!");
}
}
exit(0);
} elsif ($action eq "stop" && !$is_system) {
my $global_exit_code = 0;
for my $instance (@instances) {
chomp ($instance);
system('systemctl', '--quiet', '--user', '--machine', "$instance@", $action, @units);
}
exit(0);
} elsif (($action eq "daemon-reload" || $action eq "daemon-reexec") && !$is_system && $use_dbus) {
my $global_exit_code = 0;
for my $instance (@instances) {
chomp ($instance);
system('systemctl', '--quiet', '--user', '--machine', "$instance@", $action);
}
exit(0);
} elsif (($action eq "daemon-reload" || $action eq "daemon-reexec") && !$use_dbus) {
my $global_exit_code = 0;
my $signal;
if ($action eq "daemon-reload") {
$signal = 'SIGHUP';
} else {
$signal = 'SIGRTMIN+25';
}
if ($is_system) {
system('kill', '-s', $signal, '1');
} else {
system('systemctl', '--quiet', 'kill', '--kill-whom=main', '--signal', $signal, 'user@*.service');
}
exit(0);
} else {
exec('systemctl', @ARGV);
}
+121
View File
@@ -0,0 +1,121 @@
#!/usr/bin/perl
=head1 NAME
debconf - run a debconf-using program
=cut
=head1 SYNOPSIS
debconf [options] command [args]
=head1 DESCRIPTION
Debconf is a configuration system for Debian packages. For a debconf
overview and documentation for sysadmins, see L<debconf(7)> (in the
debconf-doc package).
The B<debconf> program runs a program under debconf's control, setting it up
to talk with debconf on stdio. The program's output is expected to be debconf
protocol commands, and it is expected to read result codes on stdin. See
L<debconf-devel(7)> for details about the debconf protocol.
The command to be run under debconf must be specified in a way that will
let your PATH find it.
This command is not the usual way that debconf is used. It's more typical
for debconf to be used via L<dpkg-preconfigure(8)> or L<dpkg-reconfigure(8)>.
=head1 OPTIONS
=over 4
=item B<-o>I<package>, B<--owner=>I<package>
Tell debconf what package the command it is running is a part of. This is
necessary to get ownership of registered questions right, and to support
unregister and purge commands properly.
=item B<-f>I<type>, B<--frontend=>I<type>
Select the frontend to use.
=item B<-p>I<value>, B<--priority=>I<value>
Specify the minimum priority of question that will be displayed.
=item B<--terse>
Enables terse output mode. This affects only some frontends.
=back
=head1 EXAMPLES
To debug a shell script that uses debconf, you might use:
DEBCONF_DEBUG=developer debconf my-shell-prog
Or, you might use this:
debconf --frontend=readline sh -x my-shell-prog
=head1 SEE ALSO
L<debconf-devel(7)>, L<debconf(7)>
=cut
use warnings;
use strict;
use Debconf::Db;
use Debconf::AutoSelect qw(:all);
use Debconf::Gettext;
use Debconf::Config;
# Find the end of the options for this command, and the beginning of the
# command to run, which may have arguments. Break those arguments out.
my (@argv, @command);
for (my $x=0; $x <= $#ARGV; $x++) {
if ($ARGV[$x] =~ /^-(o|f|p|-(owner|frontend|priority))$/) {
push @argv, $ARGV[$x++];
push @argv, $ARGV[$x] if defined $ARGV[$x]; # skip option argument
next;
}
elsif ($ARGV[$x] =~ /^-/) {
push @argv, $ARGV[$x];
}
else {
# end of arguments, start of command
@command=@ARGV[$x..$#ARGV];
last;
}
}
@ARGV=@argv;
my $usage = gettext("Usage: debconf [options] command [args]");
my $owner='';
Debconf::Config->getopt($usage.gettext(qq{
-o, --owner=package Set the package that owns the command.}),
"o|owner=s" => \$owner,
);
die "$usage\n" unless @command;
Debconf::Db->load;
my $frontend=make_frontend();
my $confmodule=make_confmodule(@command);
$confmodule->owner($owner) if length $owner;
1 while ($confmodule->communicate);
my $code=$confmodule->exitcode;
$frontend->shutdown;
$confmodule->finish;
Debconf::Db->save;
exit $code;
=head1 AUTHOR
Joey Hess <joeyh@debian.org>
=cut
+494
View File
@@ -0,0 +1,494 @@
#!/usr/bin/perl
# This file was preprocessed, do not edit!
use warnings;
use strict;
use POSIX;
use Fcntl;
use Getopt::Long;
use Debconf::Client::ConfModule ();
my ($config, $start, $from, $to, $stop);
my $progress=1;
my $dlwaypoint=15;
my ($logfile, $logstderr);
my $had_frontend;
our ($status_read, $status_write);
our ($command_read, $command_write);
our ($debconf_command_read, $debconf_command_write);
our ($debconf_reply_read, $debconf_reply_write);
our $apt_log;
sub checkopen (@) {
my $file = $_[0];
my $fd = POSIX::open($file, &POSIX::O_RDONLY);
defined $fd or die "$0: can't open $file: $!\n";
return $fd;
}
sub checkclose ($) {
my $fd = $_[0];
unless (POSIX::close($fd)) {
return if $! == &POSIX::EBADF;
die "$0: can't close fd $fd: $!\n";
}
}
sub checkdup2 ($$) {
my ($oldfd, $newfd) = @_;
checkclose($newfd);
POSIX::dup2($oldfd, $newfd)
or die "$0: can't dup fd $oldfd to $newfd: $!\n";
}
sub nocloexec ($) {
my $fh = shift;
my $flags = fcntl($fh, F_GETFD, 0);
fcntl($fh, F_SETFD, $flags & ~FD_CLOEXEC);
}
sub nonblock ($) {
my $fh = shift;
my $flags = fcntl($fh, F_GETFL, 0);
fcntl($fh, F_SETFL, $flags | O_NONBLOCK);
}
sub reservefds (@) {
my $null = checkopen('/dev/null');
my $close = 1;
for my $fd (@_) {
if ($null == $fd) {
$close = 0;
} else {
checkclose($fd);
checkdup2($null, $fd);
}
}
if ($close) {
checkclose($null);
}
}
sub envnonempty ($) {
my $name = shift;
return (exists $ENV{$name} and $ENV{$name} ne '');
}
sub start_debconf (@) {
if (! $ENV{DEBIAN_HAS_FRONTEND}) {
if (envnonempty('DEBCONF_DB_REPLACE')) {
$ENV{DEBCONF_APT_PROGRESS_DB_REPLACE} =
$ENV{DEBCONF_DB_REPLACE};
}
if (envnonempty('DEBCONF_DB_OVERRIDE')) {
$ENV{DEBCONF_APT_PROGRESS_DB_OVERRIDE} =
$ENV{DEBCONF_DB_OVERRIDE};
}
$ENV{DEBCONF_DB_REPLACE} = 'configdb';
$ENV{DEBCONF_DB_OVERRIDE} = 'Pipe{infd:none outfd:none}';
$ENV{DEBCONF_APT_PROGRESS_NO_FRONTEND} = 1;
@ARGV = @_;
}
import Debconf::Client::ConfModule;
}
sub passthrough (@) {
my $priority = Debconf::Client::ConfModule::get('debconf/priority');
defined(my $pid = fork) or die "$0: can't fork: $!\n";
if (!$pid) {
close $status_read;
close $command_write;
close $debconf_command_read;
close $debconf_reply_write;
$^F = 6; # avoid close-on-exec
if (fileno($command_read) != 0) {
checkdup2(fileno($command_read), 0);
close $command_read;
}
if (fileno($apt_log) != 1) {
checkclose(1);
checkdup2(fileno($apt_log), 1);
}
if (fileno($apt_log) != 2) {
checkclose(2);
checkdup2(fileno($apt_log), 2);
}
close $apt_log;
delete $ENV{DEBIAN_HAS_FRONTEND};
delete $ENV{DEBCONF_REDIR};
delete $ENV{DEBCONF_SYSTEMRC};
delete $ENV{DEBCONF_PIPE}; # just in case ...
$ENV{DEBIAN_FRONTEND} = 'passthrough';
$ENV{DEBIAN_PRIORITY} = $priority;
$ENV{DEBCONF_READFD} = 5;
$ENV{DEBCONF_WRITEFD} = 6;
$ENV{APT_LISTCHANGES_FRONTEND} = 'none';
if ($had_frontend) {
$ENV{DEBCONF_DB_REPLACE} = 'configdb';
$ENV{DEBCONF_DB_OVERRIDE} = 'Pipe{infd:none outfd:none}';
}
exec @_ or die "can't exec $_[0]: $!";
}
close $status_write;
close $command_read;
close $debconf_command_write;
close $debconf_reply_read;
return $pid;
}
sub handle_status ($$$) {
my ($from, $to, $line) = @_;
my ($status, $pkg, $percent, $description) = split ':', $line, 4;
my ($min, $len);
if ($status eq 'dlstatus') {
$min = 0;
$len = $dlwaypoint;
}
elsif ($status eq 'pmstatus') {
$min = $dlwaypoint;
$len = 100 - $dlwaypoint;
}
elsif ($status eq 'media-change') {
Debconf::Client::ConfModule::subst(
'debconf-apt-progress/media-change', 'MESSAGE',
$description);
my @ret = Debconf::Client::ConfModule::input(
'critical', 'debconf-apt-progress/media-change');
$ret[0] == 0 or die "Can't display media change request!\n";
Debconf::Client::ConfModule::go();
print $command_write "\n" ||
die "can't talk to command fd: $!";
return;
}
else {
return;
}
$percent = ($percent * $len / 100 + $min);
$percent = ($percent * ($to - $from) / 100 + $from);
$percent =~ s/\..*//;
if ($progress) {
my @ret=Debconf::Client::ConfModule::progress('SET', $percent);
if ($ret[0] eq '30') {
cancel();
}
}
Debconf::Client::ConfModule::subst(
'debconf-apt-progress/info', 'DESCRIPTION', $description);
my @ret=Debconf::Client::ConfModule::progress(
'INFO', 'debconf-apt-progress/info');
if ($ret[0] eq '30') {
cancel();
}
}
sub handle_debconf_command ($) {
my $line = shift;
print "$line\n" || die "can't write to stdout: $!";
my $ret = <STDIN>;
chomp $ret;
print $debconf_reply_write "$ret\n" ||
die "can't write to \$debconf_reply_write: $!";
}
my $pid;
sub run_progress ($$@) {
my $from = shift;
my $to = shift;
my $command = shift;
local ($status_read, $status_write);
local ($command_read, $command_write);
local ($debconf_command_read, $debconf_command_write);
local ($debconf_reply_read, $debconf_reply_write);
local $apt_log;
use IO::Handle;
if ($progress) {
my @ret=Debconf::Client::ConfModule::progress(
'INFO', 'debconf-apt-progress/preparing');
if ($ret[0] eq '30') {
cancel();
return 30;
}
}
reservefds(4, 5, 6);
pipe $status_read, $status_write
or die "$0: can't create status pipe: $!";
nonblock($status_read);
checkdup2(fileno($status_write), 4);
open $status_write, '>&=', 4
or die "$0: can't reopen \$status_write as fd 4: $!";
nocloexec($status_write);
pipe $command_read, $command_write
or die "$0: can't create command pipe: $!";
nocloexec($command_read);
$command_write->autoflush(1);
pipe $debconf_command_read, $debconf_command_write
or die "$0: can't create debconf command pipe: $!";
nonblock($debconf_command_read);
checkdup2(fileno($debconf_command_write), 6);
open $debconf_command_write, '>&=', 6
or die "$0: can't reopen \$debconf_command_write as fd 6: $!";
nocloexec($debconf_command_write);
pipe $debconf_reply_read, $debconf_reply_write
or die "$0: can't create debconf reply pipe: $!";
checkdup2(fileno($debconf_reply_read), 5);
open $debconf_reply_read, '<&=', 5
or die "$0: can't reopen \$debconf_reply_read as fd 5: $!";
nocloexec($debconf_reply_read);
$debconf_reply_write->autoflush(1);
if (defined $logfile) {
open $apt_log, '>>', $logfile
or die "$0: can't open $logfile: $!";
} elsif ($logstderr) {
open $apt_log, '>&', \*STDERR
or die "$0: can't duplicate stderr: $!";
} else {
open $apt_log, '>', '/dev/null'
or die "$0: can't open /dev/null: $!";
}
nocloexec($apt_log);
$pid = passthrough $command,
'-o', 'APT::Status-Fd=4',
'-o', 'APT::Keep-Fds::=5',
'-o', 'APT::Keep-Fds::=6',
@_;
my $status_eof = 0;
my $debconf_command_eof = 0;
my $status_buf = '';
my $debconf_command_buf = '';
while (not $status_eof) {
my $rin = '';
my $rout;
vec($rin, fileno($status_read), 1) = 1;
vec($rin, fileno($debconf_command_read), 1) = 1
unless $debconf_command_eof;
my $sel = select($rout = $rin, undef, undef, undef);
if ($sel < 0) {
next if $! == &POSIX::EINTR;
die "$0: select failed: $!";
}
if (vec($rout, fileno($status_read), 1) == 1) {
while (1) {
my $r = sysread($status_read, $status_buf,
4096, length $status_buf);
if (not defined $r) {
next if $! == &POSIX::EINTR;
last if $! == &POSIX::EAGAIN or
$! == &POSIX::EWOULDBLOCK;
die "$0: read \$status_read failed: $!";
}
elsif ($r == 0) {
if ($status_buf ne '' and
$status_buf !~ /\n$/) {
$status_buf .= "\n";
}
$status_eof = 1;
last;
}
last if $status_buf =~ /\n/;
}
while ($status_buf =~ /\n/) {
my $status_line;
($status_line, $status_buf) =
split /\n/, $status_buf, 2;
handle_status $from, $to, $status_line;
}
}
if (vec($rout, fileno($debconf_command_read), 1) == 1) {
while (1) {
my $r = sysread($debconf_command_read,
$debconf_command_buf, 4096,
length $debconf_command_buf);
if (not defined $r) {
next if $! == &POSIX::EINTR;
last if $! == &POSIX::EAGAIN or
$! == &POSIX::EWOULDBLOCK;
die "$0: read " .
"\$debconf_command_read " .
"failed: $!";
}
elsif ($r == 0) {
if ($debconf_command_buf ne '' and
$debconf_command_buf !~ /\n$/) {
$debconf_command_buf .= "\n";
}
$debconf_command_eof = 1;
last;
}
last if $debconf_command_buf =~ /\n/;
}
while ($debconf_command_buf =~ /\n/) {
my $debconf_command_line;
($debconf_command_line, $debconf_command_buf) =
split /\n/, $debconf_command_buf, 2;
handle_debconf_command $debconf_command_line;
}
}
}
waitpid $pid, 0;
undef $pid;
my $status = $?;
if ($progress) {
my @ret=Debconf::Client::ConfModule::progress('SET', $to);
if ($ret[0] eq '30') {
cancel();
}
}
if ($status & 127) {
return 127;
}
return ($status >> 8);
}
my $cancelled=0;
my $cancel_sent_signal=0;
sub cancel () {
$cancelled++;
if (defined $pid) {
$cancel_sent_signal++;
if ($cancel_sent_signal == 1) {
kill INT => $pid;
}
else {
kill KILL => $pid;
}
}
}
sub start_bar ($$) {
my ($from, $to) = @_;
if ($progress) {
Debconf::Client::ConfModule::progress(
'START', $from, $to, 'debconf-apt-progress/title');
my @ret=Debconf::Client::ConfModule::progress(
'INFO', 'debconf-apt-progress/preparing');
if ($ret[0] eq '30') {
cancel();
}
}
}
sub stop_bar () {
Debconf::Client::ConfModule::progress('STOP') if $progress;
Debconf::Client::ConfModule::stop() unless $had_frontend;
}
if (envnonempty('DEBCONF_APT_PROGRESS_DB_REPLACE')) {
$ENV{DEBCONF_DB_REPLACE} = $ENV{DEBCONF_APT_PROGRESS_DB_REPLACE};
} else {
delete $ENV{DEBCONF_DB_REPLACE};
}
if (envnonempty('DEBCONF_APT_PROGRESS_DB_OVERRIDE')) {
$ENV{DEBCONF_DB_OVERRIDE} = $ENV{DEBCONF_APT_PROGRESS_DB_OVERRIDE};
} else {
delete $ENV{DEBCONF_DB_OVERRIDE};
}
$had_frontend = 1 unless $ENV{DEBCONF_APT_PROGRESS_NO_FRONTEND};
delete $ENV{DEBCONF_APT_PROGRESS_NO_FRONTEND}; # avoid inheritance
my @saved_argv = @ARGV;
my $result = GetOptions('config' => \$config,
'start' => \$start,
'from=i' => \$from,
'to=i' => \$to,
'stop' => \$stop,
'logfile=s' => \$logfile,
'logstderr' => \$logstderr,
'progress!' => \$progress,
'dlwaypoint=i' => \$dlwaypoint,
);
if (! $progress && ($start || $from || $to || $stop)) {
die "--no-progress cannot be used with --start, --from, --to, or --stop\n";
}
unless ($start) {
if (defined $from and not defined $to) {
die "$0: --from requires --to\n";
} elsif (defined $to and not defined $from) {
die "$0: --to requires --from\n";
}
}
my $mutex = 0;
++$mutex if $config;
++$mutex if $start;
++$mutex if $stop;
if ($mutex > 1) {
die "$0: must use only one of --config, --start, or --stop\n";
}
if (($config or $stop) and (defined $from or defined $to)) {
die "$0: cannot use --from or --to with --config or --stop\n";
}
start_debconf(@saved_argv) unless $config;
my $status = 0;
if ($config) {
print <<'EOF';
DEBCONF_APT_PROGRESS_DB_REPLACE="$DEBCONF_DB_REPLACE"
DEBCONF_APT_PROGRESS_DB_OVERRIDE="$DEBCONF_DB_OVERRIDE"
export DEBCONF_APT_PROGRESS_DB_REPLACE DEBCONF_APT_PROGRESS_DB_OVERRIDE
DEBCONF_DB_REPLACE=configdb
DEBCONF_DB_OVERRIDE='Pipe{infd:none outfd:none}'
export DEBCONF_DB_REPLACE DEBCONF_DB_OVERRIDE
EOF
} elsif ($start) {
$from = 0 unless defined $from;
$to = 100 unless defined $to;
start_bar($from, $to);
} elsif (defined $from) {
$status = run_progress($from, $to, @ARGV);
} elsif ($stop) {
stop_bar();
} else {
start_bar(0, 100);
if (! $cancelled) {
$status = run_progress(0, 100, @ARGV);
stop_bar();
}
}
if ($cancelled) {
Debconf::Client::ConfModule::get("debconf/priority");
exit 30;
}
elsif ($status == 30) {
exit 3;
}
else {
exit $status;
}
+34
View File
@@ -0,0 +1,34 @@
#!/usr/bin/perl
# This file was preprocessed, do not edit!
use warnings;
use strict;
use Debconf::Db;
use Debconf::AutoSelect qw(:all);
use Debconf::Config;
use Debconf::Gettext;
Debconf::Db->load;
Debconf::Config->getopt(gettext("Usage: debconf-communicate [options] [package]"));
my $frontend=make_frontend();
my $confmodule=make_confmodule();
$confmodule->owner(shift) if @ARGV;
my $code=127;
autoflush STDOUT 1;
while (<STDIN>) {
chomp;
my $ret=$confmodule->process_command($_);
($code, undef)=split(/ /, $ret, 2);
print "$ret\n";
}
$frontend->shutdown;
$confmodule->finish;
Debconf::Db->save;
exit $code;
+81
View File
@@ -0,0 +1,81 @@
#!/usr/bin/perl
# This file was preprocessed, do not edit!
use warnings;
use strict;
use Getopt::Long;
use Debconf::Log qw{:all};
use Debconf::Db;
use Debconf::DbDriver;
use Debconf::DbDriver::Backup;
sub usage {
print STDERR <<EOF;
Usage: debconf-copydb sourcedb destdb [--pattern=pattern] [--owner-pattern=pattern] [--config=Foo:bar]
EOF
exit(1);
}
my $pattern='.*';
my $owner_pattern;
my %config;
sub config {
my ($field, $value)=split(/\s*:\s*/, $_[1], 2);
$field=~tr/-/_/;
$field=lc($field);
die "Parse error: \"$_[1]\"" unless defined $field and length $field;
if ($field eq 'name') {
if ($config{name}) {
Debconf::Db->makedriver(%config);
}
elsif (%config) {
warn "ignoring command line config data before $_[1]";
}
%config=();
}
$config{$field}=$value;
}
GetOptions(
"pattern|p=s" => \$pattern,
"config|c=s" => \&config,
"owner-pattern=s" => \$owner_pattern,
) || usage();
Debconf::Db->makedriver(%config) if %config;
my $srcname=shift || usage();
my $destname=shift || usage();
Debconf::Db->load;
my $src=Debconf::DbDriver->driver($srcname);
die "$0: source database, \"$srcname\" does not exist\n" unless ref $src;
my $dest=Debconf::DbDriver->driver($destname);
die "$0: destination database, \"$destname\" does not exist\n" unless ref $dest;
my $copier=Debconf::DbDriver::Backup->new(
db => $src, backupdb => $dest, name => 'copier');
my $i=$copier->iterator;
while (my $item=$i->iterate) {
next unless $item =~ /$pattern/;
if (defined $owner_pattern) {
my $fit_owner = 0;
foreach my $owner ($src->owners($item)){
$fit_owner = 1 if $owner =~ /$owner_pattern/;
}
next unless $fit_owner;
}
$copier->copy($item, $src, $dest);
}
$copier->shutdown;
+48
View File
@@ -0,0 +1,48 @@
#!/usr/bin/perl
# This file was preprocessed, do not edit!
use warnings;
use strict;
use Getopt::Long;
use vars qw($escape $unescape);
sub usage {
print STDERR <<EOF;
Usage: debconf-unescape -e|-u < input-text
-e, --escape escape text
-u, --unescape unescape text
Exactly one of -e or -u must be used.
EOF
exit(1);
}
$escape=0;
$unescape=0;
GetOptions(
"escape|e" => \$escape,
"unescape|u" => \$unescape,
) || usage();
if ($escape == $unescape) {
usage();
}
if ($escape) {
while (<STDIN>) {
s/\\/\\\\/g;
s/\n/\\n/g;
print;
}
} else {
while (<STDIN>) {
for (split /(\\.)/) {
s/\\(.)/$1 eq "n" ? "\n" : $1/eg;
print;
}
}
}
+156
View File
@@ -0,0 +1,156 @@
#!/usr/bin/perl
# This file was preprocessed, do not edit!
use warnings;
use strict;
use Debconf::Db;
use Debconf::Template;
use Getopt::Long;
use vars qw(%opts $filename $debug $error $checkonly $unseen);
sub usage {
print STDERR <<EOF;
Usage: debconf-set-selections [-vcu] [file]
-v, --verbose verbose output
-c, --checkonly only check the input file format
-u, --unseen do not set the 'seen' flag when preseeding values
EOF
exit(1);
}
sub info {
my $msg = shift;
print STDERR "info: $msg\n" if $debug;
}
sub warning {
my $msg = shift;
print STDERR "warning: $msg\n";
}
sub error {
my $msg = shift;
print STDERR "error: $msg\n";
$error++
}
sub load_answer {
my ($owner, $label, $type, $content) = @_;
info "Loading answer for '$label'";
my $template=Debconf::Template->get($label);
if (! $template) {
$template=Debconf::Template->new($label, $owner, $type);
$template->description("Dummy template");
$template->extended_description("This is a fake template used to pre-seed the debconf database. If you are seeing this, something is probably wrong.");
}
$template->type($type);
my $question=Debconf::Question->get($label);
if (! $question) {
error("Cannot find a question for $label");
return;
}
$question->addowner($owner, $type);
$question->value($content);
if (! $unseen) {
$question->flag("seen", "true");
}
}
sub set_flag {
my ($owner, $label, $flag, $content) = @_;
info "Setting $flag flag";
my $question=Debconf::Question->get($label);
if (! $question) {
error("Cannot find a question for $label");
return;
}
$question->flag($flag, $content);
}
my @knowntypes = qw(select boolean string multiselect note password text title);
my @knownflags = qw(seen);
sub ok_format {
my ($owner, $label, $type, $content) = @_;
if (! defined $owner || ! defined $label || ! defined $content) {
error "parse error on line $.: '$_'";
return;
}
elsif (! grep { $_ eq $type } @knowntypes, @knownflags) {
warning "Unknown type $type, skipping line $.";
return;
}
else {
return 1;
}
}
sub mungeline ($) {
my $line=shift;
chomp $line;
$line=~s/\r$//;
return $line;
}
GetOptions(
"verbose|v" => \$debug,
"checkonly|c" => \$checkonly,
"unseen|u" => \$unseen,
) || usage();
{
local $ENV{DEBCONF_NOWARNINGS} = 'yes' if $checkonly;
Debconf::Db->load;
}
$error = 0;
unshift @ARGV, '-' unless @ARGV;
foreach my $filename (@ARGV) {
my $input;
if ($filename eq '-') {
$input = \*STDIN;
} elsif (not open $input, '<', $filename) {
warn $!;
next;
}
while (<$input>) {
$_=mungeline($_);
while (/\\$/ && ! eof) {
s/\\$//;
$_.=mungeline(<$input>);
}
next if /^\s*$/ || /^\s*\#/;
my ($owner, $label, $type, $content) = /^\s*(\S+)\s+(\S+)\s+(\S+)(?:\s(.*))?/;
if (! defined $content) {
$content='';
}
if (ok_format($owner, $label, $type, $content)) {
if (grep { $_ eq $type } @knownflags) {
info "Trying to set '$type' flag to '$content'";
set_flag($owner, $label, $type, $content);
}
else {
info "Trying to set '$label' [$type] to '$content'";
load_answer($owner, $label, $type, $content);
}
}
}
}
if (! $checkonly) {
Debconf::Db->save;
}
if ($error) {
exit 1;
}
+102
View File
@@ -0,0 +1,102 @@
#!/usr/bin/perl
# This file was preprocessed, do not edit!
use strict;
use warnings;
use Debconf::Db;
use Debconf::Template;
use Debconf::Question;
use Getopt::Long;
sub usage {
print STDERR <<EOF;
Usage:
debconf-show packagename [...] [--db=dbname]
debconf-show --listowners [--db=dbname]
debconf-show --listdbs
EOF
exit(1);
}
my $db='';
my $listowners=0;
my @packages;
my $listdbs=0;
GetOptions(
"db=s" => \$db,
"listowners" => \$listowners,
"listdbs" => \$listdbs,
) || usage();
unless ($listowners or $listdbs) {
@packages=@ARGV;
usage() unless @packages;
}
Debconf::Db->load(readonly => 'true');
my %drivers = %Debconf::DbDriver::drivers;
my $conf = Debconf::Config->config;
sub tree {
my $node=shift;
my $string=shift || "";
my $driver = Debconf::DbDriver->driver($node);
my $name = $driver->{name};
$string = $string.$name;
print $string."\n";
if ($driver->isa("Debconf::DbDriver::Stack")) {
$string=$string.'/';
map { tree($_->{name},$string) } @{$driver->{stack}};
}
}
if ($db) {
my $driver = $drivers{$db};
die $db.": unknown database" unless defined($driver);
$Debconf::Db::config = $driver;
}
my $qi=Debconf::Question->iterator;
if ($listdbs) {
tree($conf);
}
elsif (@packages) {
while (my $q=$qi->iterate) {
foreach my $package (@packages) {
if (grep { $package eq $_} split(/, /, $q->owners)) {
if ($q->flag("seen") eq 'true') {
print "* ";
}
else {
print " ";
}
print $q->name.":";
if ($q->type eq 'password') {
print " (password omitted)";
}
elsif (length $q->value) {
print " ".$q->value;
}
print "\n";
}
}
}
}
elsif ($listowners) {
my %seen;
while (my $q=$qi->iterate) {
foreach (split(/, /, $q->owners)) {
unless ($seen{$_}) {
print "$_\n";
$seen{$_}=1;
}
}
}
}
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
+1
View File
@@ -0,0 +1 @@
hostname
+1
View File
@@ -0,0 +1 @@
hostname
BIN
View File
Binary file not shown.
Binary file not shown.
Binary file not shown.
+664
View File
@@ -0,0 +1,664 @@
#!/bin/sh
#
# Copyright © 2005 Scott James Remnant
# Copyright © 2008 Joey Hess <joeyh@debian.org>
# Copyright © 2007, 2011-2015 Guillem Jover <guillem@debian.org>
# Copyright © 2010 Raphaël Hertzog <hertzog@debian.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# The conffile related functions are inspired by
# https://wiki.debian.org/DpkgConffileHandling
# This script is documented in dpkg-maintscript-helper(1)
##
## Functions to remove an obsolete conffile during upgrade
##
rm_conffile() {
local CONFFILE="$1"
local LASTVERSION="$2"
local PACKAGE="$3"
if [ "$LASTVERSION" = "--" ]; then
LASTVERSION=""
PACKAGE="$DPKG_MAINTSCRIPT_PACKAGE${DPKG_MAINTSCRIPT_ARCH:+:$DPKG_MAINTSCRIPT_ARCH}"
fi
if [ "$PACKAGE" = "--" -o -z "$PACKAGE" ]; then
PACKAGE="$DPKG_MAINTSCRIPT_PACKAGE${DPKG_MAINTSCRIPT_ARCH:+:$DPKG_MAINTSCRIPT_ARCH}"
fi
# Skip remaining parameters up to --
while [ "$1" != "--" -a $# -gt 0 ]; do
shift
done
[ $# -gt 0 ] || badusage "missing arguments after --"
shift
[ -n "$PACKAGE" ] || error "couldn't identify the package"
[ -n "$1" ] || error "maintainer script parameters are missing"
[ -n "$DPKG_MAINTSCRIPT_NAME" ] || \
error "environment variable DPKG_MAINTSCRIPT_NAME is required"
[ -n "$DPKG_MAINTSCRIPT_PACKAGE" ] || \
error "environment variable DPKG_MAINTSCRIPT_PACKAGE is required"
[ "${CONFFILE}" != "${CONFFILE#/}" ] || \
error "conffile '$CONFFILE' is not an absolute path"
validate_optional_version "$LASTVERSION"
debug "Executing $0 rm_conffile in $DPKG_MAINTSCRIPT_NAME" \
"of $DPKG_MAINTSCRIPT_PACKAGE"
debug "CONFFILE=$CONFFILE PACKAGE=$PACKAGE" \
"LASTVERSION=$LASTVERSION ACTION=$1 PARAM=$2"
case "$DPKG_MAINTSCRIPT_NAME" in
preinst)
if [ "$1" = "install" -o "$1" = "upgrade" ] && [ -n "$2" ] &&
dpkg --compare-versions -- "$2" le-nl "$LASTVERSION"; then
prepare_rm_conffile "$CONFFILE" "$PACKAGE"
fi
;;
postinst)
if [ "$1" = "configure" ] && [ -n "$2" ] &&
dpkg --compare-versions -- "$2" le-nl "$LASTVERSION"; then
finish_rm_conffile "$CONFFILE"
fi
;;
postrm)
if [ "$1" = "purge" ]; then
rm -f "$DPKG_ROOT$CONFFILE.dpkg-bak" \
"$DPKG_ROOT$CONFFILE.dpkg-remove" \
"$DPKG_ROOT$CONFFILE.dpkg-backup"
fi
if [ "$1" = "abort-install" -o "$1" = "abort-upgrade" ] &&
[ -n "$2" ] &&
dpkg --compare-versions -- "$2" le-nl "$LASTVERSION"; then
abort_rm_conffile "$CONFFILE" "$PACKAGE"
fi
;;
*)
debug "$0 rm_conffile not required in $DPKG_MAINTSCRIPT_NAME"
;;
esac
}
prepare_rm_conffile() {
local CONFFILE="$1"
local PACKAGE="$2"
[ -e "$DPKG_ROOT$CONFFILE" ] || return 0
ensure_package_owns_file "$PACKAGE" "$CONFFILE" || return 0
local md5sum old_md5sum
md5sum="$(md5sum "$DPKG_ROOT$CONFFILE" | sed -e 's/ .*//')"
old_md5sum="$(dpkg-query -W -f='${Conffiles}' "$PACKAGE" | \
sed -n -e "\\'^ $CONFFILE ' { s/ obsolete$//; s/.* //; p }")"
if [ "$md5sum" != "$old_md5sum" ]; then
mv -f "$DPKG_ROOT$CONFFILE" "$DPKG_ROOT$CONFFILE.dpkg-backup"
else
mv -f "$DPKG_ROOT$CONFFILE" "$DPKG_ROOT$CONFFILE.dpkg-remove"
fi
}
finish_rm_conffile() {
local CONFFILE="$1"
if [ -e "$DPKG_ROOT$CONFFILE.dpkg-backup" ]; then
echo "Obsolete conffile $DPKG_ROOT$CONFFILE has been modified by you."
echo "Saving as $DPKG_ROOT$CONFFILE.dpkg-bak ..."
mv -f "$DPKG_ROOT$CONFFILE.dpkg-backup" "$DPKG_ROOT$CONFFILE.dpkg-bak"
fi
if [ -e "$DPKG_ROOT$CONFFILE.dpkg-remove" ]; then
echo "Removing obsolete conffile $DPKG_ROOT$CONFFILE ..."
rm -f "$DPKG_ROOT$CONFFILE.dpkg-remove"
fi
}
abort_rm_conffile() {
local CONFFILE="$1"
local PACKAGE="$2"
ensure_package_owns_file "$PACKAGE" "$CONFFILE" || return 0
if [ -e "$DPKG_ROOT$CONFFILE.dpkg-remove" ]; then
echo "Reinstalling $DPKG_ROOT$CONFFILE that was moved away"
mv "$DPKG_ROOT$CONFFILE.dpkg-remove" "$DPKG_ROOT$CONFFILE"
fi
if [ -e "$DPKG_ROOT$CONFFILE.dpkg-backup" ]; then
echo "Reinstalling $DPKG_ROOT$CONFFILE that was backed-up"
mv "$DPKG_ROOT$CONFFILE.dpkg-backup" "$DPKG_ROOT$CONFFILE"
fi
}
##
## Functions to rename a conffile during upgrade
##
mv_conffile() {
local OLDCONFFILE="$1"
local NEWCONFFILE="$2"
local LASTVERSION="$3"
local PACKAGE="$4"
if [ "$LASTVERSION" = "--" ]; then
LASTVERSION=""
PACKAGE="$DPKG_MAINTSCRIPT_PACKAGE${DPKG_MAINTSCRIPT_ARCH:+:$DPKG_MAINTSCRIPT_ARCH}"
fi
if [ "$PACKAGE" = "--" -o -z "$PACKAGE" ]; then
PACKAGE="$DPKG_MAINTSCRIPT_PACKAGE${DPKG_MAINTSCRIPT_ARCH:+:$DPKG_MAINTSCRIPT_ARCH}"
fi
# Skip remaining parameters up to --
while [ "$1" != "--" -a $# -gt 0 ]; do
shift
done
[ $# -gt 0 ] || badusage "missing arguments after --"
shift
[ -n "$PACKAGE" ] || error "couldn't identify the package"
[ -n "$1" ] || error "maintainer script parameters are missing"
[ -n "$DPKG_MAINTSCRIPT_NAME" ] || \
error "environment variable DPKG_MAINTSCRIPT_NAME is required"
[ -n "$DPKG_MAINTSCRIPT_PACKAGE" ] || \
error "environment variable DPKG_MAINTSCRIPT_PACKAGE is required"
[ "${OLDCONFFILE}" != "${OLDCONFFILE#/}" ] || \
error "old-conffile '$OLDCONFFILE' is not an absolute path"
[ "${NEWCONFFILE}" != "${NEWCONFFILE#/}" ] || \
error "new-conffile '$NEWCONFFILE' is not an absolute path"
validate_optional_version "$LASTVERSION"
debug "Executing $0 mv_conffile in $DPKG_MAINTSCRIPT_NAME" \
"of $DPKG_MAINTSCRIPT_PACKAGE"
debug "CONFFILE=$OLDCONFFILE -> $NEWCONFFILE PACKAGE=$PACKAGE" \
"LASTVERSION=$LASTVERSION ACTION=$1 PARAM=$2"
case "$DPKG_MAINTSCRIPT_NAME" in
preinst)
if [ "$1" = "install" -o "$1" = "upgrade" ] && [ -n "$2" ] &&
dpkg --compare-versions -- "$2" le-nl "$LASTVERSION"; then
prepare_mv_conffile "$OLDCONFFILE" "$PACKAGE"
fi
;;
postinst)
if [ "$1" = "configure" ] && [ -n "$2" ] &&
dpkg --compare-versions -- "$2" le-nl "$LASTVERSION"; then
finish_mv_conffile "$OLDCONFFILE" "$NEWCONFFILE" "$PACKAGE"
fi
;;
postrm)
if [ "$1" = "abort-install" -o "$1" = "abort-upgrade" ] &&
[ -n "$2" ] &&
dpkg --compare-versions -- "$2" le-nl "$LASTVERSION"; then
abort_mv_conffile "$OLDCONFFILE" "$PACKAGE"
fi
;;
*)
debug "$0 mv_conffile not required in $DPKG_MAINTSCRIPT_NAME"
;;
esac
}
prepare_mv_conffile() {
local CONFFILE="$1"
local PACKAGE="$2"
[ -e "$DPKG_ROOT$CONFFILE" ] || return 0
ensure_package_owns_file "$PACKAGE" "$CONFFILE" || return 0
local md5sum old_md5sum
md5sum="$(md5sum "$DPKG_ROOT$CONFFILE" | sed -e 's/ .*//')"
old_md5sum="$(dpkg-query -W -f='${Conffiles}' "$PACKAGE" | \
sed -n -e "\\'^ $CONFFILE ' { s/ obsolete$//; s/.* //; p }")"
if [ "$md5sum" = "$old_md5sum" ]; then
mv -f "$DPKG_ROOT$CONFFILE" "$DPKG_ROOT$CONFFILE.dpkg-remove"
fi
}
finish_mv_conffile() {
local OLDCONFFILE="$1"
local NEWCONFFILE="$2"
local PACKAGE="$3"
rm -f "$DPKG_ROOT$OLDCONFFILE.dpkg-remove"
[ -e "$DPKG_ROOT$OLDCONFFILE" ] || return 0
ensure_package_owns_file "$PACKAGE" "$OLDCONFFILE" || return 0
echo "Preserving user changes to $DPKG_ROOT$NEWCONFFILE (renamed from $DPKG_ROOT$OLDCONFFILE)..."
if [ -e "$DPKG_ROOT$NEWCONFFILE" ]; then
mv -f "$DPKG_ROOT$NEWCONFFILE" "$DPKG_ROOT$NEWCONFFILE.dpkg-new"
fi
mv -f "$DPKG_ROOT$OLDCONFFILE" "$DPKG_ROOT$NEWCONFFILE"
}
abort_mv_conffile() {
local CONFFILE="$1"
local PACKAGE="$2"
ensure_package_owns_file "$PACKAGE" "$CONFFILE" || return 0
if [ -e "$DPKG_ROOT$CONFFILE.dpkg-remove" ]; then
echo "Reinstalling $DPKG_ROOT$CONFFILE that was moved away"
mv "$DPKG_ROOT$CONFFILE.dpkg-remove" "$DPKG_ROOT$CONFFILE"
fi
}
##
## Functions to replace a symlink with a directory
##
symlink_to_dir() {
local SYMLINK="$1"
local SYMLINK_TARGET="$2"
local LASTVERSION="$3"
local PACKAGE="$4"
if [ "$LASTVERSION" = "--" ]; then
LASTVERSION=""
PACKAGE="$DPKG_MAINTSCRIPT_PACKAGE${DPKG_MAINTSCRIPT_ARCH:+:$DPKG_MAINTSCRIPT_ARCH}"
fi
if [ "$PACKAGE" = "--" -o -z "$PACKAGE" ]; then
PACKAGE="$DPKG_MAINTSCRIPT_PACKAGE${DPKG_MAINTSCRIPT_ARCH:+:$DPKG_MAINTSCRIPT_ARCH}"
fi
# Skip remaining parameters up to --
while [ "$1" != "--" -a $# -gt 0 ]; do
shift
done
[ $# -gt 0 ] || badusage "missing arguments after --"
shift
[ -n "$DPKG_MAINTSCRIPT_NAME" ] || \
error "environment variable DPKG_MAINTSCRIPT_NAME is required"
[ -n "$DPKG_MAINTSCRIPT_PACKAGE" ] || \
error "environment variable DPKG_MAINTSCRIPT_PACKAGE is required"
[ -n "$PACKAGE" ] || error "cannot identify the package"
[ -n "$SYMLINK" ] || error "symlink parameter is missing"
[ "${SYMLINK#/}" = "$SYMLINK" ] && \
error "symlink pathname is not an absolute path"
[ "${SYMLINK%/}" = "$SYMLINK" ] || \
error "symlink pathname ends with a slash"
[ -n "$SYMLINK_TARGET" ] || error "original symlink target is missing"
[ -n "$1" ] || error "maintainer script parameters are missing"
validate_optional_version "$LASTVERSION"
debug "Executing $0 symlink_to_dir in $DPKG_MAINTSCRIPT_NAME" \
"of $DPKG_MAINTSCRIPT_PACKAGE"
debug "SYMLINK=$SYMLINK -> $SYMLINK_TARGET PACKAGE=$PACKAGE" \
"LASTVERSION=$LASTVERSION ACTION=$1 PARAM=$2"
case "$DPKG_MAINTSCRIPT_NAME" in
preinst)
if [ "$1" = "install" -o "$1" = "upgrade" ] &&
[ -n "$2" ] && [ -h "$DPKG_ROOT$SYMLINK" ] &&
symlink_match "$SYMLINK" "$SYMLINK_TARGET" &&
dpkg --compare-versions -- "$2" le-nl "$LASTVERSION"; then
mv -f "$DPKG_ROOT$SYMLINK" "$DPKG_ROOT${SYMLINK}.dpkg-backup"
fi
;;
postinst)
# We cannot bail depending on the version, as here we only
# know what was the last configured version, and we might
# have been unpacked, then upgraded with an unpack and thus
# never been configured before.
if [ "$1" = "configure" ] &&
[ -h "$DPKG_ROOT${SYMLINK}.dpkg-backup" ] &&
symlink_match "${SYMLINK}.dpkg-backup" "$SYMLINK_TARGET"
then
rm -f "$DPKG_ROOT${SYMLINK}.dpkg-backup"
fi
;;
postrm)
if [ "$1" = "purge" ] && [ -h "$DPKG_ROOT${SYMLINK}.dpkg-backup" ]; then
rm -f "$DPKG_ROOT${SYMLINK}.dpkg-backup"
fi
if [ "$1" = "abort-install" -o "$1" = "abort-upgrade" ] &&
[ -n "$2" ] &&
[ ! -e "$DPKG_ROOT$SYMLINK" ] &&
[ -h "$DPKG_ROOT${SYMLINK}.dpkg-backup" ] &&
symlink_match "${SYMLINK}.dpkg-backup" "$SYMLINK_TARGET" &&
dpkg --compare-versions -- "$2" le-nl "$LASTVERSION"; then
echo "Restoring backup of $DPKG_ROOT$SYMLINK ..."
mv "$DPKG_ROOT${SYMLINK}.dpkg-backup" "$DPKG_ROOT$SYMLINK"
fi
;;
*)
debug "$0 symlink_to_dir not required in $DPKG_MAINTSCRIPT_NAME"
;;
esac
}
##
## Functions to replace a directory with a symlink
##
dir_to_symlink() {
local PATHNAME="${1%/}"
local SYMLINK_TARGET="$2"
local LASTVERSION="$3"
local PACKAGE="$4"
if [ "$LASTVERSION" = "--" ]; then
LASTVERSION=""
PACKAGE="$DPKG_MAINTSCRIPT_PACKAGE${DPKG_MAINTSCRIPT_ARCH:+:$DPKG_MAINTSCRIPT_ARCH}"
fi
if [ "$PACKAGE" = "--" -o -z "$PACKAGE" ]; then
PACKAGE="$DPKG_MAINTSCRIPT_PACKAGE${DPKG_MAINTSCRIPT_ARCH:+:$DPKG_MAINTSCRIPT_ARCH}"
fi
# Skip remaining parameters up to --
while [ "$1" != "--" -a $# -gt 0 ]; do
shift
done
[ $# -gt 0 ] || badusage "missing arguments after --"
shift
[ -n "$DPKG_MAINTSCRIPT_NAME" ] || \
error "environment variable DPKG_MAINTSCRIPT_NAME is required"
[ -n "$DPKG_MAINTSCRIPT_PACKAGE" ] || \
error "environment variable DPKG_MAINTSCRIPT_PACKAGE is required"
[ -n "$PACKAGE" ] || error "cannot identify the package"
[ -n "$PATHNAME" ] || error "directory parameter is missing"
[ "${PATHNAME#/}" = "$PATHNAME" ] && \
error "directory parameter is not an absolute path"
[ -n "$SYMLINK_TARGET" ] || error "new symlink target is missing"
[ -n "$1" ] || error "maintainer script parameters are missing"
validate_optional_version "$LASTVERSION"
debug "Executing $0 dir_to_symlink in $DPKG_MAINTSCRIPT_NAME" \
"of $DPKG_MAINTSCRIPT_PACKAGE"
debug "PATHNAME=$PATHNAME SYMLINK_TARGET=$SYMLINK_TARGET" \
"PACKAGE=$PACKAGE LASTVERSION=$LASTVERSION ACTION=$1 PARAM=$2"
case "$DPKG_MAINTSCRIPT_NAME" in
preinst)
if [ "$1" = "install" -o "$1" = "upgrade" ] &&
[ -n "$2" ] &&
[ ! -h "$DPKG_ROOT$PATHNAME" ] &&
[ -d "$DPKG_ROOT$PATHNAME" ] &&
dpkg --compare-versions -- "$2" le-nl "$LASTVERSION"; then
prepare_dir_to_symlink "$PACKAGE" "$PATHNAME"
fi
;;
postinst)
# We cannot bail depending on the version, as here we only
# know what was the last configured version, and we might
# have been unpacked, then upgraded with an unpack and thus
# never been configured before.
if [ "$1" = "configure" ] &&
[ -d "$DPKG_ROOT${PATHNAME}.dpkg-backup" ] &&
[ ! -h "$DPKG_ROOT$PATHNAME" ] &&
[ -d "$DPKG_ROOT$PATHNAME" ] &&
[ -f "$DPKG_ROOT$PATHNAME/.dpkg-staging-dir" ]; then
finish_dir_to_symlink "$PATHNAME" "$SYMLINK_TARGET"
fi
;;
postrm)
if [ "$1" = "purge" ] &&
[ -d "$DPKG_ROOT${PATHNAME}.dpkg-backup" ]; then
rm -rf "$DPKG_ROOT${PATHNAME}.dpkg-backup"
fi
if [ "$1" = "abort-install" -o "$1" = "abort-upgrade" ] &&
[ -n "$2" ] &&
[ -d "$DPKG_ROOT${PATHNAME}.dpkg-backup" ] &&
[ \( ! -h "$DPKG_ROOT$PATHNAME" -a \
-d "$DPKG_ROOT$PATHNAME" -a \
-f "$DPKG_ROOT$PATHNAME/.dpkg-staging-dir" \) -o \
\( -h "$DPKG_ROOT$PATHNAME" -a \
\( "$(readlink "$DPKG_ROOT$PATHNAME")" = "$SYMLINK_TARGET" -o \
"$(dpkg-realpath "$PATHNAME")" = "$SYMLINK_TARGET" \) \) ] &&
dpkg --compare-versions -- "$2" le-nl "$LASTVERSION"; then
abort_dir_to_symlink "$PATHNAME"
fi
;;
*)
debug "$0 dir_to_symlink not required in $DPKG_MAINTSCRIPT_NAME"
;;
esac
}
prepare_dir_to_symlink()
{
local PACKAGE="$1"
local PATHNAME="$2"
local LINE
# If there are conffiles we should not perform the switch.
dpkg-query -W -f='${Conffiles}\n' "$PACKAGE" | while read -r LINE; do
case "$LINE" in
"$PATHNAME"/*)
error "directory '$PATHNAME' contains conffiles," \
"cannot switch to symlink"
;;
esac
done
# If there are locally created files or files owned by another package
# we should not perform the switch.
export DPKG_MAINTSCRIPT_HELPER_INTERNAL_API="$version"
find "$DPKG_ROOT$PATHNAME" -print0 | \
xargs -0 -n1 "$0" _internal_pkg_must_own_file "$PACKAGE" || \
error "directory '$PATHNAME' contains files not owned by" \
"package $PACKAGE, cannot switch to symlink"
unset DPKG_MAINTSCRIPT_HELPER_INTERNAL_API
# At this point, we know that the directory either contains no files,
# or only non-conffiles owned by the package.
#
# To do the switch we cannot simply replace it with the final symlink
# just yet, because dpkg needs to remove any file present in the old
# package that have disappeared in the new one, and we do not want to
# lose files resolving to the same pathname in the symlink target.
#
# We cannot replace the directory with a staging symlink either,
# because dpkg will update symlinks to their new target.
#
# So we need to create a staging directory, to avoid removing files
# from other packages, and to trap any new files in the directory
# to move them to their correct place later on.
mv -f "$DPKG_ROOT$PATHNAME" "$DPKG_ROOT${PATHNAME}.dpkg-backup"
mkdir "$DPKG_ROOT$PATHNAME"
# Mark it as a staging directory, so that we can track things.
touch "$DPKG_ROOT$PATHNAME/.dpkg-staging-dir"
}
finish_dir_to_symlink()
{
local PATHNAME="$1"
local SYMLINK_TARGET="$2"
# Move the contents of the staging directory to the symlink target,
# as those are all new files installed between this package being
# unpacked and configured.
local ABS_SYMLINK_TARGET
if [ "${SYMLINK_TARGET#/}" = "$SYMLINK_TARGET" ]; then
ABS_SYMLINK_TARGET="$(dirname "$PATHNAME")/$SYMLINK_TARGET"
else
ABS_SYMLINK_TARGET="$SYMLINK_TARGET"
fi
rm "$DPKG_ROOT$PATHNAME/.dpkg-staging-dir"
find "$DPKG_ROOT$PATHNAME" -mindepth 1 -maxdepth 1 -print0 | \
xargs -0 -I% mv -f "%" "$DPKG_ROOT$ABS_SYMLINK_TARGET/"
# Remove the staging directory.
rmdir "$DPKG_ROOT$PATHNAME"
# Do the actual switch.
ln -s "$SYMLINK_TARGET" "$DPKG_ROOT$PATHNAME"
# We are left behind the old files owned by this package in the backup
# directory, just remove it.
rm -rf "$DPKG_ROOT${PATHNAME}.dpkg-backup"
}
abort_dir_to_symlink()
{
local PATHNAME="$1"
echo "Restoring backup of $DPKG_ROOT$PATHNAME ..."
if [ -h "$DPKG_ROOT$PATHNAME" ]; then
rm -f "$DPKG_ROOT$PATHNAME"
else
# The staging directory must be empty, as no other package
# should have been unpacked in between.
rm -f "$DPKG_ROOT$PATHNAME/.dpkg-staging-dir"
rmdir "$DPKG_ROOT$PATHNAME"
fi
mv "$DPKG_ROOT${PATHNAME}.dpkg-backup" "$DPKG_ROOT$PATHNAME"
}
# Common functions
validate_optional_version() {
local VERSION="$1"
if [ -z "$VERSION" ]; then
return
fi
if ! VERSIONCHECK=$(dpkg --validate-version -- "$VERSION" 2>&1); then
error "$VERSIONCHECK"
fi
}
ensure_package_owns_file() {
local PACKAGE="$1"
local FILE="$2"
if ! dpkg-query -L "$PACKAGE" | grep -F -q -x "$FILE"; then
debug "File '$FILE' not owned by package " \
"'$PACKAGE', skipping $command"
return 1
fi
return 0
}
internal_pkg_must_own_file()
{
local PACKAGE="$1"
local FILE="${2##"$DPKG_ROOT"}"
if [ "$DPKG_MAINTSCRIPT_HELPER_INTERNAL_API" != "$version" ]; then
error "internal API used by external command"
fi
if ! ensure_package_owns_file "$PACKAGE" "$FILE"; then
error "file '$FILE' not owned by package '$PACKAGE'"
fi
return 0
}
symlink_match()
{
local SYMLINK="$1"
local SYMLINK_TARGET="$2"
[ "$(readlink "$DPKG_ROOT$SYMLINK")" = "$SYMLINK_TARGET" ] || \
[ "$(dpkg-realpath "$SYMLINK")" = "$SYMLINK_TARGET" ]
}
usage() {
cat <<END
Usage: $PROGNAME <command> <parameter>... -- <maintainer-script-parameter>...
Commands:
supports <command>
Returns 0 (success) if the given command is supported, 1 otherwise.
rm_conffile <conffile> [<last-version> [<package>]]
Remove obsolete conffile. Must be called in preinst, postinst and
postrm.
mv_conffile <old-conf> <new-conf> [<last-version> [<package>]]
Rename a conffile. Must be called in preinst, postinst and postrm.
symlink_to_dir <pathname> <old-symlink-target> [<last-version> [<package>]]
Replace a symlink with a directory. Must be called in preinst,
postinst and postrm.
dir_to_symlink <pathname> <new-symlink-target> [<last-version> [<package>]]
Replace a directory with a symlink. Must be called in preinst,
postinst and postrm.
help
-?, --help
Show this help message.
--version
Show the version.
END
}
# Main code
set -e
version="1.22.22"
DPKG_ROOT=${DPKG_ROOT:+$(realpath "$DPKG_ROOT")}
# Remove default root dir.
if [ "$DPKG_ROOT" = "/" ]; then
DPKG_ROOT=""
fi
export DPKG_ROOT
PKGDATADIR_DEFAULT='/usr/share/dpkg'
PKGDATADIR="${DPKG_DATADIR:-$PKGDATADIR_DEFAULT}"
# shellcheck source=src/sh/dpkg-error.sh
. "$PKGDATADIR/sh/dpkg-error.sh"
command="$1"
[ $# -gt 0 ] || badusage "missing command"
shift
case "$command" in
supports)
case "$1" in
rm_conffile|mv_conffile|symlink_to_dir|dir_to_symlink)
code=0
;;
*)
code=1
;;
esac
if [ -z "$DPKG_MAINTSCRIPT_NAME" ]; then
warning "environment variable DPKG_MAINTSCRIPT_NAME missing"
code=1
fi
if [ -z "$DPKG_MAINTSCRIPT_PACKAGE" ]; then
warning "environment variable DPKG_MAINTSCRIPT_PACKAGE missing"
code=1
fi
exit $code
;;
rm_conffile)
rm_conffile "$@"
;;
mv_conffile)
mv_conffile "$@"
;;
symlink_to_dir)
symlink_to_dir "$@"
;;
dir_to_symlink)
dir_to_symlink "$@"
;;
_internal_pkg_must_own_file)
# This is an internal command, must not be used outside this program.
internal_pkg_must_own_file "$@"
;;
--help|help|-?)
usage
;;
--version)
cat <<END
Debian $PROGNAME version $version.
This is free software; see the GNU General Public License version 2 or
later for copying conditions. There is NO warranty.
END
;;
*)
badusage "command $command is unknown
Hint: upgrading dpkg to a newer version might help."
esac
exit 0
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
+3
View File
@@ -0,0 +1,3 @@
#!/bin/sh
cmd=${0##*/}
exec grep -E "$@"
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
+3
View File
@@ -0,0 +1,3 @@
#!/bin/sh
cmd=${0##*/}
exec grep -F "$@"
BIN
View File
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
+57
View File
@@ -0,0 +1,57 @@
#!/bin/sh
# Uncompress files. This is the inverse of gzip.
# Copyright (C) 2007, 2010-2023 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
version="gunzip (gzip) 1.13
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software. You may redistribute copies of it under the terms of
the GNU General Public License <https://www.gnu.org/licenses/gpl.html>.
There is NO WARRANTY, to the extent permitted by law.
Written by Paul Eggert."
usage="Usage: $0 [OPTION]... [FILE]...
Uncompress FILEs (by default, in-place).
Mandatory arguments to long options are mandatory for short options too.
-c, --stdout write on standard output, keep original files unchanged
-f, --force force overwrite of output file and compress links
-k, --keep keep (don't delete) input files
-l, --list list compressed file contents
-n, --no-name do not save or restore the original name and timestamp
-N, --name save or restore the original name and timestamp
-q, --quiet suppress all warnings
-r, --recursive operate recursively on directories
-S, --suffix=SUF use suffix SUF on compressed files
--synchronous synchronous output (safer if system crashes, but slower)
-t, --test test compressed file integrity
-v, --verbose verbose mode
--help display this help and exit
--version display version information and exit
With no FILE, or when FILE is -, read standard input.
Report bugs to <bug-gzip@gnu.org>."
case $1 in
--help) printf '%s\n' "$usage" || exit 1; exit;;
--version) printf '%s\n' "$version" || exit 1; exit;;
esac
exec gzip -d "$@"
+241
View File
@@ -0,0 +1,241 @@
#!/bin/sh
# gzexe: compressor for Unix executables.
# Use this only for binaries that you do not use frequently.
#
# The compressed version is a shell script which decompresses itself after
# skipping $skip lines of shell commands. We try invoking the compressed
# executable with the original name (for programs looking at their name).
# We also try to retain the original file permissions on the compressed file.
# For safety reasons, gzexe will not create setuid or setgid shell scripts.
# WARNING: the first line of this file must be either : or #!/bin/sh
# The : is required for some old versions of csh.
# On Ultrix, /bin/sh is too buggy, change the first line to: #!/bin/sh5
# Copyright (C) 1998, 2002, 2004, 2006-2007, 2010-2023 Free Software
# Foundation, Inc.
# Copyright (C) 1993 Jean-loup Gailly
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
tab=' '
nl='
'
IFS=" $tab$nl"
version='gzexe (gzip) 1.13
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software. You may redistribute copies of it under the terms of
the GNU General Public License <https://www.gnu.org/licenses/gpl.html>.
There is NO WARRANTY, to the extent permitted by law.
Written by Jean-loup Gailly.'
usage="Usage: $0 [OPTION] FILE...
Replace each executable FILE with a compressed version of itself.
Make a backup FILE~ of the old version of FILE.
-d Decompress each FILE instead of compressing it.
--help display this help and exit
--version output version information and exit
Report bugs to <bug-gzip@gnu.org>."
decomp=0
res=0
while :; do
case $1 in
-d) decomp=1; shift;;
--h*) printf '%s\n' "$usage" || exit 1; exit;;
--v*) printf '%s\n' "$version" || exit 1; exit;;
--) shift; break;;
*) break;;
esac
done
if test $# -eq 0; then
printf >&2 '%s\n' "$0: missing operand
Try \`$0 --help' for more information."
exit 1
fi
tmp=
trap 'res=$?
test -n "$tmp" && rm -f "$tmp"
(exit $res); exit $res
' 0 1 2 3 5 10 13 15
mktemp_status=
for i do
case $i in
-*) file=./$i;;
*) file=$i;;
esac
if test ! -f "$file" || test ! -r "$file"; then
res=$?
printf >&2 '%s\n' "$0: $i is not a readable regular file"
continue
fi
if test $decomp -eq 0; then
case `LC_ALL=C sed -n -e 1d -e '/^skip=[0-9][0-9]*$/p' -e 2q "$file"` in
skip=[0-9] | skip=[0-9][0-9] | skip=[0-9][0-9][0-9])
printf >&2 '%s\n' "$0: $i is already gzexe'd"
continue;;
esac
fi
if test -u "$file"; then
printf >&2 '%s\n' "$0: $i has setuid permission, unchanged"
continue
fi
if test -g "$file"; then
printf >&2 '%s\n' "$0: $i has setgid permission, unchanged"
continue
fi
case /$file in
*/basename | */bash | */cat | */chmod | */cp | \
*/dirname | */expr | */gzip | \
*/ln | */mkdir | */mktemp | */mv | */printf | */rm | \
*/sed | */sh | */sleep | */test | */tail)
printf >&2 '%s\n' "$0: $i might depend on itself"; continue;;
esac
dir=`dirname "$file"` || dir=$TMPDIR
test -d "$dir" && test -w "$dir" && test -x "$dir" || dir=/tmp
test -n "$tmp" && rm -f "$tmp"
if test -z "$mktemp_status"; then
type mktemp >/dev/null 2>&1
mktemp_status=$?
fi
case $dir in
*/) ;;
*) dir=$dir/;;
esac
if test $mktemp_status -eq 0; then
tmp=`mktemp "${dir}gzexeXXXXXXXXX"`
else
tmp=${dir}gzexe$$
fi && { cp -p "$file" "$tmp" 2>/dev/null || cp "$file" "$tmp"; } || {
res=$?
printf >&2 '%s\n' "$0: cannot copy $file"
continue
}
if test -w "$tmp"; then
writable=1
else
writable=0
chmod u+w "$tmp" || {
res=$?
printf >&2 '%s\n' "$0: cannot chmod $tmp"
continue
}
fi
if test $decomp -eq 0; then
(cat <<'EOF' &&
#!/bin/sh
skip=49
tab=' '
nl='
'
IFS=" $tab$nl"
umask=`umask`
umask 77
gztmpdir=
trap 'res=$?
test -n "$gztmpdir" && rm -fr "$gztmpdir"
(exit $res); exit $res
' 0 1 2 3 5 10 13 15
case $TMPDIR in
/ | /*/) ;;
/*) TMPDIR=$TMPDIR/;;
*) TMPDIR=/tmp/;;
esac
if type mktemp >/dev/null 2>&1; then
gztmpdir=`mktemp -d "${TMPDIR}gztmpXXXXXXXXX"`
else
gztmpdir=${TMPDIR}gztmp$$; mkdir $gztmpdir
fi || { (exit 127); exit 127; }
gztmp=$gztmpdir/$0
case $0 in
-* | */*'
') mkdir -p "$gztmp" && rm -r "$gztmp";;
*/*) gztmp=$gztmpdir/`basename "$0"`;;
esac || { (exit 127); exit 127; }
case `printf 'X\n' | tail -n +1 2>/dev/null` in
X) tail_n=-n;;
*) tail_n=;;
esac
if tail $tail_n +$skip <"$0" | gzip -cd > "$gztmp"; then
umask $umask
chmod 700 "$gztmp"
(sleep 5; rm -fr "$gztmpdir") 2>/dev/null &
"$gztmp" ${1+"$@"}; res=$?
else
printf >&2 '%s\n' "Cannot decompress $0"
(exit 127); res=127
fi; exit $res
EOF
gzip -cv9 "$file") > "$tmp" || {
res=$?
printf >&2 '%s\n' "$0: compression not possible for $i, file unchanged."
continue
}
else
# decompression
skip=44
skip_line=`LC_ALL=C sed -e 1d -e 2q "$file"`
case $skip_line in
skip=[0-9] | skip=[0-9][0-9] | skip=[0-9][0-9][0-9])
eval "$skip_line";;
esac
case `printf 'X\n' | tail -n +1 2>/dev/null` in
X) tail_n=-n;;
*) tail_n=;;
esac
tail $tail_n +$skip "$file" | gzip -cd > "$tmp" || {
res=$?
printf >&2 '%s\n' "$0: $i probably not in gzexe format, file unchanged."
continue
}
fi
test $writable -eq 1 || chmod u-w "$tmp" || {
res=$?
printf >&2 '%s\n' "$0: $tmp: cannot chmod"
continue
}
ln -f "$file" "$file~" 2>/dev/null || {
# Hard links may not work. Fall back on rm+cp so that $file always exists.
rm -f "$file~" && cp -p "$file" "$file~"
} || {
res=$?
printf >&2 '%s\n' "$0: cannot backup $i as $i~"
continue
}
mv -f "$tmp" "$file" || {
res=$?
printf >&2 '%s\n' "$0: cannot rename $tmp to $i"
continue
}
tmp=
done
(exit $res); exit $res
BIN
View File
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.
+1
View File
@@ -0,0 +1 @@
tic
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.

Some files were not shown because too many files have changed in this diff Show More