From 12a11b2435a46af02554274bc76ef08ea2349435 Mon Sep 17 00:00:00 2001 From: Michael Campagnaro Date: Mon, 19 Jun 2023 22:27:36 -0400 Subject: [PATCH] Update some scripts --- .vimrc | 2 +- dotfiles/bin/antimalware-service-disable.bat | 2 +- dotfiles/bin/aws-list-deep-glacier-files | 25 ++++++++++ dotfiles/bin/aws-restore-deep-glacier-folder | 51 +++++++++++++++++--- dotfiles/bin/transcribe-audio | 7 ++- 5 files changed, 78 insertions(+), 9 deletions(-) diff --git a/.vimrc b/.vimrc index 1293067..ddc805d 100644 --- a/.vimrc +++ b/.vimrc @@ -1259,7 +1259,7 @@ fu! Build(optimized=0, silent=0) " scripts won't be looking at the user metaprogram args. " We also don't bother adding an import directory for local modules " because the build file should manage that sort of thing for us. - let l:cmd .= " -release - release" + let l:cmd .= " -release - -release" let l:set_metaprogram_args = 1 else echo "Compiling debug build.jai" diff --git a/dotfiles/bin/antimalware-service-disable.bat b/dotfiles/bin/antimalware-service-disable.bat index fdf6a2e..2f45f81 100644 --- a/dotfiles/bin/antimalware-service-disable.bat +++ b/dotfiles/bin/antimalware-service-disable.bat @@ -94,7 +94,7 @@ reg add HKLM\SYSTEM\Setup /v DisabledDefenderServices /t REG_DWORD /d 1 /f echo. echo Windows Defender has (hopefully) been disabled. -echo You should still be able to scan files going forward. Also, the Antimalware Service Executable should immediately stop using CPU cycles. +echo You might still be able to scan files going forward depending on your version of Windows. Also, the Antimalware Service Executable should immediately stop using CPU cycles. echo Please restart your computer to see all changes. goto eof diff --git a/dotfiles/bin/aws-list-deep-glacier-files b/dotfiles/bin/aws-list-deep-glacier-files index 7da7f6f..0b8b8c7 100644 --- a/dotfiles/bin/aws-list-deep-glacier-files +++ b/dotfiles/bin/aws-list-deep-glacier-files @@ -1,5 +1,30 @@ #!/usr/bin/env bash +# Creates a file containing the names of all files in a specific bucket. +# +# e.g. aws-list-deep-glacier-files my-deep-glacier images image_list +# +# You'll need the aws cli tools. Download them from https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html +# +# If you see an error like along the lines of "'charmap' codec can't encode +# character '\u200e' in position 42: character maps to " then that +# means a filename has a Unicode codepoint and the dumb aws Python code is +# trying to read it using your system's locale, which is very likely not set to +# use the Windows UTF-8 beta feature. This is an ongoing issue in this tool +# that goes back to 2013!!! There's no way to fix it using environment +# variables, at least nothing worked for me. The fix provided by the devs is +# heavy handed: you change your system locale to use UTF-8... This has +# consequences though like breaking legacy apps that don't have Unicode support +# and I'm sure other weird things will happen, such as file corruption. Anyway, +# if you're getting this charmap error then I suggest changing your system +# locale, run this again, then switch back to your previous locale. If you +# don't get the canonical file name then you won't be able to restore it. +# +# You can enable the UTF-8 locale with: +# +# win+r -> intl.cpl -> Administrative tab -> Change system locale -> Beta: Use Unicode UTF-8 box. +# + if which tput >/dev/null 2>&1; then ncolors=$(tput colors) fi diff --git a/dotfiles/bin/aws-restore-deep-glacier-folder b/dotfiles/bin/aws-restore-deep-glacier-folder index e3d0bdc..6104d2f 100644 --- a/dotfiles/bin/aws-restore-deep-glacier-folder +++ b/dotfiles/bin/aws-restore-deep-glacier-folder @@ -1,10 +1,49 @@ #!/usr/bin/env bash # -# Restores all files/folders inside a particular bucket path, -# e.g. aws-restore-deep-glacier-folder mcampagnaro-deep-glacier images restored_images -# will restore all files inside the images folder of the mcampagnaro-deep-glacier bucket, saving -# temp restoration data in the local "restored_images" directory. +# Restores all files/folders inside a particular bucket path for the next 7 days. This uses the bulk retreival tier: +# +# Bulk retrievals are the lowest-cost retrieval option when restoring objects +# from S3 Glacier Deep Archive. They typically finish within 48 hours for +# objects stored in the S3 Glacier Deep Archive storage class or S3 +# Intelligent-Tiering Deep Archive tier. +# +# If you need faster access then use the `Expedited` or `Standard` tiers. +# +# Example usage: +# +# aws-restore-deep-glacier-folder my-deep-glacier-bucket path/to/images restored_images +# +# This will create a run.sh script in a folder called "restored_images". Run that to restore all files inside the `path/to/images` folder inside the my-deep-glacier bucket. +# +# After you run the generated script, you have to wait for AWS to make the files available for download. You can check the status of a file with: +# +# aws s3api head-object --bucket my-deep-glacier --key path/to/images/photo1.jpg +# +# (obviously change the bucket and path to suit your needs). +# +# Once the files are restored you can download them on the S3 website or better yet use RcloneBrowser. I'm sure there's also a way to do it over cli too, I just haven't checked. +# +# You'll need the aws cli tools for this script. Download them from https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html +# Once installed, open a new shell and verify that you can run the `aws` command. +# +# If you see an error like along the lines of "'charmap' codec can't encode +# character '\u200e' in position 42: character maps to " then that +# means a filename has a Unicode codepoint and the dumb aws Python code is +# trying to read it using your system's locale, which is very likely not set to +# use the Windows UTF-8 beta feature. This is an ongoing issue in this tool +# that goes back to 2013!!! There's no way to fix it using environment +# variables, at least nothing worked for me. The fix provided by the devs is +# heavy handed: you change your system locale to use UTF-8... This has +# consequences though like breaking legacy apps that don't have Unicode support +# and I'm sure other weird things will happen, such as file corruption. Anyway, +# if you're getting this charmap error then I suggest changing your system +# locale, run this again, then switch back to your previous locale. If you +# don't get the canonical file name then you won't be able to restore it. +# +# You can enable the UTF-8 locale with: +# +# win+r -> intl.cpl -> Administrative tab -> Change system locale -> Beta: Use Unicode UTF-8 box. # if which tput >/dev/null 2>&1; then @@ -46,7 +85,7 @@ path="$2" temp_dir="$3" number_of_objects_per_file=100 days_available=7 -restore_tier="Bulk" # Can also be "Standard" +restore_tier="Bulk" # Can also be "Standard" or "Expedited" if [[ $bucket == "" || $path == "" || $temp_dir == "" ]]; then error "Usage: aws-restore-deep-glacier-folder " @@ -61,7 +100,7 @@ pushd "$temp_dir" &>/dev/null aws s3api list-objects-v2 --bucket $bucket --prefix $path --query "Contents[?StorageClass=='DEEP_ARCHIVE']" --output text | LC_ALL=C awk '{print substr($0, index($0, $2))}' | awk '{NF-=3};3' > all_objects_list.txt # Generate the main script that will kick off the restoration. -printf "while read x; do\n printf \"aws s3api restore-object --restore-request '{\\\\\"Days\\\\\":$days_available,\\\\\"GlacierJobParameters\\\\\":{\\\\\"Tier\\\\\":\\\\\"$restore_tier\\\\\"}}' --bucket $bucket --key \\\\\"\$x\\\\\"\\\\n\"\n aws s3api restore-object --restore-request \"{\\\\\"Days\\\\\":$days_available,\\\\\"GlacierJobParameters\\\\\":{\\\\\"Tier\\\\\":\\\\\"$restore_tier\\\\\"}}\" --bucket $bucket --key \"\$x\"\ndone < all_objects_list.txt\nprintf \"\\\\nDone! You can now delete this folder.\\\\n\"\n" > run.sh +printf "while read x; do\n printf \"aws s3api restore-object --restore-request '{\\\\\"Days\\\\\":$days_available,\\\\\"GlacierJobParameters\\\\\":{\\\\\"Tier\\\\\":\\\\\"$restore_tier\\\\\"}}' --bucket $bucket --key \\\\\"\$x\\\\\"\\\\n\"\n aws s3api restore-object --restore-request \"{\\\\\"Days\\\\\":$days_available,\\\\\"GlacierJobParameters\\\\\":{\\\\\"Tier\\\\\":\\\\\"$restore_tier\\\\\"}}\" --bucket $bucket --key \"\$x\"\ndone < all_objects_list.txt\nprintf \"\\\\nDone! You can now delete this folder.\\\\nYour files are currently being restored. The time it takes to restore can be found in the AWS docs - just look for the $restore_tier restore tier, which is what you used.\\\\nOnce restored, download the files from the S3 site or better yet use RCloneBrowser.\\\\n\"\n" > run.sh chmod +x run.sh printf "${BOLD}You can now run ${GREEN}$temp_dir/run.sh${NORMAL}${BOLD} to start the restoration process.\n" diff --git a/dotfiles/bin/transcribe-audio b/dotfiles/bin/transcribe-audio index 34ef892..22b3e8a 100644 --- a/dotfiles/bin/transcribe-audio +++ b/dotfiles/bin/transcribe-audio @@ -85,7 +85,12 @@ whisper_fullname="$(expand_path $(which whisper.exe))" whisper_path="$(dirname $whisper_fullname)" models_path="$whisper_path/models" -whisper.exe --processors ${cores} --threads ${threads} -m "$models_path/ggml-${model}.en.bin" -otxt -osrt -f "$input_wav" -of "$output_name" --print-colors --print-progress +if [[ $model != "large" ]]; then + model="${model}.en" +fi + +whisper.exe --processors ${cores} --threads ${threads} -m "$models_path/ggml-${model}.bin" -otxt -osrt -f "$input_wav" -of "$output_name" --print-colors --print-progress + error=$? if [[ error -eq 0 ]]; then printf "${GREEN}${BOLD}Done transcribing $input_wav | model: $model | cores: $cores | threads: $threads | output: $output_name${NORMAL}\n"