summaryrefslogtreecommitdiff
path: root/reorderips.sh
blob: 6567d95c50d6ce476f0048935d20e60f8255b180 (plain)
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
#!/usr/bin/env bash

echo "Reassigning container IPs in increments of 10..."

# Container name to IP mapping
declare -A CONTAINERS=(
  [archivecontrol]="10.196.1.10"
  [archivelist]="10.196.1.20"
  [ftp]="10.196.1.30"
  [hostingtoot]="10.196.1.40"
  [humptydumpty]="10.196.1.50"
  [teamtalk]="10.196.1.60"
  [akkoma]="10.196.1.70"
)

# Ordered list to process in sequence
ORDER=(archivecontrol archivelist ftp hostingtoot humptydumpty teamtalk akkoma)

for container in "${ORDER[@]}"; do
  new_ip="${CONTAINERS[$container]}"

  # Check current IP assignment
  current_ip=$(lxc config device get "$container" eth0 ipv4.address 2>/dev/null)

  if [[ "$current_ip" == "$new_ip" ]]; then
    # No change needed
    continue
  fi

  echo "Updating $container: assigning IP $new_ip (was: ${current_ip:-unset})"

  # Override NIC to allow per-container IP (silently if already done)
  lxc config device override "$container" eth0 >/dev/null 2>&1

  # Clear any existing IP config
  lxc config device unset "$container" eth0 ipv4.address >/dev/null 2>&1

  # Set the new IP
  lxc config device set "$container" eth0 ipv4.address "$new_ip"
done

echo "Restarting updated containers..."
for container in "${ORDER[@]}"; do
  new_ip="${CONTAINERS[$container]}"
  current_ip=$(lxc config device get "$container" eth0 ipv4.address 2>/dev/null)
  if [[ "$current_ip" == "$new_ip" ]]; then
    echo "Restarting $container (new IP: $new_ip)"
    lxc restart "$container" >/dev/null
  fi
done

echo "IP assignment complete! Here’s the final layout:"
lxc list