#!/usr/bin/env bash

# make all files read-only to prevent data corruption

if [ "$UID" != 0 ]; then
  echo "error: you must run this as root. hint: sudo $0"
  exit 1
fi

set -eux

cd "$(dirname "$0")"

# cas_dirs="btih todo"
cas_dirs="btih"

echo "making all files read-only"
find $cas_dirs -type f -print0 | xargs -0 chmod a-w

echo "making all dirs world-writable"
find $cas_dirs -type d -print0 | xargs -0 chmod a+w

echo "making all files and dirs owned by root"
chown -R root:root $cas_dirs

echo "making all files immutable"
find $cas_dirs -type f -print0 | xargs -0 chattr +i