1
0
Fork 0

Bin: clean up shell scripts per Shellcheck

This commit is contained in:
Aires 2024-12-06 13:04:15 -05:00
parent 2b2c416e49
commit 26e4889ba8
3 changed files with 28 additions and 30 deletions

View file

@ -53,7 +53,6 @@ while [[ $# -gt 0 ]]; do
;; ;;
esac esac
done done
remainingArgs=${POSITIONAL_ARGS[@]}
set -- "${POSITIONAL_ARGS[@]}" # restore positional parameters set -- "${POSITIONAL_ARGS[@]}" # restore positional parameters
# If this is a git repo and no name has been provided, name the draft after the current branch # If this is a git repo and no name has been provided, name the draft after the current branch
@ -63,9 +62,9 @@ fi
# Check if this directory already exists # Check if this directory already exists
outDir="$outDir/${draftName}" outDir="$outDir/${draftName}"
if [ -d $outDir ]; then if [ -d "$outDir" ]; then
echo "The folder $outDir already exists." echo "The folder $outDir already exists."
read -p "Enter YES to overwrite, or Ctrl-C to cancel: " confirm && [ $confirm = "YES" ] || exit 1 read -rp "Enter YES to overwrite, or Ctrl-C to cancel: " confirm && [ "$confirm" = "YES" ] || exit 1
fi fi
draftFile="$outDir/${draftName}" draftFile="$outDir/${draftName}"
@ -73,20 +72,20 @@ draftFile="$outDir/${draftName}"
echo "Compiling draft \"${draftName}\"..." echo "Compiling draft \"${draftName}\"..."
# Create the draft directory if it doesn't already exist # Create the draft directory if it doesn't already exist
mkdir -p $outDir mkdir -p "$outDir"
# Initialize merged file # Initialize merged file
echo > $draftFile.md echo > "$draftFile".md
# Grab content files and add a page break to the end of each one. # Grab content files and add a page break to the end of each one.
# Obsidian specifically creates "folder notes," which are named for the directory, so we make sure to exclude it. # Obsidian specifically creates "folder notes," which are named for the directory, so we make sure to exclude it.
find "$inDir" -type f -wholename "* *.md" ! -name content.md -print0 | sort -z | while read -d $'\0' file find "$inDir" -type f -wholename "* *.md" ! -name content.md -print0 | sort -z | while read -rd $'\0' file
do do
# Add newline to Markdown doc # Add newline to Markdown doc
echo >> $draftFile.md echo >> "$draftFile".md
# Clean up incoming Markdown and append it to final doc # Clean up incoming Markdown and append it to final doc
sed "s|(../|($inDir/../|g" "$file" >> $draftFile.md sed "s|(../|($inDir/../|g" "$file" >> "$draftFile".md
echo "\\newpage" >> $draftFile.md echo "\\newpage" >> "$draftFile".md
done done
# Generate the output files: # Generate the output files:
@ -94,9 +93,9 @@ done
# Markdown -> EPUB # Markdown -> EPUB
# Markdown -> PDF (A4 size) # Markdown -> PDF (A4 size)
# Markdown -> PDF (B6/Standard book size) # Markdown -> PDF (B6/Standard book size)
pandoc -t docx $draftFile.md -o $draftFile.docx --metadata-file "$metadataFile" pandoc -t docx "$draftFile".md -o "$draftFile".docx --metadata-file "$metadataFile"
pandoc -t epub $draftFile.md -o $draftFile.epub --metadata-file "$metadataFile" pandoc -t epub "$draftFile".md -o "$draftFile".epub --metadata-file "$metadataFile"
pandoc $draftFile.md -o ${draftFile}-a4.pdf --metadata-file "$metadataFile" -V geometry:"a4paper" -V fontsize:"12pt" pandoc "$draftFile".md -o "$draftFile"-a4.pdf --metadata-file "$metadataFile" -V geometry:"a4paper" -V fontsize:"12pt"
pandoc $draftFile.md -o ${draftFile}-b6.pdf --metadata-file "$metadataFile" -V geometry:"b6paper" -V fontsize:"10pt" pandoc "$draftFile".md -o "$draftFile"-b6.pdf --metadata-file "$metadataFile" -V geometry:"b6paper" -V fontsize:"10pt"
echo "Done! Your new draft is in $outDir" echo "Done! Your new draft is in $outDir"

View file

@ -46,7 +46,6 @@ while [[ $# -gt 0 ]]; do
;; ;;
--help|-h) --help|-h)
usage usage
shift
;; ;;
*) *)
POSITIONAL_ARGS+=("$1") # save positional arg POSITIONAL_ARGS+=("$1") # save positional arg
@ -57,8 +56,8 @@ done
set -- "${POSITIONAL_ARGS[@]}" # restore positional parameters set -- "${POSITIONAL_ARGS[@]}" # restore positional parameters
cryptsetup luksOpen $luks_partition nixos-crypt cryptsetup luksOpen "$luks_partition" nixos-crypt
mkfs.btrfs -L nixos $root_partition mkfs.btrfs -L nixos "$root_partition"
mount /dev/mapper/nixos-crypt /mnt mount /dev/mapper/nixos-crypt /mnt
btrfs subvolume create /mnt/@ btrfs subvolume create /mnt/@
btrfs subvolume create /mnt/@home btrfs subvolume create /mnt/@home
@ -67,13 +66,13 @@ btrfs subvolume create /mnt/@nix
btrfs subvolume create /mnt/@swap btrfs subvolume create /mnt/@swap
umount /mnt umount /mnt
mount -o subvol=@ $root_partition /mnt mount -o subvol=@ "$root_partition" /mnt
mkdir -p /mnt/{boot,home,var/log,nix,swap} mkdir -p /mnt/{boot,home,var/log,nix,swap}
mount $boot_partition /mnt/boot mount "$boot_partition" /mnt/boot
mount -o subvol=@home $root_partition /mnt/home mount -o subvol=@home "$root_partition" /mnt/home
mount -o subvol=@log $root_partition /mnt/var/log mount -o subvol=@log "$root_partition" /mnt/var/log
mount -o subvol=@nix $root_partition /mnt/nix mount -o subvol=@nix "$root_partition" /mnt/nix
mount -o subvol=@swap $root_partition /mnt/swap mount -o subvol=@swap "$root_partition" /mnt/swap
echo "Disks partitioned and mounted to /mnt." echo "Disks partitioned and mounted to /mnt."
# Generate hardware-configuration.nix # Generate hardware-configuration.nix

View file

@ -73,7 +73,7 @@ while [[ $# -gt 0 ]]; do
;; ;;
esac esac
done done
remainingArgs=${POSITIONAL_ARGS[@]} remainingArgs=${POSITIONAL_ARGS[*]}
set -- "${POSITIONAL_ARGS[@]}" # restore positional parameters set -- "${POSITIONAL_ARGS[@]}" # restore positional parameters
if [ -z "${flakeDir}" ]; then if [ -z "${flakeDir}" ]; then
@ -81,28 +81,28 @@ if [ -z "${flakeDir}" ]; then
exit 1 exit 1
fi fi
cd $flakeDir cd "$flakeDir" || exit 1
echo "Pulling the latest version of the repository..." echo "Pulling the latest version of the repository..."
/run/wrappers/bin/sudo -u $user /run/current-system/sw/bin/git pull /run/wrappers/bin/sudo -u "$user" /run/current-system/sw/bin/git pull
if [ $update = true ]; then if [ $update = true ]; then
echo "Updating flake.lock..." echo "Updating flake.lock..."
/run/wrappers/bin/sudo -u $user /run/current-system/sw/bin/nix flake update --commit-lock-file /run/wrappers/bin/sudo -u "$user" /run/current-system/sw/bin/nix flake update --commit-lock-file
/run/wrappers/bin/sudo -u $user git push /run/wrappers/bin/sudo -u "$user" git push
else else
echo "Skipping 'nix flake update'..." echo "Skipping 'nix flake update'..."
fi fi
options="--flake ${flakeDir}#${hostname} ${remainingArgs} --use-remote-sudo --log-format multiline-with-logs" options="--flake ${flakeDir}#${hostname} ${remainingArgs} --use-remote-sudo --log-format multiline-with-logs"
if [[ -n "${buildHost}" && $operation != "build" && $operation != *"dry"* ]]; then if [[ -n "${buildHost}" && "$operation" != "build" && "$operation" != *"dry"* ]]; then
echo "Remote build detected, running this operation first: nixos-rebuild build ${options} --build-host $buildHost" echo "Remote build detected, running this operation first: nixos-rebuild build ${options} --build-host $buildHost"
/run/current-system/sw/bin/nixos-rebuild build $options --build-host $buildHost /run/current-system/sw/bin/nixos-rebuild build "$options" --build-host "$buildHost"
echo "Remote build complete!" echo "Remote build complete!"
fi fi
echo "Running this operation: nixos-rebuild ${operation} ${options}" echo "Running this operation: nixos-rebuild ${operation} ${options}"
/run/current-system/sw/bin/nixos-rebuild $operation $options /run/current-system/sw/bin/nixos-rebuild "$operation" "$options"
exit 0 exit 0