initial commit

This commit is contained in:
2024-06-23 11:54:59 +03:00
commit c9200b8d39
20 changed files with 736 additions and 0 deletions

49
scripts/apt-clean.sh Executable file
View File

@@ -0,0 +1,49 @@
#!/bin/sh
set -f
## apt
find /var/cache/apt/ ! -type d ! -name 'lock' -delete
find /var/lib/apt/ ! -type d -wholename '/var/lib/apt/listchanges*' -delete
find /var/lib/apt/lists/ ! -type d ! -name 'lock' -delete
find /var/log/ ! -type d -wholename '/var/log/apt/*' -delete
find /var/log/ ! -type d -wholename '/var/log/aptitude*' -delete
## dpkg
: "${DPKG_ADMINDIR:=/var/lib/dpkg}"
truncate -s 0 "${DPKG_ADMINDIR}/available"
find "${DPKG_ADMINDIR}/" ! -type d -wholename "${DPKG_ADMINDIR}/*-old" -delete
find /var/log/ ! -type d -wholename '/var/log/alternatives.log' -delete
find /var/log/ ! -type d -wholename '/var/log/dpkg.log' -delete
## debconf
find /var/cache/debconf/ ! -type d -wholename '/var/cache/debconf/*-old' -delete
__t=$(mktemp) ; : "${__t:?}"
debconf_trim_i18n() {
mawk 'BEGIN { m = 0 }
$0 == "" { print }
/^[^[:space:]]/ {
if ($1 ~ "\.[Uu][Tt][Ff]-?8:") { m = 1; next; }
m = 0; print $0;
}
/^[[:space:]]/ {
if (m == 1) next;
print $0;
}' < "$1" > "${__t}"
cat < "${__t}" > "$1"
}
debconf_trim_i18n /var/cache/debconf/templates.dat
while read -r tmpl ; do
[ -n "${tmpl}" ] || continue
[ -s "${tmpl}" ] || continue
debconf_trim_i18n "${tmpl}"
done <<EOF
$(find "${DPKG_ADMINDIR}/info/" -type f -name '*.templates' | sort -V)
EOF
rm -f "${__t}" ; unset __t
## misc
rm -f /var/cache/ldconfig/aux-cache
exit 0

8
scripts/apt-env.sh Executable file
View File

@@ -0,0 +1,8 @@
#!/bin/sh
set -a
DEBCONF_NONINTERACTIVE_SEEN=true
DEBIAN_FRONTEND=noninteractive
DEBIAN_PRIORITY=critical
TERM=linux
set +a
exec "$@"

4
scripts/apt-install.sh Executable file
View File

@@ -0,0 +1,4 @@
#!/bin/sh
set -ef
apt-env.sh apt-get update
exec apt-env.sh apt-get install -y --no-install-recommends "$@"

17
scripts/dumb-run-as.sh Executable file
View File

@@ -0,0 +1,17 @@
#!/bin/sh
set -ef
_user="${1%%:*}" ; _group="${1#*:}" ; shift
getent passwd "${_user}" >/dev/null
_home=$(getent passwd "${_user}" | cut -d: -f6)
_test_dir() { setpriv --reuid="$1" --regid="$2" --init-groups test -d "$3" ; }
unset _cwd
if ! _test_dir "${_user}" "${_group}" . ; then
_cwd=${_home}
if ! _test_dir "${_user}" "${_group}" "${_cwd}" ; then
_cwd=/
fi
fi
exec \
setpriv --reuid="${_user}" --regid="${_group}" --init-groups \
env ${_cwd:+ -C "${_cwd}" } USER="${_user}" LOGNAME="${_user}" "HOME=${_home}" SHELL=/bin/sh \
"$@"

45
scripts/gpg-batch.sh Executable file
View File

@@ -0,0 +1,45 @@
#!/bin/sh
set -ef
: "${GPG_KEYSERVER:=hkps://keyserver.ubuntu.com}"
[ $# != 0 ] || exit 1
case "$1" in
1 | start )
[ -n "${GNUPGHOME}" ] || exit 1
[ -d "${GNUPGHOME}" ] || exit 1
cd "${GNUPGHOME}"
cat > gpg.conf <<-EOF
quiet
batch
trust-model always
no-auto-check-trustdb
ignore-time-conflict
keyid-format 0xlong
keyserver ${GPG_KEYSERVER}
EOF
cat > dirmngr.conf <<-EOF
quiet
batch
keyserver ${GPG_KEYSERVER}
EOF
gpg --update-trustdb >/dev/null 2>&1
gpg --list-keys >/dev/null 2>&1
dirmngr >/dev/null 2>&1
;;
0 | stop )
[ -n "${GNUPGHOME}" ] || exit 0
[ -d "${GNUPGHOME}" ] || exit 1
cd "${GNUPGHOME}"
gpgconf --kill all
cd /
rm -rf "${GNUPGHOME}"
;;
* )
exit 1
;;
esac
exit 0

28
scripts/gpg-export.sh Executable file
View File

@@ -0,0 +1,28 @@
#!/bin/sh
set -ef
: "${1:?}" "${2:?}"
w=$(mktemp -d) ; : "${w:?}"
gpg_on() { gpg-batch.sh start ; }
gpg_off() {
cd /
gpg-batch.sh stop
unset GNUPGHOME
rm -rf "$w"
exit "${1:-0}"
}
(
export GNUPGHOME="$w/.gnupg"
mkdir -m 0700 "${GNUPGHOME}"
gpg_on
gpg --import "$1"
gpg --armor --export > "$w/export"
cat < "$w/export" > "$2"
gpg --show-keys "$2"
gpg_off
) || gpg_off 1

7
scripts/pip-clean.sh Executable file
View File

@@ -0,0 +1,7 @@
#!/bin/sh
set -f
for i ; do
find "$i/" -name __pycache__ -exec rm -rf {} +
find "$i/" ! -type d -name '*.py[co]' -exec rm -f {} +
done
exit 0

8
scripts/pip-env.sh Executable file
View File

@@ -0,0 +1,8 @@
#!/bin/sh
set -a
PIP_DISABLE_PIP_VERSION_CHECK=1
PIP_NO_CACHE_DIR=1
PIP_ROOT_USER_ACTION=ignore
PIP_NO_COMPILE=1
set +a
exec "$@"