Skip to content

Commit

Permalink
adds generate-netplan and app-config-partitions.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
jennazwick646 committed Jun 10, 2023
1 parent 9a79d4f commit b9a62e9
Show file tree
Hide file tree
Showing 2 changed files with 225 additions and 0 deletions.
65 changes: 65 additions & 0 deletions generate-netplan-file.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/bin/bash

# Creates a new 00-installer-config.yml in /etc/netplan if one does not exist. If it does,
function generate_new_config() {
if [ ! -f /etc/netplan/00-installer-config.yml ]; then
sudo tee /etc/netplan/00-installer-config.yml >/dev/null <<EOF
network:
renderer: networkd
ethernets:
eth0:
addresses:
- 192.168.10.5/24
nameservers:
addresses: [1.1.1.1, 8.8.8.8]
routes:
- to: default
via: 192.168.1.1
version: 2
EOF
else
echo "The file /etc/netplan/00-installer-config.yml already exists."
fi
}

function if_config_exists() {
if [ -f /etc/netplan/00-installer-config.yml ]; then
cat <<EOF > ./example.00-installer-config.yml
network:
renderer: networkd
ethernets:
eth0:
addresses:
- 192.168.10.5/24
nameservers:
addresses: [1.1.1.1, 8.8.8.8]
routes:
- to: default
via: 192.168.1.1
version: 2
EOF
echo "Copy the following bash script and make sure your 00-installer-config.yml file in /etc/netplan matches this one, except for having a unique IP address. "
read -p "Hit enter when ready to open the existing file. Save when you're done and run 'sudo netplan apply'."
echo " "
sudo nano /etc/netplan/00-installer-config.yml
else
echo "The file /etc/netplan/00-installer-config.yml doesn't exist."
fi
}

function ask_installation() {
read -p "Do you want to install 00-installer-config.yml? (yes/no): " response
case "$response" in
[yY]|[yY][eE][sS])
if_config_exists
;;
[nN]|[nN][oO])
generate_new_config
;;
*)
echo "Invalid response. Please enter 'yes' or 'no'."
;;
esac
}

ask_installation
160 changes: 160 additions & 0 deletions jamanative-setup/app-config-partitions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
#!/bin/bash

# Set up dedicated volumes for the data Jama Native is going to write. Use this example to partition the logical volumes on your application server.
# Start with a 110 GB disk, or simply run all 7 steps to write to disk and exit.

# Used for counting completed steps; quits the function if all 7 steps are run in one run-through. Otherwise whits on Ctrl-C or q.

functions_array=()

function CreateMountpoints() {
read -p "Create mountpoints? (Ctrl-c to cancel) "
sudo mkdir /data
sudo mkdir /logs
sudo mkdir /var/lib/docker || echo "Failed to create docker folder, you may need to uninstall Docker. "
sudo mkdir /var/lib/replicated
if [[ ! " ${functions_array[@]} " =~ "CreateMountpoints" ]]; then
functions_array+=("CreateMountpoints")
fi
}

# Create a physical volume:
function CreatePhysicalVolume() {
echo " "
read -p "Create physical volume? (Ctrl-c to cancel) "
pvcreate /dev/sdb
if [[ ! " ${functions_array[@]} " =~ "CreatePhysicalVolume" ]]; then
functions_array+=("CreatePhysicalVolume")
fi
}
# Create a volume group:

function CreateVolumeGroup() {
echo " "
read -p "Create volume group? (Ctrl-c to cancel) "
vgcreate vg_jama /dev/sdb
if [[ ! " ${functions_array[@]} " =~ "CreateVolumeGroup" ]]; then
functions_array+=("CreateVolumeGroup")
fi
}

function AddLinesToFstab() {
echo " "
read -p "Check if /etc/fstab is already modified and modify it with new partitions if not? (Ctrl-c to cancel) "
etcfstabstring="logs /logs ext4 defaults 0 0"
last_line=$(tail -n 1 "/etc/fstab")
if [[ $last_line == *"$etcfstabstring"* ]]; then
echo "Match found: $search_string, skipping."
else
echo "No match found; addling lines..."
sudo echo "LABEL=docker /var/lib/docker xfs defaults 0 0" >> /etc/fstab
sudo echo "LABEL=replicated /var/lib/replicated ext4 defaults 0 0" >> /etc/fstab
sudo echo "LABEL=data /data ext4 defaults 0 0" >> /etc/fstab
sudo echo "LABEL=logs /logs ext4 defaults 0 0" >> /etc/fstab
fi

if [[ ! " ${functions_array[@]} " =~ "AddLinesToFstab" ]]; then
functions_array+=("AddLinesToFstab")
fi
}

function MountPartitions() {
echo " "
read -p "Mount partitions? (Ctrl-c to cancel) "
mount -a
if [[ ! " ${functions_array[@]} " =~ "MountPartitions" ]]; then
functions_array+=("MountPartitions")
fi
}

# Create logical volumes:
function CreateLogicalVolumes() {
echo " "
read -p "Create logical volumes in group? (Ctrl-c to cancel) "
lvcreate -L 30G -n lv_docker vg_jama
lvcreate -L 20G -n lv_replicated vg_jama
lvcreate -L 10G -n lv_logs vg_jama
lvcreate -l 100%FREE -n lv_data vg_jama
if [[ ! " ${functions_array[@]} " =~ "CreateLogicalVolumes" ]]; then
functions_array+=("CreateLogicalVolumes")
fi
}

# Write file systems:
function WriteFileSystems() {
echo " "
read -p "Write filesystems to storage? (Ctrl-c to cancel) "
mkfs.xfs -L docker -n ftype=1 /dev/vg_jama/lv_docker
mkfs.ext4 -L replicated /dev/vg_jama/lv_replicated
mkfs.ext4 -L data /dev/vg_jama/lv_data
mkfs.ext4 -L logs /dev/vg_jama/lv_logs
if [[ ! " ${functions_array[@]} " =~ "WriteFileSystems" ]]; then
functions_array+=("WriteFileSystems")
fi
}

function quit() {
echo "Exiting..."
exit
}

function menu() {
while true; do
echo "To exit, run all 7 steps, or press Ctrl-C or q."
echo "---------------------------------- "
echo "1) Create mountpoints as folders"
echo "2) Create physical volume"
echo "3) Create volume group"
echo "4) Create logical volumes in group"
echo "5) Write filesystem to disk"
echo "6) Add lines to /etc/fstab"
echo "7) Mount newly created partitions"
echo "q) Exit"
echo " "
read -p "Choose an option (1-7) or; choose q or press Ctrl-C to quit: " choice
case "$choice" in
1)
CreateMountPoints
menu
;;
2)
CreatePhysicalVolume
menu
;;
3)
CreateVolumeGroup
menu
;;
4)
CreateLogicalVolumes
menu
;;
5)
WriteFileSystem
menu
;;
6)
AddLinesToFstab
menu
;;
7)
MountPartitions
menu
;;
q)
quit
break
;;
*)
echo "Invalid choice. Only options 1-3 are allowed. Press Ctrl-C to quit."
menu
;;
esac
if [[ ${#functions_array[@]} -ge 7 ]]; then
echo "Array length is 7 or greater. Quitting."
break
fi
done
}

menu

0 comments on commit b9a62e9

Please sign in to comment.