Commit 5876d0c3 authored by Ophélie Gagnard's avatar Ophélie Gagnard

generation: Clean the code.

parent 0d4ed329
# This file is sourced by some other scripts in this directory
# get the root of the git repository (requires git to be installed)
GIT_ROOT=`git rev-parse --show-toplevel`
PROJECT_DIR=$GIT_ROOT
# get the root of the git repository
GIT_ROOT=$(git rev-parse --show-toplevel)
PROJECT_DIR="$GIT_ROOT"
### TO BE MODIFIED BY USERS ###
KERNEL_VERSION=5.10.0-21
......@@ -13,7 +13,7 @@ PLG_PACKAGE_NAME=plugin-fluentbit-to-wendelin
MCA_VERSION=0.3.1
FLB_VERSION=1.9.8
PLG_VERSION=0.3.2
CERT_NAME=db.crt
SIGNING_KEY_NAME=db.key
### DO NOT MODIFY ###
......
......@@ -3,7 +3,7 @@
set -e
# get the root of the git repository (requires git to be installed)
GIT_ROOT=`git rev-parse --show-toplevel`
GIT_ROOT=$(git rev-parse --show-toplevel)
cd "$GIT_ROOT"/generation
# define useful variables
......@@ -18,6 +18,8 @@ git config --local user.name "Ophelie Gagnard"
apt -y install dracut-core dracut dracut-network sbsigntool pip
apt -y build-dep linux
apt -y install libncurses-dev
# the next line should be enabled when the following is merged and an egg containing the changes is released:
# https://lab.nexedi.com/nexedi/slapos.libnetworkcache/merge_requests/8
#pip install slapos.libnetworkcache
NC_BRANCH=cmdline-selection
NC_DIR="${NC_BRANCH}"_slapos.libnetworkcache
......
#!/bin/bash
## To run this script successfully, you MUST have sourced the target machine's specific environment file
## or have exported ALL the required variables. (See subdirectories of this directory.)
## This script assumes to be run by the root user (with /sbin in the path).
required_variables="
CERT_NAME
SERVER_GROUP
"
for variable in $required_variables; do
if [ ! -v "$variable" ]; then
echo "ERROR: $variable is undefined, please export all required variables."
echo "Required variables (and their value):"
for v in $required_variables; do
echo $v=${!v}
done
exit 1
fi
done
set -e
# get the root of the git repository (requires git to be installed)
GIT_ROOT=`git rev-parse --show-toplevel`
cd $GIT_ROOT
GIT_ROOT=$(git rev-parse --show-toplevel)
cd "$GIT_ROOT"
# define useful variables
source generation/00env.sh
get_partition_path () {
# Return the path of the desired partition.
# Exit and display an error if it finds 0 or several results.
#
# This function should be called ith exactly one argument: the desired partition type.
# Its behavior is undefined otherwise.
desired_partitions=$(fdisk -l | grep "$1")
desired_partition_count=$(echo -e "$desired_partitions" | wc | awk '{print $1}')
if [ -z "$desired_partitions" ]; then
echo -e "No partition of type $1 (shouldbe 1). Exiting."
exit
elif [ "$desired_partition_count" -ne 1 ]; then
echo -e "$desired_partition_count partitions of type $1 (should be 1). Exiting."
exit
else
echo -e "$desired_partitions" | awk '{print $1}'
fi
}
get_partition_id () {
desired_partition_path=$(get_partition_path "$1")
echo -e "$(findmnt -fn -o UUID "$desired_partition_path")"
}
get_default_interface () {
default_results=$(ip route | grep default | wc | awk '{print $1}')
if [ "$default_results" -ne 1 ]; then
echo -e "$default_results default result(s) (should be 1). Exiting."
exit
else
echo -e "$(ip route | grep default | sed 's|.*dev \([^ ]*\).*|\1|g')"
fi
}
get_default_router () {
default_results=$(ip route | grep default | wc | awk '{print $1'})
if [ "$default_results" -ne 1 ]; then
echo -e "$defaults_results default result(s) (should be 1). Exiting."
exit
else
echo -e "$(ip route | grep default | sed 's|.*via \([^ ]*\).*|\1|g')"
fi
}
get_default_ip () {
default_interface=$(get_default_interface)
interface_results=$(ip route | grep -v default | grep "$default_interface" | wc | awk '{print $1}')
if [ "$interface_results" -ne 1 ]; then
echo -e "$interface_results results for \"${default_interface}\" (should be 1). Exiting."
exit
else
echo -e "$(ip route | grep -v default | grep "$default_interface" | sed 's|.*src \([^ ]*\).*|\1|g')"
fi
}
get_default_netmask () {
default_interface=$(get_default_interface)
interface_results=$(ip route | grep -v default | grep "$default_interface" | wc | awk '{print $1}')
if [ "$interface_results" -ne 1 ]; then
echo -e "$interface_results results for \"${default_interface}\" (should be 1). Exiting."
exit
else
echo -e "$(ip route | grep -v default | grep "$default_interface" | sed 's|^\([^ ]*\).*|\1|g')"
fi
}
int_to_generic_netmask () {
# get the mask size: the number right after the "/" (ex: <ipv4>/24 -> 24)
mask_length=$1
mask=""
for i in {0..3}; do
if [ ${mask_length} -ge 8 ]; then
mask=${mask}255
elif [ ${mask_length} -eq 0 ]; then
mask=${mask}0
else
mask=${mask}$((256-2**(8-${mask_length})))
fi
if [ $i -ne 3 ]; then
mask=${mask}.
fi
mask_length=$((mask_length-8))
done
echo -e "${mask}"
}
CERT_DIR=uefi-keys/public-certificates
KEYS_DIR=uefi-keys/private-keys
PUBLIC_CERT_DIR=${PROJECT_DIR}/${CERT_DIR}/${SERVER_GROUP}
......
......@@ -3,15 +3,16 @@
set -e
# get the root of the git repository (requires git to be installed)
GIT_ROOT=`git rev-parse --show-toplevel`
GIT_ROOT=$(git rev-parse --show-toplevel)
cd $GIT_ROOT
# define useful variables
source generation/00env.sh
SERVER_GROUP="${SERVER_GROUP:-generic}"
metadata_file=metadata.json
sha_list=installation/images-sha512.list
hash_comment="# self-compiled kernel, network autoconfig off + dummy ips, rd.neednet=1 LABEL=Root, metadata in shadir, no scan no send"
hash_comment="# debian-signed Debian kernel, network autoconfig off + dummy ips, rd.neednet=1 LABEL=Root, metadata in shadir, scan and send"
version_to_list () {
# take a version with no letters, and return a json list
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment