Skip to content

Commit

Permalink
Merge pull request #499 from jfly/enable-shellcheck
Browse files Browse the repository at this point in the history
Enable shellcheck, address errors
  • Loading branch information
Mic92 authored Oct 30, 2024
2 parents e6ab062 + 715df41 commit e8b4196
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 29 deletions.
14 changes: 7 additions & 7 deletions build/scripts/nix-mac-installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ echo "created nixbld group with gid $gid"
for i in $(seq 1 10); do
user=/Users/nixbld$i
uid="$((30000 + i))"
dscl . -create $user
dscl . -create $user RealName "Nix build user $i"
dscl . -create $user PrimaryGroupID "$gid"
dscl . -create $user UserShell /usr/bin/false
dscl . -create $user NFSHomeDirectory /var/empty
dscl . -create $user UniqueID "$uid"
dseditgroup -o edit -a nixbld$i -t user nixbld
dscl . -create "$user"
dscl . -create "$user" RealName "Nix build user $i"
dscl . -create "$user" PrimaryGroupID "$gid"
dscl . -create "$user" UserShell /usr/bin/false
dscl . -create "$user" NFSHomeDirectory /var/empty
dscl . -create "$user" UniqueID "$uid"
dseditgroup -o edit -a "nixbld$i" -t user nixbld
echo "created nixbld$i user with uid $uid"
done

Expand Down
6 changes: 3 additions & 3 deletions build/scripts/nix-mac-nuke.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ launchctl unload $service_plist
dscl . -delete /Groups/nixbld

for i in $(seq 1 20); do
dscl . -delete /Users/nixbld$i
dscl . -delete "/Users/nixbld$i"
done

sudo rm -f $service_plist

sudo rm -rf /nix /etc/nix/nix.conf

rm -f $HOME/.nix-channels $HOME/.nix-profile
rm -rf $HOME/.nix-defexpr
rm -f "$HOME/.nix-channels" "$HOME/.nix-profile"
rm -rf "$HOME/.nix-defexpr"
3 changes: 1 addition & 2 deletions formatter/flake-module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
programs.nixfmt.package = pkgs.nixfmt-rfc-style;
programs.ruff-format.enable = true;

# TODO: fix shellcheck errors in a follow up pr
#programs.shellcheck.enable = true;
programs.shellcheck.enable = true;

programs.shfmt.enable = true;
programs.rustfmt.enable = true;
Expand Down
6 changes: 4 additions & 2 deletions metrics/fastly/cron.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#! /bin/sh -e
#!/usr/bin/env bash

set -e

export AWS_PROFILE=nixos-org

Expand All @@ -19,7 +21,7 @@ if [[ -e $marker ]]; then
fi

mkdir -p "$(dirname "$marker")"
touch $marker
touch "$marker"

./ingest-raw-logs.sh "$from_date_incl" "$to_date_incl"

Expand Down
12 changes: 7 additions & 5 deletions metrics/fastly/ingest-raw-logs.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#! /bin/sh -e
#!/usr/bin/env bash

set -e

region=eu-west-1

Expand All @@ -14,7 +16,7 @@ run_query() {

res=$(aws athena start-query-execution \
--region $region \
--result-configuration OutputLocation=s3://nixos-athena/ingestion/$name/ \
--result-configuration "OutputLocation=s3://nixos-athena/ingestion/$name/" \
--query-string "$query")

execution_id="$(printf "%s" "$res" | jq -r -e .QueryExecutionId)"
Expand All @@ -24,14 +26,14 @@ run_query() {

printf "Waiting..."
while true; do
res="$(aws athena get-query-execution --region $region --query-execution-id $execution_id)"
res="$(aws athena get-query-execution --region $region --query-execution-id "$execution_id")"
status="$(printf %s "$res" | jq -r -e .QueryExecution.Status.State)"
if [[ $status = RUNNING || $status = QUEUED ]]; then
if [[ $status == RUNNING || $status == QUEUED ]]; then
printf "."
sleep 1
continue
fi
if [[ $status = SUCCEEDED ]]; then
if [[ $status == SUCCEEDED ]]; then
printf " done.\n"
break
fi
Expand Down
10 changes: 6 additions & 4 deletions metrics/fastly/run-queries.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#! /bin/sh -e
#!/usr/bin/env bash

set -e

region=eu-west-1

Expand All @@ -10,7 +12,7 @@ run_query() {

res=$(aws athena start-query-execution \
--region $region \
--result-configuration OutputLocation=s3://nixos-metrics/$report_date/$name/ \
--result-configuration "OutputLocation=s3://nixos-metrics/$report_date/$name/" \
--query-string "$query")

execution_id="$(printf "%s" "$res" | jq -r -e .QueryExecutionId)"
Expand All @@ -21,8 +23,8 @@ run_query() {
redirect=latest/$name.csv
aws s3api put-object \
--bucket nixos-metrics \
--key $redirect \
--website-redirect-location /$report_date/$name/$execution_id.csv >/dev/null
--key "$redirect" \
--website-redirect-location "/$report_date/$name/$execution_id.csv" >/dev/null

echo "Created redirect http://nixos-metrics.s3-website-eu-west-1.amazonaws.com/$redirect."
}
Expand Down
17 changes: 11 additions & 6 deletions modules/prometheus/system-version-exporter.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
#!/bin/sh
#!/usr/bin/env bash

set -euo pipefail

readonly VERSION="$(cat /run/current-system/nixos-version)"
readonly CURRENT_SYSTEM_DRV="$(readlink /run/current-system)"
readonly CURRENT_SYSTEM_PROFILE="$(find /nix/var/nix/profiles -ilname "${CURRENT_SYSTEM_DRV}")"
readonly DEPLOY_TIMESTAMP="$(stat -c '%y' "${CURRENT_SYSTEM_PROFILE}" | cut -c '-16')"
readonly DEPLOY_SECONDS="$(stat -c '%Y' "${CURRENT_SYSTEM_PROFILE}")"
readonly VERSION
VERSION="$(cat /run/current-system/nixos-version)"
readonly CURRENT_SYSTEM_DRV
CURRENT_SYSTEM_DRV="$(readlink /run/current-system)"
readonly CURRENT_SYSTEM_PROFILE
CURRENT_SYSTEM_PROFILE="$(find /nix/var/nix/profiles -ilname "${CURRENT_SYSTEM_DRV}")"
readonly DEPLOY_TIMESTAMP
DEPLOY_TIMESTAMP="$(stat -c '%y' "${CURRENT_SYSTEM_PROFILE}" | cut -c '-16')"
readonly DEPLOY_SECONDS
DEPLOY_SECONDS="$(stat -c '%Y' "${CURRENT_SYSTEM_PROFILE}")"

echo "node_deployed{version=\"${VERSION}\",date=\"${DEPLOY_TIMESTAMP}\"} ${DEPLOY_SECONDS}"

0 comments on commit e8b4196

Please sign in to comment.