Created
April 2, 2025 13:18
-
-
Save TomasKulhanek/176f7984f9bdeda0d59d7aad1a5cdad9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| set -e | |
| # --- Clean Up System Caches, Temporary Files, and Logs --- | |
| # List of packages often found in a default Ubuntu installation that you might not need with XFCE. | |
| # Review and modify this list according to your requirements. | |
| PACKAGES_TO_REMOVE=( | |
| # Ubuntu/Unity/GNOME related packages | |
| gnome-shell | |
| gnome-session | |
| unity | |
| # Office suite, media players, and other utilities | |
| thunderbird | |
| rhythmbox | |
| totem | |
| brasero | |
| firefox | |
| # Snap support (if you prefer not to use snap packages) | |
| # snapd | |
| ) | |
| echo "Removing unnecessary packages..." | |
| # Purge the listed packages | |
| apt-get purge -y "${PACKAGES_TO_REMOVE[@]}" | |
| echo "Autoremoving dependencies and cleaning up..." | |
| apt-get autoremove -y | |
| apt-get clean | |
| echo "System minimization complete for a lean XFCE desktop environment." | |
| # Clean apt caches | |
| apt-get clean | |
| rm -rf /var/lib/apt/lists/* | |
| # Remove temporary files | |
| rm -rf /tmp/* | |
| rm -rf /var/tmp/* | |
| # Truncate log files | |
| find /var/log -type f -exec truncate -s 0 {} \; | |
| # (Optional) Remove machine-id so a new one is generated on boot | |
| # rm -f /etc/machine-id | |
| # --- Create and Configure Vagrant User --- | |
| # Create the vagrant user if it doesn't exist | |
| if ! id vagrant &>/dev/null; then | |
| useradd -m -s /bin/bash vagrant | |
| fi | |
| # Setup passwordless sudo for vagrant | |
| echo "vagrant ALL=(ALL) NOPASSWD:ALL" >/etc/sudoers.d/vagrant | |
| chmod 0440 /etc/sudoers.d/vagrant | |
| # --- Install the Default Vagrant SSH Public Key --- | |
| # Create .ssh directory for vagrant user if not exists | |
| mkdir -p /home/vagrant/.ssh | |
| chmod 700 /home/vagrant/.ssh | |
| # Download the default vagrant public key and install it | |
| curl -fsSL https://raw.githubusercontent.com/hashicorp/vagrant/master/keys/vagrant.pub -o /home/vagrant/.ssh/authorized_keys | |
| chmod 600 /home/vagrant/.ssh/authorized_keys | |
| chown -R vagrant:vagrant /home/vagrant/.ssh | |
| echo 'Cleanup bash history' | |
| unset HISTFILE | |
| [ -f /root/.bash_history ] && rm /root/.bash_history | |
| [ -f /home/vagrant/.bash_history ] && rm /home/vagrant/.bash_history | |
| rm -rf /home/vagrant/.cache /home/vagrant/.local /root/.cache /root/.local | |
| echo 'Cleanup log files' | |
| find /var/log -type f | while read f; do echo -ne '' > $f; done | |
| echo Whiteout root | |
| count=`df --sync -kP / | tail -n1 | awk -F ' ' '{print $4}'` | |
| let count-- | |
| dd if=/dev/zero of=/tmp/whitespace bs=1024 count=$count | |
| rm /tmp/whitespace | |
| echo "System cleaning completed and Vagrant user configured." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment