From a741cde852fabc70f7d29c70da6cd84d938f964c Mon Sep 17 00:00:00 2001 From: Date: Mon, 6 Nov 2017 16:48:24 -0500 Subject: [PATCH] deploy script almost done! :D --- arch_setup.sh | 5 +++-- deploy.sh | 38 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/arch_setup.sh b/arch_setup.sh index d6f9364..a451c69 100644 --- a/arch_setup.sh +++ b/arch_setup.sh @@ -18,7 +18,7 @@ pacman-key --populate archlinux # with USA and worldwide mirrors but eh. echo "----> Setting up mirror list" mv /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.backup -cat > /etc/pacman.d/mirrorlist <<-`EOM05594313219813` +cat <<- 'EOM05594313219813' > /etc/pacman.d/mirrorlist # Server list generated by rankmirrors on 2017-11-03 ## ## Arch Linux repository mirrorlist @@ -32,7 +32,8 @@ cat > /etc/pacman.d/mirrorlist <<-`EOM05594313219813` Server = http://mirrors.evowise.com/archlinux/$repo/os/$arch Server = http://mirrors.advancedhosters.com/archlinux/$repo/os/$arch Server = http://mirror.math.princeton.edu/pub/archlinux/$repo/os/$arch -`EOM05594313219813` +EOM05594313219813 +cat /etc/pacman.d/mirrorlist # Do an update and install some packages. echo "----> Updating and installing base-devel, git, htop, vim, and cowsay" diff --git a/deploy.sh b/deploy.sh index cd75086..9433e4e 100644 --- a/deploy.sh +++ b/deploy.sh @@ -57,8 +57,42 @@ if [[ $1 == "-ID" ]]; then fi fi +# Make sure SSH public key is in proxmox host. This overwrites if it exists. +scp $HOME/.ssh/id_rsa.pub root@$PROXMOX_IP_ADDR:/tmp/id_rsa.pub > /dev/null + # 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" +VMID=$(ssh root@$PROXMOX_IP_ADDR /usr/bin/env bash <<-'AcRP030CAlfad6' + # use the highest VMID+1 as our new VMID. This returns 1 if no VMID's exist. + VMID=$(pct list | awk 'NR > 1 {print $1}' | sort -nr | head -n1) + VMID=$(($VMID + 1)) + + # VMID's less than 100 are for internal proxmox use, make sure we are >= 100. + # This also could mean there were no proxmox boxes created. + if [[ $VMID -lt 100 ]]; then + VMID=100 + fi + + # Create a new container with the VMID + pct create $VMID /var/lib/vz/template/cache/archlinux-base_20170704-1_amd64.tar.gz -ssh-public-keys /tmp/id_rsa.pub -storage local-zfs -net0 name=eth0,bridge=vmbr0,ip=dhcp,ip6=dhcp -ostype archlinux > /dev/null + + # Start the container. + pct start $VMID > /dev/null + + # And say all went well. + echo "$VMID" AcRP030CAlfad6 +) +echo "Completed Container Init, ID: $VMID" + +# Send our default arch init script over to proxmox host. This overwrites any old file. +scp arch_setup.sh root@$PROXMOX_IP_ADDR:/tmp/arch_setup.sh > /dev/null + +# Copy the script into the container and run it. +ssh root@$PROXMOX_IP_ADDR /usr/bin/env bash <<- AcRP030CAlfad6 + pct push $VMID /tmp/arch_setup.sh /tmp/arch_setup.sh > /dev/null + pct exec $VMID chmod +x /tmp/arch_setup.sh + pct exec $VMID /tmp/arch_setup.sh +AcRP030CAlfad6 + +echo "Deploy.sh Complete!"