Improved variable management

This commit is contained in:
Michele Cereda
2022-04-18 01:11:56 +02:00
parent 8dc9f14e8a
commit a202013a33
6 changed files with 33 additions and 28 deletions

View File

@@ -2,14 +2,15 @@
: ${DEVICE:?not set} : ${DEVICE:?not set}
: ${LABEL:?not set} : ${LABEL:?not set}
MOUNT_OPTIONS="${MOUNT_OPTIONS:-compress-force=zstd}"
[[ ${EUID} -eq 0 ]] || (echo "Please rerun this script with root privileges" && exit 1) : "${MOUNT_OPTIONS:=compress-force=zstd}"
[[ -f "${DEVICE}" ]] || echo "${DEVICE} not found"
cryptsetup luksFormat "${DEVICE}" [[ $EUID -eq 0 ]] || (echo "Please rerun this script with root privileges" && exit 1)
cryptsetup luksOpen "${DEVICE}" "${LABEL}" [[ -f "$DEVICE" ]] || echo "${DEVICE} not found"
mkfs.btrfs --label "${LABEL}" "/dev/mapper/${LABEL}"
mount --types btrfs --options "${MOUNT_OPTIONS}" "/dev/mapper/${LABEL}" "/mnt/${LABEL}" cryptsetup luksFormat "$DEVICE"
cryptsetup luksOpen "$DEVICE" "$LABEL"
mkfs.btrfs --label "$LABEL" "/dev/mapper/${LABEL}"
mount --types btrfs --options "$MOUNT_OPTIONS" "/dev/mapper/${LABEL}" "/mnt/${LABEL}"
umount "/mnt/${LABEL}" umount "/mnt/${LABEL}"
cryptsetup luksClose "${DEVICE}" cryptsetup luksClose "$DEVICE"

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env sh #!/usr/bin/env sh
TOP_LEVEL="$(git rev-parse --show-toplevel)" : "${TOP_LEVEL:=$(git rev-parse --show-toplevel)}"
echo "Decrypting files…" echo "Decrypting files…"

View File

@@ -1,8 +0,0 @@
#!/usr/bin/env sh
USER_FULL_NAME='Mek'
USER_NAME='mek'
USER_PASSWORD="${USER_PASSWORD:?'not set'}"
USER_TYPE='local'
yast users add batchmode verbose type="${USER_TYPE}" username="${USER_NAME}" password="${USER_PASSWORD}" cn="${USER_FULL_NAME}"

12
scripts/opensuse/pi.setup.sh Executable file
View File

@@ -0,0 +1,12 @@
#!/usr/bin/env sh
: "${USER_FULL_NAME:='Mek'}"
: "${USER_NAME:='mek'}"
: "${USER_PASSWORD:?'not set'}"
: "${USER_TYPE:='local'}"
yast users add batchmode verbose \
type="$USER_TYPE" \
username="$USER_NAME" \
password="$USER_PASSWORD" \
cn="$USER_FULL_NAME"

View File

@@ -3,7 +3,7 @@
set -e set -e
sudo curl -fsSL https://get.docker.com | sh - sudo curl -fsSL https://get.docker.com | sh -
sudo usermod -aG docker ${USER} sudo usermod -aG docker $USER
# logout && login to apply the new status # logout && login to apply the new status

View File

@@ -1,21 +1,21 @@
#!/usr/bin/env bash #!/usr/bin/env bash
interface="wlan0" : "${INTERFACE:='wlan0'}"
max_retries=3 : ${MAX_RETRIES:=3}
timeout=1 : ${TIMEOUT:=1}
log_path="$(dirname $0)/$(basename $0).log" : "${LOG_PATH=$(dirname $0)/$(basename $0).log}"
log_prefix="$(date +'%Y-%m-%d %T')" : "${LOG_PREFIX=$(date +'%Y-%m-%d %T')}"
i=0 i=0
until [ $i -eq $max_retries ]; do until [ $i -eq $MAX_RETRIES ]; do
let "i++" let "i++"
if nc -Nz -w $timeout www.google.com 443; then if nc -Nz -w $TIMEOUT www.google.com 443; then
echo "$log_prefix" "connection is OK" >> $log_path echo "$LOG_PREFIX" "connection is OK" >> $LOG_PATH
break break
else else
echo "$log_prefix" "no connection, resetting interface" >> $log_path echo "$LOG_PREFIX" "no connection, resetting interface" >> $LOG_PATH
sudo ifconfig wlan0 down && sudo ifconfig wlan0 up sudo ifconfig $INTERFACE down && sudo ifconfig $INTERFACE up
fi fi
done done