Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## 0.6 (10/03/26)
- **Package installation/upgrade fix**: Fixed `.deb` installation and reinstallation flow for newer Ubuntu versions, especially Ubuntu 24.04.
- **`postinst`**: Added post-install configuration to load `shutils.sh` through `/etc/profile.d/shutils.sh`.
- **`prerm`**: Added safe cleanup of `/etc/bash.bashrc`, `/etc/zsh/zshrc`, and `/etc/profile.d/shutils.sh` on package removal.
- **`postrm`**: Added final cleanup on `purge` without removing package-owned files managed by `dpkg`.
- **`preinst`**: Simplified pre-install script to avoid deleting installed files during upgrade/reinstall.
- **Upgrade safety**: Removed destructive maintenance behavior that could delete `/bin/shutils` during reinstall or package upgrade.
- **Shell integration**: Improved idempotent shell hook registration, avoiding duplicate entries in `bashrc` and `zshrc`.
- **Ubuntu 24.04 compatibility**: Adjusted maintainer scripts to behave correctly under newer Debian/Ubuntu package lifecycle handling.

## 0.5 (15/08/24)
- **`portkill`**:Kill all processes running on a specific port.

Expand Down
6 changes: 3 additions & 3 deletions dev/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ EOF
#Using dh_make to create the debian packaging structure

cd shutils/
cd shutils-0.4/
cd shutils-0.6/
rm -rf debian/
dh_make --indep --createorig
# Create the debian/install and preinst files
Expand All @@ -21,8 +21,8 @@ cp ../dev/preinst debian/preinst
cp ../dev/postinst debian/postinst
cp ../dev/postrm debian/postrm
cp ../dev/control debian/control

cp ../dev/prerm debian/prerm
debuild -us -uc

sudo apt remove shutils
sudo dpkg -i ../shutils_0.3-1_all.deb
sudo dpkg -i ../shutils_0.6-1_all.deb
37 changes: 20 additions & 17 deletions dev/postinst
Original file line number Diff line number Diff line change
@@ -1,32 +1,35 @@
#!/bin/bash

set -e
set -x

# Set execution permissions for all files in /bin/shutils/
chmod -R +x /bin/shutils/
SHUTILS_FILE="/bin/shutils/shutils.sh"
PROFILE_FILE="/etc/profile.d/shutils.sh"
BASHRC_FILE="/etc/bash.bashrc"
ZSHRC_FILE="/etc/zsh/zshrc"
HOOK_LINE='. /etc/profile.d/shutils.sh'
Comment on lines +5 to +9
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The installation path /bin/shutils is non-standard according to the Filesystem Hierarchy Standard (FHS), which discourages creating subdirectories within /bin. A more compliant location for package-specific executables and support files would be /usr/lib/shutils. This change would also require updating the path in dev/prerm, dev/postrm, and the debian/install file.

Additionally, HOOK_LINE is hardcoded and could be defined using the PROFILE_FILE variable for better maintainability.

Suggested change
SHUTILS_FILE="/bin/shutils/shutils.sh"
PROFILE_FILE="/etc/profile.d/shutils.sh"
BASHRC_FILE="/etc/bash.bashrc"
ZSHRC_FILE="/etc/zsh/zshrc"
HOOK_LINE='. /etc/profile.d/shutils.sh'
SHUTILS_FILE="/usr/lib/shutils/shutils.sh"
PROFILE_FILE="/etc/profile.d/shutils.sh"
BASHRC_FILE="/etc/bash.bashrc"
ZSHRC_FILE="/etc/zsh/zshrc"
HOOK_LINE=". ${PROFILE_FILE}"


# Check if the shutils.sh file exists
if [ -f /bin/shutils/shutils.sh ]; then
. /bin/shutils/shutils.sh
else
echo "Error: can't find /bin/shutils/shutils.sh file"
if [ ! -f "$SHUTILS_FILE" ]; then
echo "Error: can't find $SHUTILS_FILE"
exit 1
fi

# Export functions to bash and zsh
echo '. /bin/shutils/shutils.sh' > /etc/profile.d/shutils.sh
cat > "$PROFILE_FILE" <<EOF
[ -f "$SHUTILS_FILE" ] && . "$SHUTILS_FILE"
EOF

chmod 644 "$PROFILE_FILE"

# Add shutils to bashrc and zshrc if not already present
if [ -f /etc/bash.bashrc ]; then
if ! grep -q '/etc/profile.d/shutils.sh' /etc/bash.bashrc; then
echo ". /etc/profile.d/shutils.sh" >> /etc/bash.bashrc
if [ -f "$BASHRC_FILE" ]; then
if ! grep -Fqx "$HOOK_LINE" "$BASHRC_FILE"; then
echo "$HOOK_LINE" >> "$BASHRC_FILE"
fi
fi
if [ -f /etc/zsh/zshrc ]; then
if ! grep -q '/etc/profile.d/shutils.sh' /etc/zsh/zshrc; then
echo ". /etc/profile.d/shutils.sh" >> /etc/zsh/zshrc

if [ -f "$ZSHRC_FILE" ]; then
if ! grep -Fqx "$HOOK_LINE" "$ZSHRC_FILE"; then
echo "$HOOK_LINE" >> "$ZSHRC_FILE"
fi
fi

echo "Shutils installation completed."
exit 0
24 changes: 8 additions & 16 deletions dev/postrm
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
#!/bin/bash

set -e
set -x

case "$1" in
remove|upgrade|failed-upgrade|disappear)
# Remove as configurações relacionadas ao shutils do arquivo /etc/bash.bashrc
sed -i '/\. \/etc\/profile\.d\/shutils\.sh/d' /etc/bash.bashrc

# Remove o arquivo /etc/profile.d/shutils.sh
rm -f /etc/profile.d/shutils.sh
BASHRC_FILE="/etc/bash.bashrc"
ZSHRC_FILE="/etc/zsh/zshrc"
PROFILE_FILE="/etc/profile.d/shutils.sh"

# Remove os diretórios /usr/share/shutils e /bin/shutils se eles existirem
if [ -d "/usr/share/shutils" ]; then
rm -rf "/usr/share/shutils"
fi

if [ -d "/bin/shutils" ]; then
rm -rf "/bin/shutils"
fi
case "$1" in
purge)
sed -i '\|^\. /etc/profile\.d/shutils\.sh$|d' "$BASHRC_FILE" || true
sed -i '\|^\. /etc/profile\.d/shutils\.sh$|d' "$ZSHRC_FILE" || true
rm -f "$PROFILE_FILE" || true
;;
esac

Expand Down
24 changes: 3 additions & 21 deletions dev/preinst
Original file line number Diff line number Diff line change
@@ -1,23 +1,5 @@
#!/bin/bash
set -e
set -x

echo "Looking for old version of shutils..."

if [ -f /etc/profile.d/shutils.sh ]; then
sudo rm -f /etc/profile.d/shutils.sh
echo "Removed old shutils from /etc/profile.d..."
fi

if [ -d /bin/shutils ]; then
sudo rm -rf /bin/shutils
echo "Removed old shutils from /bin..."
fi

# Clean up shutils entries from bashrc
if [ -f /etc/bash.bashrc ]; then
sed -i '/\. \/etc\/profile\.d\/shutils\.sh/d' /etc/bash.bashrc
fi

# Check if zshrc exists before trying to modify it
if [ -f /etc/zsh/zshrc ]; then
sed -i '/\. \/etc\/profile\.d\/shutils\.sh/d' /etc/zsh/zshrc
fi
exit 0
17 changes: 17 additions & 0 deletions dev/prerm
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
set -e
set -x

BASHRC_FILE="/etc/bash.bashrc"
ZSHRC_FILE="/etc/zsh/zshrc"
PROFILE_FILE="/etc/profile.d/shutils.sh"

case "$1" in
remove|deconfigure)
sed -i '\|^\. /etc/profile\.d/shutils\.sh$|d' "$BASHRC_FILE" || true
sed -i '\|^\. /etc/profile\.d/shutils\.sh$|d' "$ZSHRC_FILE" || true
rm -f "$PROFILE_FILE" || true
;;
esac

exit 0
6 changes: 0 additions & 6 deletions shutils-0.5/debian/README.Debian

This file was deleted.

10 changes: 0 additions & 10 deletions shutils-0.5/debian/README.source

This file was deleted.

5 changes: 0 additions & 5 deletions shutils-0.5/debian/changelog

This file was deleted.

2 changes: 0 additions & 2 deletions shutils-0.5/debian/files

This file was deleted.

32 changes: 0 additions & 32 deletions shutils-0.5/debian/postinst

This file was deleted.

39 changes: 0 additions & 39 deletions shutils-0.5/debian/postinst.ex

This file was deleted.

25 changes: 0 additions & 25 deletions shutils-0.5/debian/postrm

This file was deleted.

37 changes: 0 additions & 37 deletions shutils-0.5/debian/postrm.ex

This file was deleted.

23 changes: 0 additions & 23 deletions shutils-0.5/debian/preinst

This file was deleted.

35 changes: 0 additions & 35 deletions shutils-0.5/debian/preinst.ex

This file was deleted.

Loading