-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_homelabos.sh
executable file
·83 lines (71 loc) · 3.3 KB
/
install_homelabos.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash
MASTER_VERSION=$(curl https://gitlab.com/NickBusey/HomelabOS/-/raw/master/VERSION)
VERSION=${VERSION:-$MASTER_VERSION}
echo "Building version: $VERSION"
REPO=NickBusey
while getopts r:v: option
do
case "${option}"
in
v) VERSION=${OPTARG} ;;
r) REPO=${OPTARG} ;;
esac
done
is_tested() {
case "$(. /etc/os-release && echo "$ID")" in
*ubuntu* ) true ;;
* ) false;;
esac
}
hlos_install() {
printf "\x1B[01;93m========== Updating system ==========\n\x1B[0m"
sudo apt update
printf "\x1B[01;93m========== Install make and docker ==========\n\x1B[0m"
sudo apt install -y make
sudo apt install -y docker-compose
printf "\x1B[01;93m========== Ensure keys exist ==========\n\x1B[0m"
# Create .ssh/ if it doesn't exist
[ -d ~/.ssh/ ] || mkdir ~/.ssh
# Generate passwordless keys if they don't exist
[ -f ~/.ssh/id_rsa ] || ssh-keygen -N "" -f ~/.ssh/id_rsa
# Create an authorized_keys file if it doesn't exist
[ -f ~/.ssh/authorized_keys ] || touch ~/.ssh/authorized_keys
# Add our key to it if it is not present
KEY=$(cat ~/.ssh/id_rsa.pub)
grep -Fxq "$KEY" ~/.ssh/authorized_keys || cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
# Download and extract HomelabOS
printf "\x1B[01;93m========== Download and extract HomelabOS ==========\n\x1B[0m"
curl -OL https://gitlab.com/$REPO/HomelabOS/-/archive/$VERSION/HomelabOS-$VERSION.tar.gz
tar -xvzf HomelabOS-$VERSION.tar.gz
rm HomelabOS-$VERSION.tar.gz
printf "\x1B[01;93m========== Create install directory ==========\n\x1B[0m"
sudo mkdir -p /var/homelabos/install
sudo mv HomelabOS-$VERSION/* /var/homelabos/install/
rm -rf HomelabOS-$VERSION
cd /var/homelabos/install
USER=$(whoami)
sudo chown -R $USER ./
mkdir settings
# Setup IP configuration
printf "\x1B[01;93m========== Configure networking ==========\n\x1B[0m"
export HOMELAB_IP=$(hostname -I | awk '{print $1}')
printf "homelab_ip: $HOMELAB_IP\nhomelab_ssh_user: $(whoami)" > settings/config.yml
printf "We have detected and set your homelab_ip to: $HOMELAB_IP\nIf this is incorrect, edit your /var/homelabos/install/settings/config.yml file to fix it.\n"
printf "\n\n\x1B[01;92m========== HomelabOS downloaded! ==========\n\x1B[0m"
make deploy
printf "\n\x1B[01;93mYou can check the status of Organizr with \x1B[01;92m'systemctl status organizr'\x1B[01;93m or \x1B[01;92m'sudo docker ps'\x1B[01;93m"
printf "\nTo enable more services, run \x1B[01;92m'cd /var/homelabos/install'\x1B[01;93m then \x1B[01;92m'make set servicename.enable true'\x1B[01;93m"
printf "\nwhere servicename is a service you would like to have."
printf "\n\nExample: \x1B[01;92m'make set miniflux.enable true'";
printf "\n\n\x1B[01;93mOnce you have enabled all the services you would like, simply run \x1B[38;5;184m'make deploy'.\x1B[01;93m\n\n";
printf "\x1B[01;92m================== Done. ==================\n\x1B[0m\n\n"
}
#Check if distro is tested, warn if not.
if is_tested; then
echo
else
printf "\n\033[0;31mUntested operating system detected! You may press Ctrl+C now to abort this script.\nInstallation will proceed in 10 seconds.\n\n"
sleep 10
fi
# Actually do the install. Put in function and run at end to prevent parcial download and execution.
hlos_install