mirror of
https://github.com/hak8or/proxmox_scripts.git
synced 2025-01-15 11:57:57 +00:00
beginings of deploy script
This commit is contained in:
parent
1abdf8a16f
commit
1890f3fb43
@ -1,7 +1,4 @@
|
|||||||
#!/usr/bin/bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
# To run this script, do the following:
|
|
||||||
|
|
||||||
|
|
||||||
# For making the script stop if something fails like make.
|
# For making the script stop if something fails like make.
|
||||||
set -e
|
set -e
|
||||||
@ -68,6 +65,7 @@ cd ..
|
|||||||
rm -r -f ~/tmp
|
rm -r -f ~/tmp
|
||||||
|
|
||||||
# Get the ip addresses using some grep and awk magic.
|
# Get the ip addresses using some grep and awk magic.
|
||||||
|
# Magic inspired by this: https://superuser.com/questions/468727/how-to-get-the-ipv6-ip-address-of-linux-machine
|
||||||
ipv6addr=$(ip -6 addr show eth0 | grep /128 | grep -v fd75 | awk '{a=$2; split(a, b, "/"); print b[1]}')
|
ipv6addr=$(ip -6 addr show eth0 | grep /128 | grep -v fd75 | awk '{a=$2; split(a, b, "/"); print b[1]}')
|
||||||
ipv4addr=$(ip -4 addr show eth0 | grep inet | awk '{a=$2; split(a, b, "/"); print b[1]}')
|
ipv4addr=$(ip -4 addr show eth0 | grep inet | awk '{a=$2; split(a, b, "/"); print b[1]}')
|
||||||
|
|
||||||
|
64
deploy.sh
Normal file
64
deploy.sh
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
##########################
|
||||||
|
# Deploy script used for initilizing an Arch based container on Proxmox
|
||||||
|
##########################
|
||||||
|
|
||||||
|
# Retrieve the IP address of a container as IPv4,IPv6
|
||||||
|
FN_get_IPaddr (){
|
||||||
|
# IPv6 address fetch
|
||||||
|
local IPv6ADDR=$(ssh root@$PROXMOX_IP_ADDR $"pct exec 101 ip addr show eth0 | grep /128 | grep -v fd75")
|
||||||
|
IPv6ADDR=$(echo $IPv6ADDR | awk '{a=$2; split(a, b, "/"); print b[1]}')
|
||||||
|
|
||||||
|
# IPv4 address fetch
|
||||||
|
local IPv4ADDR=$(ssh root@$PROXMOX_IP_ADDR $"pct exec 101 ip addr show eth0 | grep inet")
|
||||||
|
IPv4ADDR=$(echo $IPv4ADDR | awk '{a=$2; split(a, b, "/"); print b[1]}')
|
||||||
|
|
||||||
|
# And return the address
|
||||||
|
printf "%s,%s\n" $IPv4ADDR $IPv6ADDR
|
||||||
|
}
|
||||||
|
|
||||||
|
# IP address of the Proxmox host
|
||||||
|
PROXMOX_IP_ADDR=192.168.1.224
|
||||||
|
if [[ -z $PROXMOX_IP_ADDR ]]; then
|
||||||
|
echo "PROXMOX_IP_ADDR was not set!"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Verify we can talk to the proxmox host.
|
||||||
|
REPLYFROMSERVER=$(ssh root@$PROXMOX_IP_ADDR $"echo "Hello World"")
|
||||||
|
if [[ $REPLYFROMSERVER != "Hello World" ]]; then
|
||||||
|
echo "Failed to verify SSH connectivty with proxmox host."
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if we are referring to a specific container.
|
||||||
|
if [[ $1 == "-ID" ]]; then
|
||||||
|
# Make sure we have a container ID
|
||||||
|
if [[ -z $2 ]]; then
|
||||||
|
echo "No container ID was given!"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if a script was provided.
|
||||||
|
if [[ -z $3 ]]; then
|
||||||
|
# No script found, just return the ip address.
|
||||||
|
FN_get_IPaddr $2
|
||||||
|
exit
|
||||||
|
else
|
||||||
|
# A script was found, verify it exists.
|
||||||
|
if [[ -e $3 ]]; then
|
||||||
|
ssh root@$PROXMOX_IP_ADDR 'bash -s' < $3
|
||||||
|
exit
|
||||||
|
else
|
||||||
|
echo "Bash script $3 was not found."
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# No specific container was provided, so we create one.
|
||||||
|
# Can pass small script like this: https://stackoverflow.com/a/3872762/516959
|
||||||
|
ssh root@$PROXMOX_IP_ADDR /usr/bin/env bash <<-'AcRP030CAlfad6'
|
||||||
|
echo "Hello world! :D"
|
||||||
|
AcRP030CAlfad6
|
34
readme.md
Normal file
34
readme.md
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
# Proxmox Scripts
|
||||||
|
|
||||||
|
My collections of various scripts related to proxmox. These can be used to create a new master template based on arch, re-setup my "homelab" from scratch on a new proxmox machine, and other smaller helper scripts.
|
||||||
|
|
||||||
|
## Deploy Script
|
||||||
|
|
||||||
|
A small wrapper which generates an Arch Linux based container (by default) and then runs a optional script. Also can provide the IP address of a container created using the Arch setup script.
|
||||||
|
|
||||||
|
Note you must update the ```PROXMOX_IP_ADDR``` variable at the top of the script so the script knows where to SSH to. Also, this is intentionally configured such that the proxmox login is via ssh-key only. If you need to setup the SSH keys, instructions can be found [here](https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-keys--2).
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Create a arch linux based container.
|
||||||
|
deploy.sh # Outputs a container ID when complete.
|
||||||
|
|
||||||
|
# Create an Arch Linux based container which then runs a script to init gogs.
|
||||||
|
deploy.sh gogs.sh # Outputs a container ID when complete.
|
||||||
|
|
||||||
|
# Just run a script to init gogs on an already existing container.
|
||||||
|
deploy.sh -ID 101 gogs.sh # Returns nothing.
|
||||||
|
|
||||||
|
# Get a comma seperated IPv4 and IPv6 address of a container.
|
||||||
|
deploy.sh -ID 101 # Outputs an IPv4 and IPv6 address seperated by a comma.
|
||||||
|
```
|
||||||
|
|
||||||
|
## Arch Setup Script
|
||||||
|
|
||||||
|
Proxmox includes a arch template but it doesn't have a SSH daemon running and is missing a decent number of packages I tend to need for pretty much all my projects. So here is a small script which does a decent bit of the seutp.
|
||||||
|
|
||||||
|
- Enables SSH
|
||||||
|
- Sets up keys and mirrorlist for pacman
|
||||||
|
- Installs yaourt, htop, vim, base-devel (gcc, strip, ...), and cowsay
|
||||||
|
- Displays the containers IPv4 and IPv6 addreses
|
||||||
|
|
||||||
|
The ```deploy.sh``` script calls this script by default.
|
Loading…
Reference in New Issue
Block a user