Skip to content

Instantly share code, notes, and snippets.

@flatlinebb
Last active December 23, 2019 02:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flatlinebb/3dea9f4ee2c39ca92ec8bcbd6b0b9a82 to your computer and use it in GitHub Desktop.
Save flatlinebb/3dea9f4ee2c39ca92ec8bcbd6b0b9a82 to your computer and use it in GitHub Desktop.
Debian Server Init Script
#!/bin/bash
logfile=/root/$$.log
exec > $logfile 2>&1
# Can be executed remotely with this command:
# curl -L https://gist.githubusercontent.com/flatlinebb/3dea9f4ee2c39ca92ec8bcbd6b0b9a82/raw/f3b63c55d007375bfb4cb10832ff05d6315ce6d8/debian-initial-install.sh | bash
# Get OS details:
lsb_release -a
# Get IP Address:
echo "***Getting IP Address ..."
ip add | grep inet | grep global > /root/ip_address
echo "***Current IP Address: ..."
cat /root/ip_address | grep global
# Get WAN IP Address:
echo "***Getting WAN IP Address ..."
host myip.opendns.com resolver1.opendns.com | grep "has address" >> /root/ip_address
echo "***Current WAN IP Address: ..."
cat /root/ip_address | grep "has address"
# Install "apt-add-repository" apt module
apt install -y software-properties-common
#Modify APT sources:
echo "***Backup Sources.list ..."
cp -v /etc/apt/sources.list /etc/apt/sources.list.bak
echo "***Add non-free & contrib repositories ..."
apt-add-repository non-free
apt-add-repository contrib
echo "***Installing latest updates ..."
apt update && apt upgrade -y && apt-get clean && apt-get autoclean
#After OS install, install prerequsites:
echo "***Installing prerequisites ..."
apt install -y sudo htop iftop iotop pydf ncdu wget curl nano bwm-ng dnsutils nload
# Set Time Zone:
#echo "America/Los_Angeles" > /etc/timezone
#dpkg-reconfigure -f noninteractive tzdata
export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true
echo -e "tzdata tzdata/Areas select America\ntzdata tzdata/Zones/America select Los_Angeles" > /tmp/tz
debconf-set-selections /tmp/tz
rm /etc/localtime /etc/timezone
dpkg-reconfigure -f non-interactive tzdata
#modify sudoers file if you want:
echo "***Backup sudoers file ..."
cp /etc/sudoers /etc/sudoers.bak
echo "***Add option for no password to sudoers file ..."
echo "%sudo ALL=(ALL) NOPASSWD:ALL" | sudo tee -a /etc/sudoers
echo "***Verify sudoers file changes: ..."
cat /etc/sudoers | grep NOPASSWD
# Run and install updates one last time:
echo "***Installing latest updates ..."
apt update && apt upgrade -y
# All Done
echo "***All Done! ..."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment