You've already forked Trash-Bin
Inital Commit
This commit is contained in:
9
root/DEBIAN/control
Normal file
9
root/DEBIAN/control
Normal file
@@ -0,0 +1,9 @@
|
||||
Package: trash-bin
|
||||
Version: 1.0.0
|
||||
Architecture:
|
||||
Installed-Size:
|
||||
Priority: optional
|
||||
Section: misc
|
||||
Homepage: http://www.privlab.it
|
||||
Maintainer: PrivLab <hostmaster@privlab.it>
|
||||
Description: Trashbin for the Bash environment
|
||||
38
root/DEBIAN/postinst
Normal file
38
root/DEBIAN/postinst
Normal file
@@ -0,0 +1,38 @@
|
||||
#!/usr/bin/sh
|
||||
|
||||
set -e
|
||||
set -u
|
||||
|
||||
if [ -d '/run/systemd/system' ]; then
|
||||
/usr/bin/systemctl --system daemon-reload > '/dev/null' 2>&1 || \
|
||||
/usr/bin/true
|
||||
fi
|
||||
|
||||
case "${1}" in
|
||||
configure)
|
||||
if [ -x '/usr/bin/deb-systemd-helper' ]; then
|
||||
/usr/bin/deb-systemd-helper unmask 'trash-bin.service' > '/dev/null' 2>&1 || \
|
||||
/usr/bin/true
|
||||
/usr/bin/deb-systemd-helper unmask 'trash-bin.timer' > '/dev/null' 2>&1 || \
|
||||
/usr/bin/true
|
||||
fi
|
||||
if /usr/bin/deb-systemd-helper --quiet was-enabled 'trash-bin.timer'; then
|
||||
/usr/bin/deb-systemd-helper enable 'trash-bin.timer' > '/dev/null' 2>&1 || \
|
||||
/usr/bin/true
|
||||
else
|
||||
/usr/bin/deb-systemd-helper update-state 'trash-bin.timer' > '/dev/null' 2>&1 || \
|
||||
/usr/bin/true
|
||||
fi
|
||||
if [ -x '/usr/bin/deb-systemd-invoke' ]; then
|
||||
/usr/bin/systemctl --system daemon-reload > '/dev/null' 2>&1 || \
|
||||
/usr/bin/true
|
||||
if [ -n "${2}" ]; then
|
||||
_dh_action='restart'
|
||||
else
|
||||
_dh_action='start'
|
||||
fi
|
||||
/usr/bin/deb-systemd-invoke "${_dh_action}" 'trash-bin.timer' > '/dev/null' 2>&1 || \
|
||||
/usr/bin/true
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
33
root/DEBIAN/postrm
Normal file
33
root/DEBIAN/postrm
Normal file
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/sh
|
||||
|
||||
set -e
|
||||
set -u
|
||||
|
||||
if [ -d '/run/systemd/system' ]; then
|
||||
/usr/bin/systemctl --system daemon-reload > '/dev/null' 2>&1 || \
|
||||
/usr/bin/true
|
||||
fi
|
||||
|
||||
case "${1}" in
|
||||
remove)
|
||||
if [ -x '/usr/bin/deb-systemd-helper' ]; then
|
||||
/usr/bin/deb-systemd-helper mask 'trash-bin.service' > '/dev/null' 2>&1 || \
|
||||
/usr/bin/true
|
||||
/usr/bin/deb-systemd-helper mask 'trash-bin.timer' > '/dev/null' 2>&1 || \
|
||||
/usr/bin/true
|
||||
fi
|
||||
;;
|
||||
purge)
|
||||
if [ -x '/usr/bin/deb-systemd-helper' ]; then
|
||||
/usr/bin/deb-systemd-helper purge 'trash-bin.service' > '/dev/null' 2>&1 || \
|
||||
/usr/bin/true
|
||||
/usr/bin/deb-systemd-helper purge 'trash-bin.timer' > '/dev/null' 2>&1 || \
|
||||
/usr/bin/true
|
||||
/usr/bin/deb-systemd-helper unmask 'trash-bin.service' > '/dev/null' 2>&1 || \
|
||||
/usr/bin/true
|
||||
/usr/bin/deb-systemd-helper unmask 'trash-bin.timer' > '/dev/null' 2>&1 || \
|
||||
/usr/bin/true
|
||||
fi
|
||||
/usr/bin/rm --force --recursive '/var/trash'
|
||||
;;
|
||||
esac
|
||||
15
root/DEBIAN/prerm
Normal file
15
root/DEBIAN/prerm
Normal file
@@ -0,0 +1,15 @@
|
||||
#!/usr/bin/sh
|
||||
|
||||
set -e
|
||||
set -u
|
||||
|
||||
case "${1}" in
|
||||
remove)
|
||||
if [ -x '/usr/bin/deb-systemd-invoke' ]; then
|
||||
/usr/bin/deb-systemd-invoke stop 'trash-bin.timer' > '/dev/null' 2>&1 || \
|
||||
/usr/bin/true
|
||||
/usr/bin/deb-systemd-invoke disable 'trash-bin.timer' > '/dev/null' 2>&1 || \
|
||||
/usr/bin/true
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
17
root/etc/cron.d/trash-bin
Normal file
17
root/etc/cron.d/trash-bin
Normal file
@@ -0,0 +1,17 @@
|
||||
# /etc/cron.d/trash-bin
|
||||
|
||||
SHELL=/usr/bin/sh
|
||||
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
|
||||
MAILTO=root
|
||||
|
||||
# * * * * * user command to execute
|
||||
# | | | | |
|
||||
# | | | | |
|
||||
# | | | | |_______________ day of week (0 - 6) (0 to 6 are Sunday to Saturday, or use names; 7 is Sunday, the same as 0)
|
||||
# | | | |______________________ month (1 - 12)
|
||||
# | | |_____________________________ day of month (1 - 31)
|
||||
# | |____________________________________ hour (0 - 23)
|
||||
# |___________________________________________ min (0 - 59)
|
||||
#
|
||||
0 0 * * * root if [ -d '/run/systemd/system' ]; then exit 0; fi; /usr/bin/find '/var/trash/'*/* -maxdepth '0' -mtime '+7' -exec /usr/bin/rm --force --recursive {} \;;
|
||||
#
|
||||
14
root/lib/systemd/system/trash-bin.service
Normal file
14
root/lib/systemd/system/trash-bin.service
Normal file
@@ -0,0 +1,14 @@
|
||||
[Unit]
|
||||
Description=Clanup the trash bin
|
||||
ConditionDirectoryNotEmpty=/var/trash
|
||||
After=multi-user.target
|
||||
Requires=multi-user.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
ExecStart=/usr/bin/bash -c "/usr/bin/find /var/trash/*/* -maxdepth 0 -mtime +7 -exec /usr/bin/rm --force --recursive {} \;;"
|
||||
ProtectSystem=strict
|
||||
ReadWriteDirectories=/var/trash
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
9
root/lib/systemd/system/trash-bin.timer
Normal file
9
root/lib/systemd/system/trash-bin.timer
Normal file
@@ -0,0 +1,9 @@
|
||||
[Unit]
|
||||
Description=Clanup the trash bin
|
||||
|
||||
[Timer]
|
||||
OnCalendar=*-*-* 00:00:00
|
||||
Persistent=true
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
124
root/usr/bin/trash-bin
Normal file
124
root/usr/bin/trash-bin
Normal file
@@ -0,0 +1,124 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
|
||||
###
|
||||
#
|
||||
# Options Section
|
||||
#
|
||||
###
|
||||
|
||||
set -e
|
||||
set -u
|
||||
set -o pipefail
|
||||
|
||||
|
||||
###
|
||||
#
|
||||
# Variables Section
|
||||
#
|
||||
###
|
||||
|
||||
set +u
|
||||
NAME=$(/usr/bin/basename "${0}")
|
||||
ARGUMENT="${1:---help}"
|
||||
set -u
|
||||
ROOT="/var/trash/${USER}"
|
||||
TRASH="${ROOT}/$(/usr/bin/date '+%d.%m.%Y')"
|
||||
|
||||
|
||||
###
|
||||
#
|
||||
# Runtime Environment
|
||||
#
|
||||
###
|
||||
|
||||
if [ ! -d "${TRASH}" ]; then
|
||||
/usr/bin/install --directory "${ROOT}" --mode='0750'
|
||||
/usr/bin/install --directory "${TRASH}" --mode='0750'
|
||||
fi
|
||||
|
||||
if [ ! -L "${HOME}/.trash" ]; then
|
||||
/usr/bin/ln --symbolic "${ROOT}" "${HOME}/.trash"
|
||||
fi
|
||||
|
||||
if [[ -z "${ARGUMENT}" ]] || \
|
||||
[[ "${ARGUMENT}" == '--help' ]]; then
|
||||
/usr/bin/echo -n -e 'Usage: ${NAME} [File]\n\n'
|
||||
/usr/bin/echo -n -e 'File Types:\n'
|
||||
/usr/bin/echo -n -e '[F] - Regular File\n'
|
||||
/usr/bin/echo -n -e '[B] - Block Device\n'
|
||||
/usr/bin/echo -n -e '[C] - Character Device\n'
|
||||
/usr/bin/echo -n -e '[D] - Directory\n'
|
||||
/usr/bin/echo -n -e '[L] - Symbolic Link\n'
|
||||
/usr/bin/echo -n -e '[S] - Socket\n'
|
||||
/usr/bin/echo -n -e '[P] - Named Pipe\n'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
INPUT_NUMBER='1'
|
||||
|
||||
for INPUT in "${@}"; do
|
||||
unset BASENAME
|
||||
unset REALPATH
|
||||
if [[ "${INPUT}" != '-'* ]]; then
|
||||
BASENAME=$(/usr/bin/basename "${INPUT}")
|
||||
REALPATH=$(/usr/bin/realpath --canonicalize-existing --quiet --no-symlinks "${INPUT}")
|
||||
BASENAME_NUMBER='1'
|
||||
while [[ -e "${TRASH}/${BASENAME}" ]]; do
|
||||
BASENAME="${BASENAME//.[[:digit:]]/}"
|
||||
BASENAME="${BASENAME}.${BASENAME_NUMBER}"
|
||||
(( BASENAME_NUMBER++ ))
|
||||
done
|
||||
if [[ "${TRASH}" == "${REALPATH}"* ]]; then
|
||||
if ! /usr/bin/rm --force --recursive "${ROOT:?}"; then
|
||||
/usr/bin/echo -n -e 'Error: The Recycle Bin can not be cleared.\n'
|
||||
exit 1
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
if [[ -f "${REALPATH}" ]]; then
|
||||
/usr/bin/echo -n -e "[F] ${INPUT_NUMBER}.\t${REALPATH}\n"
|
||||
elif [[ -b "${REALPATH}" ]]; then
|
||||
/usr/bin/echo -n -e "[B] ${INPUT_NUMBER}.\t${REALPATH}\n"
|
||||
elif [[ -c "${REALPATH}" ]]; then
|
||||
/usr/bin/echo -n -e "[C] ${INPUT_NUMBER}.\t${REALPATH}\n"
|
||||
elif [[ -d "${REALPATH}" ]]; then
|
||||
/usr/bin/echo -n -e "[D] ${INPUT_NUMBER}.\t${REALPATH}\n"
|
||||
elif [[ -L "${REALPATH}" ]]; then
|
||||
/usr/bin/echo -n -e "[L] ${INPUT_NUMBER}.\t${REALPATH}\n"
|
||||
elif [[ -S "${REALPATH}" ]]; then
|
||||
/usr/bin/echo -n -e "[S] ${INPUT_NUMBER}.\t${REALPATH}\n"
|
||||
elif [[ -p "${REALPATH}" ]]; then
|
||||
/usr/bin/echo -n -e "[P] ${INPUT_NUMBER}.\t${REALPATH}\n"
|
||||
fi
|
||||
if [[ -f "${REALPATH}" ]] || \
|
||||
[[ -d "${REALPATH}" ]] || \
|
||||
[[ -L "${REALPATH}" ]]; then
|
||||
if ! /usr/bin/mv --no-clobber "${REALPATH}" "${TRASH}/${BASENAME}" &> '/dev/null'; then
|
||||
if [[ -f "${REALPATH}" ]]; then
|
||||
/usr/bin/echo -n -e "\r\r[ERROR] [F] ${INPUT_NUMBER}.\t${REALPATH}\n"
|
||||
elif [[ -d "${REALPATH}" ]]; then
|
||||
/usr/bin/echo -n -e "\r\r[ERROR] [D] ${INPUT_NUMBER}.\t${REALPATH}\n"
|
||||
elif [[ -L "${REALPATH}" ]]; then
|
||||
/usr/bin/echo -n -e "\r\r[ERROR] [L] ${INPUT_NUMBER}.\t${REALPATH}\n"
|
||||
fi
|
||||
fi
|
||||
elif [[ -b "${REALPATH}" ]] || \
|
||||
[[ -c "${REALPATH}" ]] || \
|
||||
[[ -S "${REALPATH}" ]] || \
|
||||
[[ -p "${REALPATH}" ]]; then
|
||||
if ! /usr/bin/rm --force "${REALPATH}" &> '/dev/null'; then
|
||||
if [[ -b "${REALPATH}" ]]; then
|
||||
/usr/bin/echo -n -e "\r\r[ERROR] [B] ${INPUT_NUMBER}.\t${REALPATH}\n"
|
||||
elif [[ -c "${REALPATH}" ]]; then
|
||||
/usr/bin/echo -n -e "\r\r[ERROR] [C] ${INPUT_NUMBER}.\t${REALPATH}\n"
|
||||
elif [[ -S "${REALPATH}" ]]; then
|
||||
/usr/bin/echo -n -e "\r\r[ERROR] [S] ${INPUT_NUMBER}.\t${REALPATH}\n"
|
||||
elif [[ -p "${REALPATH}" ]]; then
|
||||
/usr/bin/echo -n -e "\r\r[ERROR] [P] ${INPUT_NUMBER}.\t${REALPATH}\n"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
(( INPUT_NUMBER++ ))
|
||||
fi
|
||||
done
|
||||
Reference in New Issue
Block a user