Skip to content

Instantly share code, notes, and snippets.

@Ch00k
Last active November 27, 2020 06:00
Show Gist options
  • Save Ch00k/8f7ad2a31a61c8b937e30e265b2f9e54 to your computer and use it in GitHub Desktop.
Save Ch00k/8f7ad2a31a61c8b937e30e265b2f9e54 to your computer and use it in GitHub Desktop.
Slimmed down and updated version of Ubuntu unminimize script
#!/bin/sh
GREEN="\033[0;32m"
RED="\033[0;31m"
RESET="\033[0m"
echo_ok() {
echo -e "${GREEN}$@${RESET}"
}
echo_error() {
echo -e "${RED}$@${RESET}"
}
set -e
if [ -f /etc/dpkg/dpkg.cfg.d/excludes ] || [ -f /etc/dpkg/dpkg.cfg.d/excludes.dpkg-tmp ]; then
echo_ok "Re-enabling installation of all documentation in dpkg..."
if [ -f /etc/dpkg/dpkg.cfg.d/excludes ]; then
mv /etc/dpkg/dpkg.cfg.d/excludes /etc/dpkg/dpkg.cfg.d/excludes.dpkg-tmp
fi
echo_ok "Updating package list and upgrading packages..."
apt-get update
echo_ok "Installing dialog and locales..."
apt-get install dialog
apt-get install locales
echo_ok "Configuring locales..."
sudo dpkg-reconfigure locales
# apt-get upgrade asks for confirmation before upgrading packages to let the user stop here
apt-get upgrade
echo_ok "Restoring system documentation..."
echo_ok "Reinstalling packages with files in /usr/share/man/ ..."
# Reinstallation takes place in two steps because a single dpkg --verified
# command generates very long parameter list for "xargs dpkg -S" and may go
# over ARG_MAX. Since many packages have man pages the second download
# handles a much smaller amount of packages.
dpkg -S /usr/share/man/ |sed 's|, |\n|g;s|: [^:]*$||' | DEBIAN_FRONTEND=noninteractive xargs apt-get install --reinstall -y
echo_ok "Reinstalling packages with system documentation in /usr/share/doc/ .."
# This step processes the packages which still have missing documentation
dpkg --verify --verify-format rpm | awk '/..5...... \/usr\/share\/doc/ {print $2}' | sed 's|/[^/]*$||' | sort |uniq \
| xargs dpkg -S | sed 's|, |\n|g;s|: [^:]*$||' | uniq | DEBIAN_FRONTEND=noninteractive xargs apt-get install --reinstall -y
echo_ok "Restoring system translations..."
# This step processes the packages which still have missing translations
dpkg --verify --verify-format rpm | awk '/..5...... \/usr\/share\/locale/ {print $2}' | sed 's|/[^/]*$||' | sort |uniq \
| xargs dpkg -S | sed 's|, |\n|g;s|: [^:]*$||' | uniq | DEBIAN_FRONTEND=noninteractive xargs apt-get install --reinstall -y
if dpkg --verify --verify-format rpm | awk '/..5...... \/usr\/share\/doc/ {exit 1}'; then
echo_ok "Documentation has been restored successfully."
rm /etc/dpkg/dpkg.cfg.d/excludes.dpkg-tmp
else
echo_error "There are still files missing from /usr/share/doc/:"
dpkg --verify --verify-format rpm | awk '/..5...... \/usr\/share\/doc/ {print " " $2}'
echo_error "You may want to try running this script again or you can remove"
echo_error "/etc/dpkg/dpkg.cfg.d/excludes.dpkg-tmp and restore the files manually."
fi
fi
if [ "$(dpkg-divert --truename /usr/bin/man)" = "/usr/bin/man.REAL" ]; then
# Remove diverted man binary
rm -f /usr/bin/man
dpkg-divert --quiet --remove --rename /usr/bin/man
fi
echo_ok "Installing man-db..."
apt install man-db
echo_ok "Removing lxd installer package..."
apt-get purge -y lxd-installer
# unminimization succeeded, there is no need to mention it in motd
rm -f /etc/update-motd.d/60-unminimize
echo_ok "Success"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment