Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add shfmt and shellcheck status checks #32

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions .github/workflows/status-checks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: status checks
on:
push:
branches:
- main
- master
pull_request:

permissions:
contents: read
pull-requests: read

jobs:
shfmt:
name: runner / shfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: reviewdog/action-shfmt@v1
with:
level: info
filter_mode: nofilter
fail_on_error: true
shfmt_flags: '-ln bash -ci -sr -i 2'

shellcheck:
name: runner / shellcheck
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: shellcheck
uses: reviewdog/action-shellcheck@v1
with:
level: info
reporter: github-check
filter_mode: nofilter
fail_on_error: true
exclude: |
"./.git/*"
40 changes: 22 additions & 18 deletions config.sample.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env bash
## config.sample.sh
## zfs-replicate configuration file - edit as needed
## config.sh
# shellcheck disable=SC2034

## ip address or hostname of a remote server
## not used if TYPE is set to LOCAL
Expand Down Expand Up @@ -46,46 +48,48 @@ ALLOW_REPLICATE_FROM_SCRATCH=0
## script will generate a warning and skip replicating root datasets
## 0 - disable (default)
## 1 - enable (use at your own risk)
ALLOW_ROOT_DATASETS=0
readonly ALLOW_ROOT_DATASETS=0

## number of snapshots to keep for each dataset
## older snapshots will be deleted
SNAP_KEEP=2
readonly SNAP_KEEP=2

## number of logs to keep
## older logs will be deleted
LOG_KEEP=5
readonly LOG_KEEP=5

## log files directory (defaults to script path)
SCRIPT=$(readlink -f "$0")
SCRIPTPATH=$(dirname "${SCRIPT}")
LOGBASE="${SCRIPTPATH}/logs"
readonly SCRIPT=$(readlink -f "$0")
readonly SCRIPTPATH=$(dirname "${SCRIPT}")
readonly LOGBASE="${SCRIPTPATH}/logs"

## command to check health of remote host
## a return code of 0 will be considered OK
## not used if TYPE is set to LOCAL
REMOTE_CHECK="ping -c1 -q -W2 ${REMOTE_SERVER}"
readonly REMOTE_CHECK="ping -c1 -q -W2 ${REMOTE_SERVER}"

## path to zfs binary (only command for now)
ZFS=zfs
## path to zfs binary
## the default will find the first `zfs` executable in $PATH
readonly ZFS=$(which zfs)

## path to GNU find binary
## solaris `find` does not support the -maxdepth option, which is required
## on solaris 11, GNU find is typically located at /usr/bin/gfind
FIND=/usr/bin/find
## the default will return the first `find` executable in $PATH
readonly FIND=$(which find)

## get the current date info
DOW=$(date "+%a")
MOY=$(date "+%m")
DOM=$(date "+%d")
NOW=$(date "+%s")
CYR=$(date "+%Y")
readonly DOW=$(date "+%a")
readonly MOY=$(date "+%m")
readonly DOM=$(date "+%d")
readonly NOW=$(date "+%s")
readonly CYR=$(date "+%Y")

## snapshot and log name tags
## ie: pool0/someplace@autorep-${NAMETAG}
NAMETAG="${MOY}${DOM}${CYR}_${NOW}"
readonly NAMETAG="${MOY}${DOM}${CYR}_${NOW}"

## the log file needs to start with
## autorep- in order for log cleanup to work
## using the default below is strongly suggested
LOGFILE="${LOGBASE}/autorep-${NAMETAG}.log"
readonly LOGFILE="${LOGBASE}/autorep-${NAMETAG}.log"
40 changes: 21 additions & 19 deletions get-last-status.sh
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
#!/bin/bash
#!/usr/bin/env bash
## get-last-status.sh

# Set default script directory
SCRIPT=$(readlink -f "$0")
SCRIPTPATH=$(dirname "${SCRIPT}")
print_status() {
## Set local variables used below
local script scriptPath logPath find
script=$(readlink -f "$0")
scriptPath=$(dirname "${script}")
logPath="${scriptPath}/logs"
find=$(which find)

# Check for existing logs
if ! [ -e ${SCRIPTPATH}/logs ]; then
echo "Log directory does not exist, can't check status."
exit 0
fi
## Check for existing logs
if ! [ -e "${logPath}" ]; then
printf "Log directory does not exist, can't check status.\n"
exit 0
fi

# Set log directory
LOGS="${SCRIPTPATH}/logs"
## Retrieve latest log status
local newestLog status
newestLog=$(${find} "${logPath}" -maxdepth 1 -type f -name autorep-\* | sort | tail -1)
status=$(tail -n 1 "${logPath}/${newestLog}")

# Retrieve latest log status
RECENT_LOG_FILE=$(ls ${LOGS} | grep autorep- | tail -n 1)
STATUS=$(tail -n 1 ${LOGS}/${RECENT_LOG_FILE})

echo "Last Replication Status"
echo "----------"
echo "${STATUS}"
echo "----------"
## Print status block
printf "Last Replication Status\n----------\n%s\n----------\n" "${status}"
}
Loading
Loading