Skip to content

Instantly share code, notes, and snippets.

@jcppkkk
Last active February 6, 2024 22:35
Show Gist options
  • Select an option

  • Save jcppkkk/ba195725a2532bce3740315c637b7414 to your computer and use it in GitHub Desktop.

Select an option

Save jcppkkk/ba195725a2532bce3740315c637b7414 to your computer and use it in GitHub Desktop.

Revisions

  1. jcppkkk revised this gist Mar 2, 2023. 1 changed file with 12 additions and 17 deletions.
    29 changes: 12 additions & 17 deletions prepare-ubuntu-template.sh
    Original file line number Diff line number Diff line change
    @@ -6,19 +6,17 @@ if [ `id -u` -ne 0 ]; then
    exit 1
    fi
    set -v
    #add VMware package keys
    wget http://packages.vmware.com/tools/keys/VMWARE-PACKAGING-GPG-DSA-KEY.pub -O - | apt-key add -

    #update apt-cache
    apt-get update

    #install packages
    # Install vmware guest tool
    apt-get update
    apt-get install -y open-vm-tools
    apt-get clean

    #Stop services for cleanup
    # Stop services for cleanup
    service rsyslog stop

    #clear audit logs
    # Clear audit logs
    if [ -f /var/log/audit/audit.log ]; then
    cat /dev/null > /var/log/audit/audit.log
    fi
    @@ -29,19 +27,19 @@ if [ -f /var/log/lastlog ]; then
    cat /dev/null > /var/log/lastlog
    fi

    #cleanup persistent udev rules
    # Cleanup persistent udev rules
    if [ -f /etc/udev/rules.d/70-persistent-net.rules ]; then
    rm /etc/udev/rules.d/70-persistent-net.rules
    fi

    #cleanup /tmp directories
    # Cleanup /tmp directories
    rm -rf /tmp/*
    rm -rf /var/tmp/*

    #cleanup current ssh keys
    # Cleanup current ssh keys
    rm -f /etc/ssh/ssh_host_*

    #add check for ssh keys on reboot...regenerate if neccessary
    # regenerate ssh keys on next boot
    cat <<EOL | sudo tee /etc/rc.local
    #!/bin/sh -e
    #
    @@ -60,12 +58,9 @@ test -f /etc/ssh/ssh_host_dsa_key || dpkg-reconfigure openssh-server
    exit 0
    EOL

    #reset hostname
    # Reset hostname
    cat /dev/null > /etc/hostname

    #cleanup apt
    apt-get clean

    #cleanup shell history
    # Cleanup shell history
    history -c
    history -w
    history -w
  2. jcppkkk created this gist Jul 31, 2017.
    71 changes: 71 additions & 0 deletions prepare-ubuntu-template.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,71 @@
    #!/bin/bash
    id

    if [ `id -u` -ne 0 ]; then
    echo Need sudo
    exit 1
    fi
    set -v
    #add VMware package keys
    wget http://packages.vmware.com/tools/keys/VMWARE-PACKAGING-GPG-DSA-KEY.pub -O - | apt-key add -

    #update apt-cache
    apt-get update

    #install packages
    apt-get install -y open-vm-tools

    #Stop services for cleanup
    service rsyslog stop

    #clear audit logs
    if [ -f /var/log/audit/audit.log ]; then
    cat /dev/null > /var/log/audit/audit.log
    fi
    if [ -f /var/log/wtmp ]; then
    cat /dev/null > /var/log/wtmp
    fi
    if [ -f /var/log/lastlog ]; then
    cat /dev/null > /var/log/lastlog
    fi

    #cleanup persistent udev rules
    if [ -f /etc/udev/rules.d/70-persistent-net.rules ]; then
    rm /etc/udev/rules.d/70-persistent-net.rules
    fi

    #cleanup /tmp directories
    rm -rf /tmp/*
    rm -rf /var/tmp/*

    #cleanup current ssh keys
    rm -f /etc/ssh/ssh_host_*

    #add check for ssh keys on reboot...regenerate if neccessary
    cat <<EOL | sudo tee /etc/rc.local
    #!/bin/sh -e
    #
    # rc.local
    #
    # This script is executed at the end of each multiuser runlevel.
    # Make sure that the script will "" on success or any other
    # value on error.
    #
    # In order to enable or disable this script just change the execution
    # bits.
    #
    # By default this script does nothing.
    test -f /etc/ssh/ssh_host_dsa_key || dpkg-reconfigure openssh-server
    exit 0
    EOL

    #reset hostname
    cat /dev/null > /etc/hostname

    #cleanup apt
    apt-get clean

    #cleanup shell history
    history -c
    history -w