Compare commits
6 Commits
c2ca0dfe27
...
v0.1.0
Author | SHA1 | Date | |
---|---|---|---|
![]() |
8af3e1a3d3 | ||
![]() |
8b975e7d54 | ||
![]() |
2d22b15e85 | ||
![]() |
e93f2a634a | ||
![]() |
851f1b1344 | ||
![]() |
171e9dd89e |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +0,0 @@
|
|||||||
starter/config.json
|
|
@@ -60,6 +60,7 @@ in {
|
|||||||
|
|
||||||
# Networking
|
# Networking
|
||||||
networking = {
|
networking = {
|
||||||
|
hostName = jsonConfig.hostname;
|
||||||
firewall = {
|
firewall = {
|
||||||
enable = true;
|
enable = true;
|
||||||
# Only allow necessary ports
|
# Only allow necessary ports
|
0
starter/env/n8n.env → env/n8n.env
vendored
0
starter/env/n8n.env → env/n8n.env
vendored
152
flake.lock
generated
152
flake.lock
generated
@@ -1,24 +1,166 @@
|
|||||||
{
|
{
|
||||||
"nodes": {
|
"nodes": {
|
||||||
|
"base-config": {
|
||||||
|
"inputs": {
|
||||||
|
"nixpkgs": "nixpkgs",
|
||||||
|
"nixpkgs-unstable": "nixpkgs-unstable"
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1744363797,
|
||||||
|
"narHash": "sha256-Zn8TIOonPBQojN5NZ9Q+y6hvwAKFvW+iLXiceGNQ40o=",
|
||||||
|
"ref": "stable",
|
||||||
|
"rev": "45622da8ac40d404e59fa1eff9f63e42b7b95e2b",
|
||||||
|
"revCount": 10,
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://code.m3ta.dev/m3tam3re/self-host-playbook-base"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"ref": "stable",
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://code.m3ta.dev/m3tam3re/self-host-playbook-base"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"deploy-rs": {
|
||||||
|
"inputs": {
|
||||||
|
"flake-compat": "flake-compat",
|
||||||
|
"nixpkgs": "nixpkgs_2",
|
||||||
|
"utils": "utils"
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1727447169,
|
||||||
|
"narHash": "sha256-3KyjMPUKHkiWhwR91J1YchF6zb6gvckCAY1jOE+ne0U=",
|
||||||
|
"owner": "serokell",
|
||||||
|
"repo": "deploy-rs",
|
||||||
|
"rev": "aa07eb05537d4cd025e2310397a6adcedfe72c76",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "serokell",
|
||||||
|
"repo": "deploy-rs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"disko": {
|
||||||
|
"inputs": {
|
||||||
|
"nixpkgs": ["nixpkgs"]
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1744145203,
|
||||||
|
"narHash": "sha256-I2oILRiJ6G+BOSjY+0dGrTPe080L3pbKpc+gCV3Nmyk=",
|
||||||
|
"owner": "nix-community",
|
||||||
|
"repo": "disko",
|
||||||
|
"rev": "76c0a6dba345490508f36c1aa3c7ba5b6b460989",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nix-community",
|
||||||
|
"repo": "disko",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"flake-compat": {
|
||||||
|
"flake": false,
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1696426674,
|
||||||
|
"narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=",
|
||||||
|
"owner": "edolstra",
|
||||||
|
"repo": "flake-compat",
|
||||||
|
"rev": "0f9255e01c2351cc7d116c072cb317785dd33b33",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "edolstra",
|
||||||
|
"repo": "flake-compat",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1741379970,
|
"lastModified": 1741600792,
|
||||||
"narHash": "sha256-Wh7esNh7G24qYleLvgOSY/7HlDUzWaL/n4qzlBePpiw=",
|
"narHash": "sha256-yfDy6chHcM7pXpMF4wycuuV+ILSTG486Z/vLx/Bdi6Y=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "36fd87baa9083f34f7f5027900b62ee6d09b1f2f",
|
"rev": "ebe2788eafd539477f83775ef93c3c7e244421d3",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"ref": "nixos-unstable",
|
"ref": "nixos-24.11",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nixpkgs-unstable": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1741708242,
|
||||||
|
"narHash": "sha256-cNRqdQD4sZpN7JLqxVOze4+WsWTmv2DGH0wNCOVwrWc=",
|
||||||
|
"owner": "NixOS",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "b62d2a95c72fb068aecd374a7262b37ed92df82b",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "NixOS",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "b62d2a95c72fb068aecd374a7262b37ed92df82b",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nixpkgs_2": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1702272962,
|
||||||
|
"narHash": "sha256-D+zHwkwPc6oYQ4G3A1HuadopqRwUY/JkMwHz1YF7j4Q=",
|
||||||
|
"owner": "NixOS",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "e97b3e4186bcadf0ef1b6be22b8558eab1cdeb5d",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "NixOS",
|
||||||
|
"ref": "nixpkgs-unstable",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"root": {
|
"root": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"nixpkgs": "nixpkgs"
|
"base-config": "base-config",
|
||||||
|
"deploy-rs": "deploy-rs",
|
||||||
|
"disko": "disko",
|
||||||
|
"nixpkgs": ["base-config", "nixpkgs"]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"systems": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1681028828,
|
||||||
|
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"utils": {
|
||||||
|
"inputs": {
|
||||||
|
"systems": "systems"
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1701680307,
|
||||||
|
"narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=",
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"rev": "4022d587cbbfd70fe950c1e2083a02621806a725",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"type": "github"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
66
flake.nix
66
flake.nix
@@ -1,29 +1,57 @@
|
|||||||
{
|
{
|
||||||
description = "Self Host Playbook!";
|
description = "Self-hosted server setup with Portainer, n8n, and Baserow";
|
||||||
|
|
||||||
inputs = {
|
inputs = {
|
||||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
base-config = {
|
||||||
|
# url = "path:/home/m3tam3re/p/nix/self-host-playbook-base";
|
||||||
|
url = "git+https://code.m3ta.dev/m3tam3re/self-host-playbook-base?ref=stable";
|
||||||
|
};
|
||||||
|
nixpkgs = {
|
||||||
|
url = "github:NixOS/nixpkgs/nixos-24.11";
|
||||||
|
follows = "base-config/nixpkgs";
|
||||||
|
};
|
||||||
|
disko = {
|
||||||
|
url = "github:nix-community/disko";
|
||||||
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
|
};
|
||||||
|
deploy-rs = {
|
||||||
|
url = "github:serokell/deploy-rs";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs = {nixpkgs, ...}: let
|
outputs = {
|
||||||
systems = [
|
self,
|
||||||
"aarch64-linux"
|
base-config,
|
||||||
"i686-linux"
|
deploy-rs,
|
||||||
"x86_64-linux"
|
nixpkgs,
|
||||||
"aarch64-darwin"
|
...
|
||||||
"x86_64-darwin"
|
} @ inputs: let
|
||||||
];
|
jsonConfig = builtins.fromJSON (builtins.readFile ./config.json);
|
||||||
forAllSystems = nixpkgs.lib.genAttrs systems;
|
|
||||||
in {
|
in {
|
||||||
templates = {
|
nixosConfigurations.${jsonConfig.hostname} = nixpkgs.lib.nixosSystem {
|
||||||
starter = {
|
system = "x86_64-linux";
|
||||||
description = ''
|
modules = [
|
||||||
Description here!
|
(base-config.nixosModules.default {
|
||||||
'';
|
tier = "starter";
|
||||||
path = ./starter;
|
inherit jsonConfig;
|
||||||
|
}) # Pass tier here
|
||||||
|
inputs.disko.nixosModules.disko
|
||||||
|
./configuration.nix
|
||||||
|
];
|
||||||
|
specialArgs = {
|
||||||
|
inherit self;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
deploy.nodes.${jsonConfig.hostname} = {
|
||||||
|
hostname = jsonConfig.hostname;
|
||||||
|
profiles.system = {
|
||||||
|
sshUser = jsonConfig.username;
|
||||||
|
user = "root";
|
||||||
|
interactiveSudo = true;
|
||||||
|
path =
|
||||||
|
deploy-rs.lib.x86_64-linux.activate.nixos
|
||||||
|
self.nixosConfigurations.${jsonConfig.hostname};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
formatter =
|
|
||||||
forAllSystems (system: nixpkgs.legacyPackages.${system}.alejandra);
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@@ -13,14 +13,23 @@ fi
|
|||||||
if [ -z "${INSIDE_NIX_SHELL+x}" ]; then
|
if [ -z "${INSIDE_NIX_SHELL+x}" ]; then
|
||||||
export NIX_CONFIG="experimental-features = nix-command flakes"
|
export NIX_CONFIG="experimental-features = nix-command flakes"
|
||||||
export INSIDE_NIX_SHELL=1
|
export INSIDE_NIX_SHELL=1
|
||||||
exec nix shell nixpkgs#git nixpkgs#mkpasswd --command bash "$0"
|
exec nix shell nixpkgs#git nixpkgs#mkpasswd nixpkgs#jq --command bash "$0"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Function to setup from template
|
# Check directory situation and handle navigation
|
||||||
setup_from_template() {
|
DIR_NAME="self-host-playbook"
|
||||||
local TEMPLATE=starter
|
CURRENT_DIR=$(basename "$(pwd)")
|
||||||
local DIR_NAME="self-host-playbook"
|
|
||||||
|
|
||||||
|
if [ "$CURRENT_DIR" = "$DIR_NAME" ]; then
|
||||||
|
echo "📂 Already in $DIR_NAME directory"
|
||||||
|
echo "⚠️ Warning: Proceeding will overwrite the current version!"
|
||||||
|
read -p "Do you want to continue? (y/N) " -n 1 -r
|
||||||
|
echo
|
||||||
|
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
||||||
|
echo "❌ Operation cancelled"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
else
|
||||||
if [ -d "$DIR_NAME" ]; then
|
if [ -d "$DIR_NAME" ]; then
|
||||||
echo "📂 Directory '$DIR_NAME' already exists"
|
echo "📂 Directory '$DIR_NAME' already exists"
|
||||||
read -p "Do you want to proceed in the existing directory? (y/N) " -n 1 -r
|
read -p "Do you want to proceed in the existing directory? (y/N) " -n 1 -r
|
||||||
@@ -32,10 +41,98 @@ setup_from_template() {
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "🔄 Creating new self-host-playbook configuration from template..."
|
echo "🔄 Creating new self-host-playbook configuration..."
|
||||||
nix flake new --template "git+https://code.m3tam3re.com/m3tam3re/self-host-playbook#${TEMPLATE}" "$DIR_NAME"
|
mkdir -p "$DIR_NAME"
|
||||||
cd "$DIR_NAME"
|
cd "$DIR_NAME"
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
get_latest_version() {
|
||||||
|
local LATEST_VERSION
|
||||||
|
|
||||||
|
latest_version=$(curl -s "https://code.m3ta.dev/api/v1/repos/m3tam3re/self-host-playbook/tags" | jq -r '.[] | select(.name | startswith("v")) | .name' | sort -V | tail -n1)
|
||||||
|
|
||||||
|
if [ -z "$latest_version" ]; then
|
||||||
|
echo "❌ Error: Could not fetch latest version from repository"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Remove 'v' prefix if present and return
|
||||||
|
echo "${latest_version#v}"
|
||||||
|
}
|
||||||
|
|
||||||
|
setup_latest_version() {
|
||||||
|
local target_version=$1
|
||||||
|
local dir_name=$2
|
||||||
|
|
||||||
|
# Safety check: Ensure we're in the self-host-playbook directory
|
||||||
|
local current_dir=$(basename "$(pwd)")
|
||||||
|
if [ "$current_dir" != "self-host-playbook" ]; then
|
||||||
|
echo "❌ Error: Must be in 'self-host-playbook' directory to setup latest version"
|
||||||
|
echo "Current directory: $(pwd)"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "⬇️ Downloading version $target_version..."
|
||||||
|
|
||||||
|
TEMP_DIR=$(mktemp -d)
|
||||||
|
trap 'rm -rf "$TEMP_DIR"' EXIT
|
||||||
|
|
||||||
|
# Create a subdirectory for the clone
|
||||||
|
CLONE_DIR="${TEMP_DIR}/clone"
|
||||||
|
mkdir -p "$CLONE_DIR"
|
||||||
|
|
||||||
|
# Clone to temporary directory with --quiet flag
|
||||||
|
if ! nix flake clone --quiet "git+https://code.m3ta.dev/m3tam3re/self-host-playbook?ref=v${target_version}" --dest "$CLONE_DIR" 2>/dev/null; then
|
||||||
|
echo "❌ Failed to clone repository"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Additional safety check before copying files
|
||||||
|
if [ ! -f "$CLONE_DIR/flake.nix" ]; then
|
||||||
|
echo "❌ Error: Downloaded content doesn't appear to be a valid self-host-playbook"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Copy files from clone to target directory
|
||||||
|
cp -r "$CLONE_DIR"/* "$dir_name/"
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to setup from template
|
||||||
|
setup_from_template() {
|
||||||
|
# Ensure we're in the correct directory
|
||||||
|
local current_dir=$(basename "$(pwd)")
|
||||||
|
if [ "$current_dir" != "self-host-playbook" ]; then
|
||||||
|
echo "❌ Error: Must be in 'self-host-playbook' directory"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Create backup if directory is not empty
|
||||||
|
if [ -n "$(ls -A)" ]; then
|
||||||
|
local CURRENT_VERSION=$(date +%Y%m%d_%H%M%S)
|
||||||
|
local backup_dir="backup_${CURRENT_VERSION}_$(date +%Y%m%d_%H%M%S)"
|
||||||
|
echo "📑 Creating backup in $backup_dir..."
|
||||||
|
mkdir -p "$backup_dir"
|
||||||
|
# Add safety check for backup creation
|
||||||
|
if [ ! -d "$backup_dir" ]; then
|
||||||
|
echo "❌ Error: Failed to create backup directory"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
find . -maxdepth 1 ! -name "." ! -name ".." ! -name "$backup_dir" -exec cp -r {} "$backup_dir/" \;
|
||||||
|
echo "✅ Backup created successfully"
|
||||||
|
|
||||||
|
# Clean current directory except backup
|
||||||
|
echo "🗑️ Cleaning current directory..."
|
||||||
|
find . -maxdepth 1 ! -name "." ! -name ".." ! -name "$backup_dir" -exec rm -rf {} \;
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Get and setup latest version
|
||||||
|
local LATEST_VERSION=$(get_latest_version)
|
||||||
|
echo "⬇️ Setting up version $LATEST_VERSION..."
|
||||||
|
setup_latest_version "$LATEST_VERSION" "."
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to generate SSH key
|
# Function to generate SSH key
|
||||||
@@ -122,6 +219,60 @@ get_device_name() {
|
|||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setup_ssh_config() {
|
||||||
|
local username=$1
|
||||||
|
local ip_address=$2
|
||||||
|
local hostname=$3 # Add hostname parameter
|
||||||
|
local ssh_config_dir="$HOME/.ssh"
|
||||||
|
local ssh_config_file="$ssh_config_dir/config"
|
||||||
|
local ssh_key_file="$ssh_config_dir/self-host-playbook"
|
||||||
|
|
||||||
|
# Create .ssh directory if it doesn't exist
|
||||||
|
mkdir -p "$ssh_config_dir"
|
||||||
|
chmod 700 "$ssh_config_dir"
|
||||||
|
|
||||||
|
# Create or append to SSH config using hostname as the Host name
|
||||||
|
local config_entry="Host $hostname
|
||||||
|
HostName $ip_address
|
||||||
|
User $username
|
||||||
|
Port 2222
|
||||||
|
IdentityFile $ssh_key_file"
|
||||||
|
|
||||||
|
# Check if entry already exists
|
||||||
|
if ! grep -q "Host $hostname" "$ssh_config_file" 2>/dev/null; then
|
||||||
|
echo -e "\n$config_entry" >> "$ssh_config_file"
|
||||||
|
echo "✅ Added SSH config entry"
|
||||||
|
else
|
||||||
|
# Update existing entry
|
||||||
|
sed -i.bak "/Host $hostname/,/IdentityFile.*/{
|
||||||
|
s/HostName.*/HostName $ip_address/
|
||||||
|
s/User.*/User $username/
|
||||||
|
}" "$ssh_config_file"
|
||||||
|
echo "✅ Updated existing SSH config entry"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Set appropriate permissions
|
||||||
|
chmod 600 "$ssh_config_file"
|
||||||
|
}
|
||||||
|
|
||||||
|
install_deploy_rs() {
|
||||||
|
echo "🔧 Installing deploy-rs to user environment..."
|
||||||
|
|
||||||
|
# Check if deploy is already installed
|
||||||
|
if command -v deploy >/dev/null 2>&1; then
|
||||||
|
echo "ℹ️ deploy-rs is already installed"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Install deploy-rs using nix profile
|
||||||
|
if nix profile install 'github:serokell/deploy-rs'; then
|
||||||
|
echo "✅ deploy-rs installed successfully"
|
||||||
|
else
|
||||||
|
echo "❌ Failed to install deploy-rs"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
echo "🚀 Welcome to the Self-Host Playbook!"
|
echo "🚀 Welcome to the Self-Host Playbook!"
|
||||||
echo "================================================"
|
echo "================================================"
|
||||||
echo "This script will help you manage your NixOS server with:"
|
echo "This script will help you manage your NixOS server with:"
|
||||||
@@ -143,11 +294,11 @@ SSH_PUB_KEY=$(cat "${SSH_KEY_PATH}.pub") || {
|
|||||||
echo
|
echo
|
||||||
echo "🔑 Here is your public key:"
|
echo "🔑 Here is your public key:"
|
||||||
echo
|
echo
|
||||||
cat $SSH_KEY_PATH.pub
|
cat "$SSH_KEY_PATH.pub"
|
||||||
echo ""
|
echo ""
|
||||||
echo "📁 You can also find the keyfile here:"
|
echo "📁 You can also find the keyfile here:"
|
||||||
echo
|
echo
|
||||||
echo $SSH_KEY_PATH.pub
|
echo "$SSH_KEY_PATH.pub"
|
||||||
echo
|
echo
|
||||||
read -p "Press ENTER to continue or CTRL + C to abort..."
|
read -p "Press ENTER to continue or CTRL + C to abort..."
|
||||||
|
|
||||||
@@ -155,16 +306,24 @@ read -p "Press ENTER to continue or CTRL + C to abort..."
|
|||||||
echo ""
|
echo ""
|
||||||
echo "📝 Please provide the following information:"
|
echo "📝 Please provide the following information:"
|
||||||
echo "-------------------------------------------"
|
echo "-------------------------------------------"
|
||||||
read -p "1. Enter target server IP address: " SERVER_IP
|
read -p "1. Enter target server IP address: " IP_ADDRESS
|
||||||
read -p "2. Enter desired username for server access: " USERNAME
|
read -p "2. Enter hostname for the server: " HOSTNAME
|
||||||
read -s -p "3. Enter desired password: " PASSWORD
|
|
||||||
|
# Validate hostname format
|
||||||
|
while ! [[ $HOSTNAME =~ ^[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?)*$ ]]; do
|
||||||
|
echo "❌ Invalid hostname format. Please use a valid hostname (e.g., my-server.example.com)"
|
||||||
|
read -p "Enter hostname for the server: " HOSTNAME
|
||||||
|
done
|
||||||
|
|
||||||
|
read -p "3. Enter desired username for server access: " USERNAME
|
||||||
|
read -s -p "4. Enter desired password: " PASSWORD
|
||||||
echo
|
echo
|
||||||
echo "4. Enter domain names for services (must point to $SERVER_IP):"
|
echo "5. Enter domain names for services (must point to $IP_ADDRESS):"
|
||||||
read -p " - Domain for Portainer: " PORTAINER_DOMAIN
|
read -p " - Domain for Portainer: " PORTAINER_DOMAIN
|
||||||
read -p " - Domain for n8n: " N8N_DOMAIN
|
read -p " - Domain for n8n: " N8N_DOMAIN
|
||||||
read -p " - Domain for Baserow: " BASEROW_DOMAIN
|
read -p " - Domain for Baserow: " BASEROW_DOMAIN
|
||||||
echo
|
echo
|
||||||
echo "5. How do you authentiate to the target machine?"
|
echo "6. How do you authenticate to the target machine?"
|
||||||
echo "-------------------------------------------"
|
echo "-------------------------------------------"
|
||||||
echo " 1) Password"
|
echo " 1) Password"
|
||||||
echo " 2) SSH Key"
|
echo " 2) SSH Key"
|
||||||
@@ -173,10 +332,10 @@ read -p "Enter your choice (1-2): " KEY_CHOICE
|
|||||||
|
|
||||||
case $KEY_CHOICE in
|
case $KEY_CHOICE in
|
||||||
1)
|
1)
|
||||||
INSTALL_COMMAND="nix run github:nix-community/nixos-anywhere -- --flake .#server root@$SERVER_IP"
|
INSTALL_COMMAND="nix run github:nix-community/nixos-anywhere -- --flake .#$HOSTNAME root@$IP_ADDRESS"
|
||||||
;;
|
;;
|
||||||
2)
|
2)
|
||||||
INSTALL_COMMAND="nix run github:nix-community/nixos-anywhere -- --flake .#server -i $SSH_KEY_PATH root@$SERVER_IP"
|
INSTALL_COMMAND="nix run github:nix-community/nixos-anywhere -- --flake .#$HOSTNAME -i $SSH_KEY_PATH root@$IP_ADDRESS"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "❌ Invalid choice"
|
echo "❌ Invalid choice"
|
||||||
@@ -187,7 +346,7 @@ esac
|
|||||||
setup_from_template
|
setup_from_template
|
||||||
|
|
||||||
echo
|
echo
|
||||||
echo "6. Select your cloud provider:"
|
echo "7. Select your cloud provider:"
|
||||||
echo " 1) AWS (Newer instances with NVMe)"
|
echo " 1) AWS (Newer instances with NVMe)"
|
||||||
echo " 2) AWS (Older instances)"
|
echo " 2) AWS (Older instances)"
|
||||||
echo " 3) Google Cloud Platform"
|
echo " 3) Google Cloud Platform"
|
||||||
@@ -264,7 +423,9 @@ cat > config.json << EOF
|
|||||||
"n8n": "$N8N_DOMAIN",
|
"n8n": "$N8N_DOMAIN",
|
||||||
"baserow": "$BASEROW_DOMAIN"
|
"baserow": "$BASEROW_DOMAIN"
|
||||||
},
|
},
|
||||||
"rootDevice": "$DEVICE_NAME"
|
"rootDevice": "$DEVICE_NAME",
|
||||||
|
"ipAddress": "$IP_ADDRESS",
|
||||||
|
"hostname": "$HOSTNAME"
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
@@ -292,6 +453,8 @@ echo "This process might take several minutes..."
|
|||||||
|
|
||||||
# Run nixos-anywhere installation
|
# Run nixos-anywhere installation
|
||||||
$INSTALL_COMMAND && {
|
$INSTALL_COMMAND && {
|
||||||
|
echo "🔧 Setting up SSH configuration..."
|
||||||
|
setup_ssh_config "$USERNAME" "$IP_ADDRESS" "$HOSTNAME"
|
||||||
echo
|
echo
|
||||||
echo "🎉 Installation completed successfully!"
|
echo "🎉 Installation completed successfully!"
|
||||||
echo "=====================================>"
|
echo "=====================================>"
|
||||||
@@ -301,7 +464,9 @@ $INSTALL_COMMAND && {
|
|||||||
echo "- Baserow: https://$BASEROW_DOMAIN"
|
echo "- Baserow: https://$BASEROW_DOMAIN"
|
||||||
echo
|
echo
|
||||||
echo "To connect to your server, use:"
|
echo "To connect to your server, use:"
|
||||||
echo "ssh -i $SSH_KEY_PATH -p 2222 $USERNAME@$SERVER_IP"
|
echo "ssh $HOSTNAME"
|
||||||
|
echo
|
||||||
|
install_deploy_rs
|
||||||
echo
|
echo
|
||||||
echo "⚠️ Important: Please save your SSH key path: $SSH_KEY_PATH"
|
echo "⚠️ Important: Please save your SSH key path: $SSH_KEY_PATH"
|
||||||
echo "=====================================>"
|
echo "=====================================>"
|
88
starter/flake.lock
generated
88
starter/flake.lock
generated
@@ -1,88 +0,0 @@
|
|||||||
{
|
|
||||||
"nodes": {
|
|
||||||
"base-config": {
|
|
||||||
"inputs": {
|
|
||||||
"nixpkgs": "nixpkgs",
|
|
||||||
"nixpkgs-unstable": "nixpkgs-unstable"
|
|
||||||
},
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1741872348,
|
|
||||||
"narHash": "sha256-4d0S59c/rR5lcfqeqw3z+k4FlDwyci6dwrwMPgKuO/g=",
|
|
||||||
"ref": "stable",
|
|
||||||
"rev": "50af8d01fb5d5d5616bd1d5c38ced9946f863ca4",
|
|
||||||
"revCount": 6,
|
|
||||||
"type": "git",
|
|
||||||
"url": "https://code.m3tam3re.com/m3tam3re/self-host-playbook-base"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"ref": "stable",
|
|
||||||
"type": "git",
|
|
||||||
"url": "https://code.m3tam3re.com/m3tam3re/self-host-playbook-base"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"disko": {
|
|
||||||
"inputs": {
|
|
||||||
"nixpkgs": [
|
|
||||||
"nixpkgs"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1741786315,
|
|
||||||
"narHash": "sha256-VT65AE2syHVj6v/DGB496bqBnu1PXrrzwlw07/Zpllc=",
|
|
||||||
"owner": "nix-community",
|
|
||||||
"repo": "disko",
|
|
||||||
"rev": "0d8c6ad4a43906d14abd5c60e0ffe7b587b213de",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "nix-community",
|
|
||||||
"repo": "disko",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"nixpkgs": {
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1741600792,
|
|
||||||
"narHash": "sha256-yfDy6chHcM7pXpMF4wycuuV+ILSTG486Z/vLx/Bdi6Y=",
|
|
||||||
"owner": "NixOS",
|
|
||||||
"repo": "nixpkgs",
|
|
||||||
"rev": "ebe2788eafd539477f83775ef93c3c7e244421d3",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "NixOS",
|
|
||||||
"ref": "nixos-24.11",
|
|
||||||
"repo": "nixpkgs",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"nixpkgs-unstable": {
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1741708242,
|
|
||||||
"narHash": "sha256-cNRqdQD4sZpN7JLqxVOze4+WsWTmv2DGH0wNCOVwrWc=",
|
|
||||||
"owner": "NixOS",
|
|
||||||
"repo": "nixpkgs",
|
|
||||||
"rev": "b62d2a95c72fb068aecd374a7262b37ed92df82b",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "NixOS",
|
|
||||||
"repo": "nixpkgs",
|
|
||||||
"rev": "b62d2a95c72fb068aecd374a7262b37ed92df82b",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"root": {
|
|
||||||
"inputs": {
|
|
||||||
"base-config": "base-config",
|
|
||||||
"disko": "disko",
|
|
||||||
"nixpkgs": [
|
|
||||||
"base-config",
|
|
||||||
"nixpkgs"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"root": "root",
|
|
||||||
"version": 7
|
|
||||||
}
|
|
@@ -1,40 +0,0 @@
|
|||||||
{
|
|
||||||
description = "Self-hosted server setup with Portainer, n8n, and Baserow";
|
|
||||||
|
|
||||||
inputs = {
|
|
||||||
base-config = {
|
|
||||||
# url = "path:/home/m3tam3re/p/nix/self-host-playbook-base";
|
|
||||||
url = "git+https://code.m3tam3re.com/m3tam3re/self-host-playbook-base?ref=stable";
|
|
||||||
};
|
|
||||||
nixpkgs = {
|
|
||||||
url = "github:NixOS/nixpkgs/nixos-24.11";
|
|
||||||
follows = "base-config/nixpkgs";
|
|
||||||
};
|
|
||||||
disko = {
|
|
||||||
url = "github:nix-community/disko";
|
|
||||||
inputs.nixpkgs.follows = "nixpkgs";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
outputs = {
|
|
||||||
self,
|
|
||||||
base-config,
|
|
||||||
nixpkgs,
|
|
||||||
...
|
|
||||||
} @ inputs: {
|
|
||||||
nixosConfigurations.nixos = nixpkgs.lib.nixosSystem {
|
|
||||||
system = "x86_64-linux";
|
|
||||||
modules = [
|
|
||||||
(base-config.nixosModules.default {
|
|
||||||
tier = "starter";
|
|
||||||
jsonConfig = builtins.fromJSON (builtins.readFile ./config.json);
|
|
||||||
}) # Pass tier here
|
|
||||||
inputs.disko.nixosModules.disko
|
|
||||||
./configuration.nix
|
|
||||||
];
|
|
||||||
specialArgs = {
|
|
||||||
inherit self;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
@@ -1,8 +0,0 @@
|
|||||||
{
|
|
||||||
"version": "0.1.0",
|
|
||||||
"minCompatibleVersion": "0.0.0",
|
|
||||||
"updateUrl": "https://code.m3tam3re.com/m3tam3re/self-host-playbook",
|
|
||||||
"changelog": {
|
|
||||||
"0.1.0": ["Management CLI", "Flake rework"]
|
|
||||||
}
|
|
||||||
}
|
|
305
update.sh
Normal file
305
update.sh
Normal file
@@ -0,0 +1,305 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
# Ensure we're in a flakes-enabled environment with required tools
|
||||||
|
if ! command -v nix &> /dev/null; then
|
||||||
|
echo "❌ Nix is not installed. Please install Nix first:"
|
||||||
|
echo "curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if we need to enter a new shell
|
||||||
|
if [ -z "${INSIDE_NIX_SHELL+x}" ]; then
|
||||||
|
export NIX_CONFIG="experimental-features = nix-command flakes"
|
||||||
|
export INSIDE_NIX_SHELL=1
|
||||||
|
exec nix shell nixpkgs#git nixpkgs#jq --command bash "$0"
|
||||||
|
fi
|
||||||
|
|
||||||
|
get_current_version() {
|
||||||
|
local version_file=$1
|
||||||
|
if [ -f "$version_file" ]; then
|
||||||
|
jq -r '.version' "$version_file"
|
||||||
|
else
|
||||||
|
echo "0.0.0"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
get_latest_version() {
|
||||||
|
local latest_version
|
||||||
|
|
||||||
|
latest_version=$(curl -s "https://code.m3ta.dev/api/v1/repos/m3tam3re/self-host-playbook/tags" | jq -r '.[] | select(.name | startswith("v")) | .name' | sort -V | tail -n1)
|
||||||
|
|
||||||
|
if [ -z "$latest_version" ]; then
|
||||||
|
echo "❌ Error: Could not fetch latest version from repository"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Remove 'v' prefix if present and return
|
||||||
|
echo "${latest_version#v}"
|
||||||
|
}
|
||||||
|
|
||||||
|
check_compatibility() {
|
||||||
|
local current_version=$1
|
||||||
|
local target_version=$2
|
||||||
|
local version_file=$3
|
||||||
|
|
||||||
|
# Special case for initial install
|
||||||
|
if [ "$current_version" = "0.0.0" ]; then
|
||||||
|
echo "ℹ️ First time upgrade detected - proceeding with upgrade"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
local min_compatible_version
|
||||||
|
min_compatible_version=$(curl -s "https://code.m3ta.dev/m3tam3re/self-host-playbook/raw/branch/develop/v${target_version}/$version_file" | jq -r '.minCompatibleVersion')
|
||||||
|
|
||||||
|
if version_lt "$current_version" "$min_compatible_version"; then
|
||||||
|
echo "❌ Your current version ($current_version) is too old for direct upgrade."
|
||||||
|
echo "Please upgrade to version $min_compatible_version first."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
# Show changelog - modified to use version file parameter
|
||||||
|
show_changelog() {
|
||||||
|
local current_version=$1
|
||||||
|
local target_version=$2
|
||||||
|
local version_file=$3
|
||||||
|
|
||||||
|
echo "📋 Changelog from $current_version to $target_version:"
|
||||||
|
echo "------------------------------------------------"
|
||||||
|
|
||||||
|
local changelog
|
||||||
|
changelog=$(curl -s "https://code.m3ta.dev/m3tam3re/self-host-playbook/raw/branch/develop/v${target_version}/$version_file" | jq -r '.changelog')
|
||||||
|
|
||||||
|
# Process each version once, then all its changes
|
||||||
|
echo "$changelog" | jq -r --arg cv "$current_version" --arg tv "$target_version" '
|
||||||
|
to_entries[]
|
||||||
|
| select(.key > $cv and .key <= $tv)
|
||||||
|
| "\(.key):\n" + (.value | map(" - " + .) | join("\n"))
|
||||||
|
' 2>/dev/null
|
||||||
|
|
||||||
|
echo "------------------------------------------------"
|
||||||
|
}
|
||||||
|
|
||||||
|
perform_update() {
|
||||||
|
local target_version=$1
|
||||||
|
local backup_dir=$2
|
||||||
|
|
||||||
|
# Verify essential files exist before proceeding
|
||||||
|
if [ ! -f "config.json" ] || [ ! -d "env" ]; then
|
||||||
|
echo "❌ Error: Essential files missing. Are you in the correct directory?"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "⬇️ Downloading version $target_version..."
|
||||||
|
|
||||||
|
TEMP_DIR=$(mktemp -d)
|
||||||
|
trap 'rm -rf "$TEMP_DIR"' EXIT
|
||||||
|
|
||||||
|
# Create a subdirectory for the clone
|
||||||
|
CLONE_DIR="${TEMP_DIR}/clone"
|
||||||
|
mkdir -p "$CLONE_DIR"
|
||||||
|
|
||||||
|
# Clone to temporary directory with --quiet flag
|
||||||
|
if ! nix flake clone --quiet "git+https://code.m3ta.dev/m3tam3re/self-host-playbook?ref=v${target_version}" --dest "$CLONE_DIR" 2>/dev/null; then
|
||||||
|
echo "❌ Failed to clone repository"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Verify downloaded content
|
||||||
|
if [ ! -f "$CLONE_DIR/flake.nix" ]; then
|
||||||
|
echo "❌ Error: Downloaded content appears invalid"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Remove current directory contents except backup
|
||||||
|
echo "🗑️ Cleaning current directory..."
|
||||||
|
find . -maxdepth 1 ! -name "." ! -name ".." ! -name "$backup_dir" -exec rm -rf {} +
|
||||||
|
|
||||||
|
# Copy new version from clone
|
||||||
|
echo "📋 Installing new version..."
|
||||||
|
cp -r "$CLONE_DIR"/* .
|
||||||
|
|
||||||
|
# Verify essential files were copied
|
||||||
|
if [ ! -f "flake.nix" ]; then
|
||||||
|
echo "❌ Error: Failed to copy new version files"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Restore configuration files from backup with validation
|
||||||
|
echo "🔄 Restoring configuration files..."
|
||||||
|
if [ -f "${backup_dir}/config.json" ]; then
|
||||||
|
cp -r "${backup_dir}/config.json" . || {
|
||||||
|
echo "❌ Error: Failed to restore config.json"
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -d "${backup_dir}/env" ]; then
|
||||||
|
cp -r "${backup_dir}/env" . || {
|
||||||
|
echo "❌ Error: Failed to restore env directory"
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
fi
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
setup_ssh_config() {
|
||||||
|
local username=$1
|
||||||
|
local ip_address=$2
|
||||||
|
local hostname=$3
|
||||||
|
local ssh_config_dir="$HOME/.ssh"
|
||||||
|
local ssh_config_file="$ssh_config_dir/config"
|
||||||
|
local ssh_key_file="$ssh_config_dir/self-host-playbook"
|
||||||
|
|
||||||
|
mkdir -p "$ssh_config_dir"
|
||||||
|
chmod 700 "$ssh_config_dir"
|
||||||
|
|
||||||
|
local config_entry="Host $hostname
|
||||||
|
HostName $ip_address
|
||||||
|
User $username
|
||||||
|
Port 2222
|
||||||
|
IdentityFile $ssh_key_file"
|
||||||
|
|
||||||
|
if ! grep -q "Host $hostname" "$ssh_config_file" 2>/dev/null; then
|
||||||
|
echo -e "\n$config_entry" >> "$ssh_config_file"
|
||||||
|
echo "✅ Added SSH config entry"
|
||||||
|
else
|
||||||
|
sed -i.bak "/Host $hostname/,/IdentityFile.*/{
|
||||||
|
s/HostName.*/HostName $ip_address/
|
||||||
|
s/User.*/User $username/
|
||||||
|
}" "$ssh_config_file"
|
||||||
|
echo "✅ Updated existing SSH config entry"
|
||||||
|
fi
|
||||||
|
|
||||||
|
chmod 600 "$ssh_config_file"
|
||||||
|
}
|
||||||
|
|
||||||
|
update_config_value() {
|
||||||
|
local key=$1
|
||||||
|
local value=$2
|
||||||
|
local config_file="config.json"
|
||||||
|
|
||||||
|
local config
|
||||||
|
config=$(cat "$config_file")
|
||||||
|
|
||||||
|
if jq -e ".$key" "$config_file" >/dev/null 2>&1; then
|
||||||
|
config=$(echo "$config" | jq --arg key "$key" --arg value "$value" '.[$key] = $value')
|
||||||
|
else
|
||||||
|
config=$(echo "$config" | jq --arg key "$key" --arg value "$value" '. + {($key): $value}')
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "$config" | jq '.' > "$config_file"
|
||||||
|
echo "✅ Updated $key in config.json"
|
||||||
|
}
|
||||||
|
|
||||||
|
install_deploy_rs() {
|
||||||
|
echo "🔧 Installing deploy-rs to user environment..."
|
||||||
|
|
||||||
|
if command -v deploy >/dev/null 2>&1; then
|
||||||
|
echo "ℹ️ deploy-rs is already installed"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if nix profile install 'github:serokell/deploy-rs'; then
|
||||||
|
echo "✅ deploy-rs installed successfully"
|
||||||
|
else
|
||||||
|
echo "❌ Failed to install deploy-rs"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Main script
|
||||||
|
echo "🔄 Self-Host Playbook Update Assistant"
|
||||||
|
echo "======================================"
|
||||||
|
|
||||||
|
if [ ! -f "config.json" ]; then
|
||||||
|
echo "❌ Error: config.json not found. Please run this script in your self-host-playbook directory."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
USERNAME=$(jq -r '.username' config.json)
|
||||||
|
IP_ADDRESS=$(jq -r '.ipAddress // empty' config.json)
|
||||||
|
HOSTNAME=$(jq -r '.hostname // empty' config.json)
|
||||||
|
|
||||||
|
if [ -z "$USERNAME" ]; then
|
||||||
|
echo "❌ Error: Could not read username from config.json"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$IP_ADDRESS" ]; then
|
||||||
|
echo "ℹ️ No IP address found in config.json"
|
||||||
|
read -p "Enter the IP address of your server: " IP_ADDRESS
|
||||||
|
|
||||||
|
if ! [[ $IP_ADDRESS =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
|
||||||
|
echo "❌ Error: Invalid IP address format"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
update_config_value "ipAddress" "$IP_ADDRESS"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$HOSTNAME" ]; then
|
||||||
|
echo "ℹ️ No hostname found in config.json"
|
||||||
|
read -p "Enter the hostname for your server: " HOSTNAME
|
||||||
|
|
||||||
|
if ! [[ $HOSTNAME =~ ^[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?)*$ ]]; then
|
||||||
|
echo "❌ Error: Invalid hostname format"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
update_config_value "hostname" "$HOSTNAME"
|
||||||
|
fi
|
||||||
|
|
||||||
|
VERSION_FILE="version.json"
|
||||||
|
CURRENT_VERSION=$(get_current_version "$VERSION_FILE")
|
||||||
|
LATEST_VERSION=$(get_latest_version)
|
||||||
|
|
||||||
|
echo "Current version: $CURRENT_VERSION"
|
||||||
|
echo "Latest version: $LATEST_VERSION"
|
||||||
|
echo
|
||||||
|
|
||||||
|
if [ "$CURRENT_VERSION" = "$LATEST_VERSION" ]; then
|
||||||
|
echo "✅ You are already on the latest version!"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! check_compatibility "$CURRENT_VERSION" "$LATEST_VERSION" "$VERSION_FILE"; then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
show_changelog "$CURRENT_VERSION" "$LATEST_VERSION" "$VERSION_FILE"
|
||||||
|
|
||||||
|
echo
|
||||||
|
read -p "Do you want to update to version $LATEST_VERSION? (y/N) " -n 1 -r
|
||||||
|
echo
|
||||||
|
|
||||||
|
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||||
|
backup_dir="backup_${CURRENT_VERSION}_$(date +%Y%m%d_%H%M%S)"
|
||||||
|
echo "📑 Creating backup in $backup_dir..."
|
||||||
|
mkdir -p "$backup_dir"
|
||||||
|
find . -maxdepth 1 ! -name "." ! -name ".." ! -name "$backup_dir" -exec cp -r {} "$backup_dir/" \;
|
||||||
|
|
||||||
|
if perform_update "$LATEST_VERSION" "$backup_dir"; then
|
||||||
|
echo
|
||||||
|
echo "✅ Update completed successfully!"
|
||||||
|
echo
|
||||||
|
echo "🔧 Setting up SSH configuration..."
|
||||||
|
setup_ssh_config "$USERNAME" "$IP_ADDRESS" "$HOSTNAME"
|
||||||
|
echo
|
||||||
|
install_deploy_rs
|
||||||
|
echo "🚀 Applying the update to your system..."
|
||||||
|
deploy .#$HOSTNAME
|
||||||
|
echo
|
||||||
|
echo "If you encounter any issues, your backup is available in $backup_dir"
|
||||||
|
else
|
||||||
|
echo "❌ Update failed. Your backup is available in $backup_dir"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "Update cancelled."
|
||||||
|
exit 1
|
||||||
|
fi
|
14
version.json
Normal file
14
version.json
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"version": "0.1.0",
|
||||||
|
"minCompatibleVersion": "0.0.0",
|
||||||
|
"updateUrl": "https://code.m3ta.dev/m3tam3re/self-host-playbook",
|
||||||
|
"changelog": {
|
||||||
|
"0.1.0": [
|
||||||
|
"Added a management CLI for easily adding custom services.",
|
||||||
|
"Automated server updates / security patches daily.",
|
||||||
|
"Structural rework for easier upgrades.",
|
||||||
|
"Install Script Optimizations",
|
||||||
|
"Update Script"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user