mirror of
https://github.com/hak8or/proxmox_scripts.git
synced 2025-01-15 11:57:57 +00:00
Pretty much working scripts!
This commit is contained in:
parent
a741cde852
commit
0bec6c2f3a
@ -1,23 +1,42 @@
|
|||||||
#!/usr/bin/env bash
|
#!/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.
|
# For making the script stop if something fails like make.
|
||||||
set -e
|
set -e
|
||||||
set -o pipefail
|
set -o pipefail
|
||||||
|
|
||||||
# Enable and start sshd so we can ssh in here in the future.
|
# Enable and start sshd so we can ssh in here in the future.
|
||||||
echo "----> Enabling SSH"
|
echo "$TAGSTR Enabling SSH"
|
||||||
systemctl enable sshd
|
systemctl enable sshd > $LOGFILE 2>&1
|
||||||
systemctl start sshd
|
systemctl start sshd > $LOGFILE 2>&1
|
||||||
|
|
||||||
# Setup keys for pacman
|
# Setup keys for pacman
|
||||||
echo "----> Setting up keys for pacman"
|
echo "$TAGSTR Setting up keys for pacman"
|
||||||
pacman-key --init
|
pacman-key --init > $LOGFILE 2>&1
|
||||||
pacman-key --populate archlinux
|
pacman-key --populate archlinux > $LOGFILE 2>&1
|
||||||
|
|
||||||
# Setup mirrors, hardcoded for now. Could have been done with rankmirror
|
# Setup mirrors, hardcoded for now. Could have been done with rankmirror
|
||||||
# with USA and worldwide mirrors but eh.
|
# with USA and worldwide mirrors but eh.
|
||||||
echo "----> Setting up mirror list"
|
echo "$TAGSTR Setting up mirror list"
|
||||||
mv /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.backup
|
mv /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.backup > $LOGFILE 2>&1
|
||||||
cat <<- 'EOM05594313219813' > /etc/pacman.d/mirrorlist
|
cat <<- 'EOM05594313219813' > /etc/pacman.d/mirrorlist
|
||||||
# Server list generated by rankmirrors on 2017-11-03
|
# 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://mirrors.advancedhosters.com/archlinux/$repo/os/$arch
|
||||||
Server = http://mirror.math.princeton.edu/pub/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.
|
# Do an update and install some packages.
|
||||||
echo "----> Updating and installing base-devel, git, htop, vim, and cowsay"
|
echo "$TAGSTR Updating and installing base-devel, git, htop, vim, and cowsay"
|
||||||
pacman -Syu base-devel git htop vim cowsay --noconfirm
|
pacman -Syu base-devel git htop vim cowsay --noconfirm > $LOGFILE 2>&1
|
||||||
|
|
||||||
# Disable root check for makepkg since we are using root for everything.
|
# 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
|
# Replace the "if (( EUID == 0 )); then" with "if (( 0 )); then" to force root
|
||||||
# check to always fail.
|
# 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
|
# 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,
|
# 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
|
# and I don't want to bother fiddling with users just for this. Yaourt on the
|
||||||
# other hand works fine for this.
|
# other hand works fine for this.
|
||||||
echo "----> Installing package-query and yaourt"
|
echo "$TAGSTR Installing package-query and yaourt"
|
||||||
mkdir ~/tmp
|
mkdir ~/tmp
|
||||||
cd ~/tmp
|
cd ~/tmp
|
||||||
# ----------- package query for yaourt -----------
|
# ----------- 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
|
cd package-query
|
||||||
makepkg -si --noconfirm
|
makepkg -si --noconfirm > $LOGFILE 2>&1
|
||||||
cd ..
|
cd ..
|
||||||
# ----------- yaourt itself -----------
|
# ----------- yaourt itself -----------
|
||||||
git clone https://aur.archlinux.org/yaourt.git
|
git clone https://aur.archlinux.org/yaourt.git > $LOGFILE 2>&1
|
||||||
cd yaourt
|
cd yaourt
|
||||||
makepkg -si --noconfirm
|
makepkg -si --noconfirm > $LOGFILE 2>&1
|
||||||
cd ..
|
cd ..
|
||||||
# Wipe tmp dir
|
# Wipe tmp dir
|
||||||
cd ..
|
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]}')
|
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]}')
|
||||||
|
|
||||||
# And say what the IP address is to the terminal.
|
# Lastly, say we are done.
|
||||||
cowsay "All Done! $ipv4addr $ipv6addr"
|
echo "$TAGSTR Completed $TITLE"
|
||||||
|
88
deploy.sh
88
deploy.sh
@ -4,39 +4,61 @@
|
|||||||
# Deploy script used for initilizing an Arch based container on Proxmox
|
# Deploy script used for initilizing an Arch based container on Proxmox
|
||||||
##########################
|
##########################
|
||||||
|
|
||||||
# Retrieve the IP address of a container as IPv4,IPv6
|
# Header for this script
|
||||||
FN_get_IPaddr (){
|
TITLE="Deployment_Script"
|
||||||
# IPv6 address fetch
|
DEPTH=0
|
||||||
local IPv6ADDR=$(ssh root@$PROXMOX_IP_ADDR $"pct exec 101 ip addr show eth0 | grep /128 | grep -v fd75")
|
if [[ $DEPTH == 0 ]]; then
|
||||||
IPv6ADDR=$(echo $IPv6ADDR | awk '{a=$2; split(a, b, "/"); print b[1]}')
|
TAGSTR="-->"
|
||||||
|
elif [[ $DEPTH == 1 ]]; then
|
||||||
# IPv4 address fetch
|
TAGSTR="--->"
|
||||||
local IPv4ADDR=$(ssh root@$PROXMOX_IP_ADDR $"pct exec 101 ip addr show eth0 | grep inet")
|
elif [[ $DEPTH == 2 ]]; then
|
||||||
IPv4ADDR=$(echo $IPv4ADDR | awk '{a=$2; split(a, b, "/"); print b[1]}')
|
TAGSTR="----->"
|
||||||
|
elif [[ $DEPTH == 3 ]]; then
|
||||||
# And return the address
|
TAGSTR="------>"
|
||||||
printf "%s,%s\n" $IPv4ADDR $IPv6ADDR
|
fi
|
||||||
}
|
echo "====== $TITLE ======"
|
||||||
|
|
||||||
# IP address of the Proxmox host
|
# IP address of the Proxmox host
|
||||||
PROXMOX_IP_ADDR=192.168.1.224
|
PROXMOX_IP_ADDR=192.168.1.224
|
||||||
if [[ -z $PROXMOX_IP_ADDR ]]; then
|
if [[ -z $PROXMOX_IP_ADDR ]]; then
|
||||||
echo "PROXMOX_IP_ADDR was not set!"
|
echo "$TAGSTR PROXMOX_IP_ADDR was not set!"
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Verify we can talk to the proxmox host.
|
# Verify we can talk to the proxmox host.
|
||||||
REPLYFROMSERVER=$(ssh root@$PROXMOX_IP_ADDR $"echo "Hello World"")
|
REPLYFROMSERVER=$(ssh root@$PROXMOX_IP_ADDR $"echo "Hello World"")
|
||||||
if [[ $REPLYFROMSERVER != "Hello World" ]]; then
|
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
|
exit
|
||||||
fi
|
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.
|
# Check if we are referring to a specific container.
|
||||||
if [[ $1 == "-ID" ]]; then
|
if [[ $1 == "-ID" ]]; then
|
||||||
# Make sure we have a container ID
|
# Make sure we have a container ID
|
||||||
if [[ -z $2 ]]; then
|
if [[ -z $2 ]]; then
|
||||||
echo "No container ID was given!"
|
echo "$TAGSTR No container ID was given!"
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -48,10 +70,13 @@ if [[ $1 == "-ID" ]]; then
|
|||||||
else
|
else
|
||||||
# A script was found, verify it exists.
|
# A script was found, verify it exists.
|
||||||
if [[ -e $3 ]]; then
|
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
|
exit
|
||||||
else
|
else
|
||||||
echo "Bash script $3 was not found."
|
echo "$TAGSTR Bash script $3 was not found."
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
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.
|
# No specific container was provided, so we create one.
|
||||||
# Can pass small script like this: https://stackoverflow.com/a/3872762/516959
|
# 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'
|
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.
|
# 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=$(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"
|
echo "$VMID"
|
||||||
AcRP030CAlfad6
|
AcRP030CAlfad6
|
||||||
)
|
)
|
||||||
echo "Completed Container Init, ID: $VMID"
|
|
||||||
|
|
||||||
# Send our default arch init script over to proxmox host. This overwrites any old file.
|
# Send and execute our arch init script.
|
||||||
scp arch_setup.sh root@$PROXMOX_IP_ADDR:/tmp/arch_setup.sh > /dev/null
|
FN_exec_script_container $VMID arch_setup.sh
|
||||||
|
|
||||||
# Copy the script into the container and run it.
|
# Run any potential secondary script.
|
||||||
ssh root@$PROXMOX_IP_ADDR /usr/bin/env bash <<- AcRP030CAlfad6
|
if [[ -n $1 ]]; then
|
||||||
pct push $VMID /tmp/arch_setup.sh /tmp/arch_setup.sh > /dev/null
|
# A script was found, verify it exists.
|
||||||
pct exec $VMID chmod +x /tmp/arch_setup.sh
|
if [[ -e $1 ]]; then
|
||||||
pct exec $VMID /tmp/arch_setup.sh
|
FN_exec_script_container $VMID $1
|
||||||
AcRP030CAlfad6
|
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"
|
||||||
|
27
gogs.sh
Normal file
27
gogs.sh
Normal file
@ -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"
|
Loading…
Reference in New Issue
Block a user