diff --git a/arch_setup.sh b/arch_setup.sh index a451c69..03e9237 100644 --- a/arch_setup.sh +++ b/arch_setup.sh @@ -1,23 +1,42 @@ #!/usr/bin/env bash +########################## +# Arch Linux initilizing script +########################## + +# Header for this script +TITLE="Arch_Setup" +LOGFILE=/tmp/$TITLE.log +DEPTH=1 +if [[ $DEPTH == 0 ]]; then + TAGSTR="-->" +elif [[ $DEPTH == 1 ]]; then + TAGSTR="--->" +elif [[ $DEPTH == 2 ]]; then + TAGSTR="----->" +elif [[ $DEPTH == 3 ]]; then + TAGSTR="------>" +fi +echo "$TAGSTR ====== $TITLE (Logged to $LOGFILE) ======" + # For making the script stop if something fails like make. set -e set -o pipefail # Enable and start sshd so we can ssh in here in the future. -echo "----> Enabling SSH" -systemctl enable sshd -systemctl start sshd +echo "$TAGSTR Enabling SSH" +systemctl enable sshd > $LOGFILE 2>&1 +systemctl start sshd > $LOGFILE 2>&1 # Setup keys for pacman -echo "----> Setting up keys for pacman" -pacman-key --init -pacman-key --populate archlinux +echo "$TAGSTR Setting up keys for pacman" +pacman-key --init > $LOGFILE 2>&1 +pacman-key --populate archlinux > $LOGFILE 2>&1 # Setup mirrors, hardcoded for now. Could have been done with rankmirror # with USA and worldwide mirrors but eh. -echo "----> Setting up mirror list" -mv /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.backup +echo "$TAGSTR Setting up mirror list" +mv /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.backup > $LOGFILE 2>&1 cat <<- 'EOM05594313219813' > /etc/pacman.d/mirrorlist # Server list generated by rankmirrors on 2017-11-03 ## @@ -33,33 +52,32 @@ cat <<- 'EOM05594313219813' > /etc/pacman.d/mirrorlist Server = http://mirrors.advancedhosters.com/archlinux/$repo/os/$arch Server = http://mirror.math.princeton.edu/pub/archlinux/$repo/os/$arch EOM05594313219813 -cat /etc/pacman.d/mirrorlist # Do an update and install some packages. -echo "----> Updating and installing base-devel, git, htop, vim, and cowsay" -pacman -Syu base-devel git htop vim cowsay --noconfirm +echo "$TAGSTR Updating and installing base-devel, git, htop, vim, and cowsay" +pacman -Syu base-devel git htop vim cowsay --noconfirm > $LOGFILE 2>&1 # Disable root check for makepkg since we are using root for everything. # Replace the "if (( EUID == 0 )); then" with "if (( 0 )); then" to force root # check to always fail. -sed -i 's/if (( EUID == 0 )); then/if (( 0 )); then/' /usr/bin/makepkg +sed -i 's/if (( EUID == 0 )); then/if (( 0 )); then/' /usr/bin/makepkg > $LOGFILE 2>&1 # Install Yaourt. Why yaourt instead of pacaur? Because pacaur doesn't allow # itself to be ran as root, even though all we have is root in the container, # and I don't want to bother fiddling with users just for this. Yaourt on the # other hand works fine for this. -echo "----> Installing package-query and yaourt" +echo "$TAGSTR Installing package-query and yaourt" mkdir ~/tmp cd ~/tmp # ----------- package query for yaourt ----------- -git clone https://aur.archlinux.org/package-query.git +git clone https://aur.archlinux.org/package-query.git > $LOGFILE 2>&1 cd package-query -makepkg -si --noconfirm +makepkg -si --noconfirm > $LOGFILE 2>&1 cd .. # ----------- yaourt itself ----------- -git clone https://aur.archlinux.org/yaourt.git +git clone https://aur.archlinux.org/yaourt.git > $LOGFILE 2>&1 cd yaourt -makepkg -si --noconfirm +makepkg -si --noconfirm > $LOGFILE 2>&1 cd .. # Wipe tmp dir cd .. @@ -70,5 +88,5 @@ rm -r -f ~/tmp 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]}') -# And say what the IP address is to the terminal. -cowsay "All Done! $ipv4addr $ipv6addr" +# Lastly, say we are done. +echo "$TAGSTR Completed $TITLE" diff --git a/deploy.sh b/deploy.sh index 9433e4e..3b0070c 100644 --- a/deploy.sh +++ b/deploy.sh @@ -4,39 +4,61 @@ # 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 -} +# Header for this script +TITLE="Deployment_Script" +DEPTH=0 +if [[ $DEPTH == 0 ]]; then + TAGSTR="-->" +elif [[ $DEPTH == 1 ]]; then + TAGSTR="--->" +elif [[ $DEPTH == 2 ]]; then + TAGSTR="----->" +elif [[ $DEPTH == 3 ]]; then + TAGSTR="------>" +fi +echo "====== $TITLE ======" # 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!" + echo "$TAGSTR 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." + echo "$TAGSTR Failed to verify SSH connectivty with proxmox host." exit fi +# Retrieve the IP address of a container as IPv4,IPv6 +FN_get_IPaddr (){ + # IPv6 address fetch + 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 + 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]}') +} + +# Run a script on the the proxmox container. Arg 1 is container ID, arg 2 is script file. +FN_exec_script_container(){ + scp $2 root@$PROXMOX_IP_ADDR:/tmp/$2 > /dev/null + + ssh root@$PROXMOX_IP_ADDR /usr/bin/env bash <<- AcRP030Cclfad6 + pct push $1 /tmp/$2 /tmp/$2 > /dev/null + pct exec $1 chmod +x /tmp/$2 + pct exec $1 /tmp/$2 +AcRP030Cclfad6 +} + # 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!" + echo "$TAGSTR No container ID was given!" exit fi @@ -48,10 +70,13 @@ if [[ $1 == "-ID" ]]; then else # A script was found, verify it exists. if [[ -e $3 ]]; then - ssh root@$PROXMOX_IP_ADDR 'bash -s' < $3 + FN_exec_script_container $2 $3 + + FN_get_IPaddr $2 + echo "$TAGSTR $IPv4ADDR, $IPv6ADDR" exit else - echo "Bash script $3 was not found." + echo "$TAGSTR Bash script $3 was not found." exit fi fi @@ -62,6 +87,7 @@ 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 +echo "$TAGSTR Creating container" 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) @@ -83,16 +109,22 @@ VMID=$(ssh root@$PROXMOX_IP_ADDR /usr/bin/env bash <<-'AcRP030CAlfad6' 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 +# Send and execute our arch init script. +FN_exec_script_container $VMID arch_setup.sh -# 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 +# Run any potential secondary script. +if [[ -n $1 ]]; then + # A script was found, verify it exists. + if [[ -e $1 ]]; then + FN_exec_script_container $VMID $1 + else + echo "$TAGSTR Bash script $1 was not found." + exit + fi +fi -echo "Deploy.sh Complete!" +# Lastly, say we are done and what the IP address is to the terminal. +echo "$TAGSTR Completed $TITLE" +FN_get_IPaddr $2 +cowsay "Arch setup all done! VMID: $VMID, IPv4: $IPv4ADDR, IPv6: $IPv6ADDR" diff --git a/gogs.sh b/gogs.sh new file mode 100644 index 0000000..a623f59 --- /dev/null +++ b/gogs.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +########################## +# Script to install Gogs, a Go based version control system. +########################## + +# Header for this script +TITLE="Gogs_Setup" +LOGFILE=/tmp/$TITLE.log +DEPTH=2 +if [[ $DEPTH == 0 ]]; then + TAGSTR="-->" +elif [[ $DEPTH == 1 ]]; then + TAGSTR="--->" +elif [[ $DEPTH == 2 ]]; then + TAGSTR="----->" +elif [[ $DEPTH == 3 ]]; then + TAGSTR="------>" +fi +echo "$TAGSTR ====== $TITLE (Logged to $LOGFILE) ======" + +# All we need to do is install gogs. Gogs configuration must be done via command line. +echo "$TAGSTR Installing Gogs" +yaourt -S gogs > $LOGFILE 2>&1 + +# Lastly, say we are done. +echo "$TAGSTR Completed $TITLE"