Last active
July 24, 2021 16:53
-
-
Save Limych/bb4e9f66b99acf35057e0b7072c112f1 to your computer and use it in GitHub Desktop.
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
#!/bin/sh | |
# Add swap space | |
sudo dphys-swapfile swapoff | |
sudo sed -r -i "s/(CONF_SWAPSIZE\s*=.*)/#\1/g; s/#((CONF_MAXSWAP\s*=).*)/\24096/g" /etc/dphys-swapfile | |
sudo dphys-swapfile swapon | |
# Update Raspberry Pi and schedule auto-updates | |
sudo apt-get update && sudo apt-get full-upgrade -y && sudo apt-get dist-upgrade -y | |
sudo apt-get autoremove -y | |
sudo apt-get autoclean | |
sudo apt-get install -y pi-bluetooth pwgen cifs-utils python3-pip | |
# | |
cat >~/update.sh <<__EOF__ | |
#!/bin/sh | |
sudo apt-get update && sudo apt-get full-upgrade -y && sudo apt-get dist-upgrade -y | |
sudo apt-get autoremove -y | |
sudo apt-get autoclean | |
sudo pip3 install --upgrade pip | |
# sudo pip3 list --outdated --format=freeze | grep -v '^\-e' | cut -d = -f 1 | sudo xargs -n1 pip3 install -U | |
sudo reboot | |
__EOF__ | |
sudo chmod +x ~/update.sh | |
install -d ~/logs | |
crontab -l | { cat; echo "0 3 * * SAT sh ${HOME}/update.sh 2>${HOME}/logs/cronlog"; } | crontab - | |
# Setup watchdog | |
sudo apt-get install -y watchdog | |
sudo sed -r -i "s/#(max-load-15\s*=.*)/\1/g; s/#(watchdog-device\s*=.*)/\1/g" /etc/watchdog.conf | |
# Install Docker | |
curl -fsSL get.docker.com -o ~/get-docker.sh | |
sudo sh ~/get-docker.sh | |
rm ~/get-docker.sh | |
sudo usermod -aG docker pi | |
docker --version | |
# Restore data from backup on external drive | |
#TODO | |
# Load .env variables | |
set -a | |
. /opt/.env | |
set +a | |
# Setup data backup to external drive | |
cat >~/backup.sh <<__EOF__ | |
#!/bin/bash | |
SMB_PATH='//nas/Archive/Backups/@ Hardware/cfg-Hassio' | |
SMB_USER='YOUR_USERNAME' | |
SMB_PASS='YOUR_PASSWORD' | |
DEST_FOLDER='/mnt/backup' | |
DEST_FILE="$(hostname)-$(date +%Y%m%d_%H%M).tar.gz" | |
sudo install -d ${DEST_FOLDER} | |
sudo mount -t cifs -o username="${SMB_USER}",password="${SMB_PASS}" "${SMB_PATH}" ${DEST_FOLDER} | |
sudo rm -Rf /opt/hassio/tmp/* | |
sudo /bin/tar -czvf ${DEST_FOLDER}/${DEST_FILE} --exclude=/opt/hassio/backup /opt | |
sudo /usr/bin/find ${DEST_FOLDER} -mtime +90 -delete | |
sudo umount ${DEST_FOLDER} | |
__EOF__ | |
sed -i "s/YOUR_USERNAME/${NAS_USER}/g; s/YOUR_PASSWORD/${NAS_PASS}/g" ~/backup.sh | |
sudo chmod +x ~/backup.sh | |
install -d ~/logs | |
crontab -l | { cat; echo "0 3 * * MON sh ${HOME}/backup.sh 2>${HOME}/logs/cronlog"; } | crontab - | |
# Prepare Docker containers | |
sudo apt-get install -y jq avahi-daemon dbus apparmor-utils | |
curl -sL https://raw.githubusercontent.com/home-assistant/hassio-installer/master/hassio_install.sh | sudo bash -s -- -m raspberrypi3 -d /opt/hassio | |
#TODO | |
# Install repository updater | |
# sudo pip3 install repository-updater | |
# install -d ~/logs | |
# crontab -l | { cat; echo "0 3 * * * repository-updater --token ${GITHUB_TOKEN} --repository Limych/hassio-addons 2>${HOME}/logs/repository-updater.log"; } | crontab - |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment