Created
March 2, 2025 16:00
-
-
Save Cerothen/fa1d2fbeda964d7e8f9f868094987bae to your computer and use it in GitHub Desktop.
LXC Init
This file contains 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
#!/usr/bin/env bash | |
# bash -c "$(wget -O - https://gist.githubusercontent.com/Cerothen/fa1d2fbeda964d7e8f9f868094987bae/raw/9bdeb56386ad9ff5ec947064c50a7dff4445dfcc/gistfile1.txt)" | |
# Make sure we arent running on a PVE host! | |
if [ -d "/etc/pve" ] || [ ! -z "$(command -v pvenode)" ]; then | |
echo "Do not run this on a Proxmox host!" | |
exit 1 | |
fi | |
# Allow Root SSH with password if not already enabled? | |
if ! grep -qF "PermitRootLogin Yes" /etc/ssh/sshd_config;then | |
read -p "Would you like to allow 'root' to ssh with password? (y/n)? " sshRootAnswer | |
case ${sshRootAnswer:0:1} in | |
y|Y ) | |
sed -i -E "s/#?\s*[Pp]ermit[Rr]oot[Ll]ogin\s+\S+/PermitRootLogin Yes/g" /etc/ssh/sshd_config | |
service ssh restart | |
echo "Allow 'root' over ssh." | |
;; | |
* ) | |
echo "No changes for 'root' over ssh." | |
;; | |
esac | |
fi | |
# Updates | |
read -p "Automatic upgrades of (A)ll/(S)ecurity/(N)one? (a/s/n)? " updatesAnswer | |
# Update System To Latest | |
echo "Updating packages..." | |
apt-get update | |
apt-get -y upgrade | |
# Add dirmngr to allow gpg to work | |
echo "Install dirmngr" | |
apt-get install -y dirmngr --install-recommends | |
# Sudo | |
echo "Install sudo" | |
apt-get install -y sudo | |
# Curl | |
echo "Install curl" | |
apt-get install -y curl | |
# Adjust Timezone | |
echo "Adjust timezone to America/Toronto" | |
ln -fs /usr/share/zoneinfo/America/Toronto /etc/localtime | |
dpkg-reconfigure --frontend noninteractive tzdata | |
# Set Locale | |
echo "Set Locale to UTF-8" | |
sed -i -e "s/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/" /etc/locale.gen | |
dpkg-reconfigure --frontend=noninteractive locales | |
update-locale LANG=en_US.UTF-8 | |
# locale-gen --purge en_US.UTF-8 | |
export LANG=en_US.UTF-8 LANGUAGE=en_US.en LC_ALL=en_US.UTF-8 | |
echo -e 'LANG="en_US.UTF-8"\nLANGUAGE="en_US:en"\n' > /etc/default/locale | |
# Locale for python 2 | |
for i in /etc/python2*; do | |
if [ -f "$i/sitecustomize.py" ]; then | |
if ! grep -qF "utf-8" "$i/sitecustomize.py";then | |
echo "Adding locale to sitecustomize.py for $i" | |
echo -e '\n\nimport sys\nsys.setdefaultencoding("utf-8")' >> "$i/sitecustomize.py" | |
fi | |
fi | |
done | |
# Create SSH RSA key | |
echo "Creating SSH RSA key for passwordless authentication" | |
ssh-keygen -q -t rsa -f /root/.ssh/id_rs -P "" | |
cat /root/.ssh/id_rs.pub | |
# Cleanup | |
echo "Cleanup" | |
apt-get autoremove | |
apt-get autoclean | |
# Automatic updates | |
case ${updatesAnswer:0:1} in | |
a|A ) | |
if ! grep -qF "apt-get update && apt-get upgrade -y" /etc/crontab;then | |
echo "Set CRONTAB for package upgrading" | |
MIN=$(shuf -i 1-59 -n 1) | |
HOUR=$(shuf -i 1-5 -n 1) | |
echo "$MIN $HOUR * * * root apt-get update && apt-get upgrade -y" >> /etc/crontab | |
echo "" >> /etc/crontab | |
fi | |
;; | |
s|S ) | |
echo "Install unattended-upgrades for security updates" | |
apt install unattended-upgrades -y | |
;; | |
* ) | |
echo "No automatic upgrades" | |
;; | |
esac | |
echo "Automatic initialization completed!" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment