Skip to content

Commit

Permalink
Feature/linting (#22)
Browse files Browse the repository at this point in the history
* testing linting
* complying with linting rules
  • Loading branch information
dblane-digicatapult authored Mar 22, 2024
1 parent 6b917d4 commit d3c9940
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 21 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: lint

on: [push]

jobs:
lint:
name: Run ShellCheck
runs-on: ubuntu-latest

steps:
- name: Check out code
uses: actions/checkout@v4

- name: Install ShellCheck
run: sudo apt-get install shellcheck

- name: Find shell scripts with \#!/bin/sh or \#!/bin/bash and run ShellCheck
run: |
files=$(find . -type f ! -path '*/\.*' -exec grep -lE '^#!(/usr)?/bin/(ba)?sh' {} +)
if [ -n "$files" ]; then
shellcheck -a -S warning $files
else
echo "No shell scripts with #!/bin/sh or #!/bin/bash shebang found."
fi
24 changes: 13 additions & 11 deletions files/extra-files/etc/rc.d/dsbd_lab
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# REQUIRE: NETWORKING LOGIN FILESYSTEM
# BEFORE: securelevel

# shellcheck disable=SC2034

. /etc/rc.subr

name="dsbd_lab"
Expand All @@ -28,7 +30,7 @@ configure_pot() {
if [ ! -d "$HOME/pot" ]; then
git -C $HOME clone https://github.com/digicatapult/pot --no-progress
fi
cd $HOME/pot
cd $HOME/pot || exit

# Copy to /usr/local64 for the hybrid ABI port
for dir in bin etc share; do
Expand All @@ -51,7 +53,7 @@ install_act() {
if [ ! -d "$HOME/act-pot-cheribsd" ]; then
git -C $HOME clone https://github.com/digicatapult/act-pot-cheribsd --no-progress
fi
cd $HOME/act-pot-cheribsd
cd $HOME/act-pot-cheribsd || exit
# Install runner scripts/flavours
./install.sh
}
Expand Down Expand Up @@ -105,34 +107,34 @@ fetch_manifests() {
}

get_latest_version() {
if [ ! -z $(echo releases) ]; then
version=$(echo $releases | awk -F " " '{print $NF}')
if [ ! -z "$(echo "$releases")" ]; then
version=$(echo "$releases" | awk -F " " '{print $NF}')
else
version="23.11"
fi
echo $version
echo "$version"
}

create_base() {
base_name=$(get_latest_version)

# Create a base pot for the latest aarch64c release
if [ ! $(pot list -b | grep -Eo '$base_name') ]; then
pot create-base -r $base_name
if [ ! "$(pot list -b | grep -Eo '$base_name')" ]; then
pot create-base -r "$base_name"
fi

# Copy libraries for the hybrid and benchmark ABIs
for lib in lib64 lib64cb; do
cp -nR /usr/$lib /opt/pot/bases/$base_name/usr/
cp -nR /usr/$lib /opt/pot/bases/"$base_name"/usr/
done
}

create_base_bridge() {
bridge_name="bridge-"$(get_latest_version)

# Create a private VNET for the release
pot create-private-bridge -B $bridge_name -S 256
pot vnet-start -B $bridge_name
pot create-private-bridge -B "$bridge_name" -S 256
pot vnet-start -B "$bridge_name"
}

configure_base_sshd() {
Expand All @@ -158,7 +160,7 @@ start_pots() {
max_runners=3

. $HOME/.profile
cd "$HOME/act-pot-cheribsd"
cd "$HOME/act-pot-cheribsd" || exit

while [ "$count" -lt "$max_runners" ]; do
# Calculate the index for the next runner
Expand Down
15 changes: 10 additions & 5 deletions files/update_qemu_morello_config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,28 @@ get_cpu_sockets() {

# Function to get the adjusted number of CPU threads for QEMU
get_cpu_threads_for_qemu() {
local total_threads=$(nproc --all)
local total_threads
total_threads=$(nproc --all)
local threads_for_qemu=$((total_threads > CPU_DEDUCTION ? total_threads - CPU_DEDUCTION : MIN_CPU_THREADS))
echo "$threads_for_qemu"
}

# Function to get the adjusted memory for QEMU
get_memory_for_qemu() {
local total_mem_mb=$(awk '/MemTotal/ {print int($2/1024)}' /proc/meminfo)
local total_mem_mb
total_mem_mb=$(awk '/MemTotal/ {print int($2/1024)}' /proc/meminfo)
local mem_for_qemu=$((total_mem_mb > BUFFER_MEM_MB ? total_mem_mb - BUFFER_MEM_MB : total_mem_mb))
echo "${mem_for_qemu}M"
}

# Function to write configuration to the config file
write_config() {
local cpu_sockets=$(get_cpu_sockets) || handle_error "Failed to get CPU sockets."
local cpu_threads=$(get_cpu_threads_for_qemu) || handle_error "Failed to calculate CPU threads for QEMU."
local memory=$(get_memory_for_qemu) || handle_error "Failed to calculate memory for QEMU."
local cpu_sockets
cpu_sockets=$(get_cpu_sockets) || handle_error "Failed to get CPU sockets."
local cpu_threads
cpu_threads=$(get_cpu_threads_for_qemu) || handle_error "Failed to calculate CPU threads for QEMU."
local memory
memory=$(get_memory_for_qemu) || handle_error "Failed to calculate memory for QEMU."

echo "QEMU_SMP=cores=1,threads=${cpu_threads},sockets=${cpu_sockets}" > "$CONFIG_FILE" || handle_error "Failed to write CPU configuration to $CONFIG_FILE."
echo "QEMU_MEM=${memory}" >> "$CONFIG_FILE" || handle_error "Failed to write memory configuration to $CONFIG_FILE."
Expand Down
8 changes: 4 additions & 4 deletions scripts/create-cheribsd-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ echo "Configuration variables set."
# Function to run cheribuild to build QEMU
run_cheribuild_qemu() {
echo "Running cheribuild to build QEMU..."
pushd "$CHERI_HOME" > /dev/null
pushd "$CHERI_HOME" > /dev/null || exit
runuser -u cheri -- "$CHERIBUILD_DIR/cheribuild.py" --build qemu -d
popd > /dev/null
popd > /dev/null || exit
echo "Cheribuild QEMU completed."
}

Expand All @@ -40,9 +40,9 @@ resize_zfs() {
# Function to run cheribuild to build the disk image
run_cheribuild_disk_image() {
echo "Running cheribuild to build CheriBSD disk image..."
pushd "$CHERI_HOME" > /dev/null
pushd "$CHERI_HOME" > /dev/null || exit
runuser -u cheri -- "$CHERIBUILD_DIR/cheribuild.py" --build disk-image-morello-purecap -d --disk-image/rootfs-type zfs --disk-image/path "$DISK_IMAGE_RAW"
popd > /dev/null
popd > /dev/null || exit
echo "Cheribuild CheriBSD disk image completed."
}
# Function to convert disk image to QCOW2
Expand Down
2 changes: 1 addition & 1 deletion scripts/install-cheribuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ determine_zfs_paths() {

configure_sudoers_for_zfs() {
local paths
paths=($(determine_zfs_paths))
mapfile -t paths < <(determine_zfs_paths)

local sudo_cmds=""
for path in "${paths[@]}"; do
Expand Down

0 comments on commit d3c9940

Please sign in to comment.