Compare commits
8 Commits
1be4719212
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| fe531b185f | |||
| e009688aa0 | |||
| bade7f762a | |||
|
01edb8f277
|
|||
| 1474e23aea | |||
| 08ed0a411d | |||
| 9fb52326f9 | |||
| 56e4ad3386 |
102
.aliases
102
.aliases
@@ -41,7 +41,7 @@ reload() {
|
||||
}
|
||||
|
||||
update-shell() {
|
||||
if [[ '${platform,,}' == *'ming'* ]]; then
|
||||
if [[ ${platform,,} == *'ming'* ]]; then
|
||||
pacman -Syu
|
||||
printf "\n${BOLD}${YELLOW}Close this shell, open a new one, and then run 'pacman -Su'${NORMAL}\n"
|
||||
fi
|
||||
@@ -124,6 +124,20 @@ open_explorer() {
|
||||
fi
|
||||
}
|
||||
|
||||
open_filepilot() {
|
||||
local target="$1"
|
||||
if [[ $target == "" ]]; then
|
||||
target="$PWD"
|
||||
fi
|
||||
local path_expanded=$(expand_path "$target")
|
||||
if [[ -d $path_expanded ]]; then
|
||||
local path=$(unix_to_windows_path "$path_expanded")
|
||||
start fpilot.exe "$path"
|
||||
else
|
||||
echo "Folder no longer exists"
|
||||
fi
|
||||
}
|
||||
|
||||
remove_extra_spaces() {
|
||||
# Replace consecutive spaces with a single space.
|
||||
#
|
||||
@@ -134,6 +148,30 @@ remove_extra_spaces() {
|
||||
echo "$ret"
|
||||
}
|
||||
|
||||
flash_taskbar() {
|
||||
if [[ ${platform,,} == *'ming'* ]]; then
|
||||
powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "
|
||||
\$h = (Get-Process mintty -EA SilentlyContinue | ? MainWindowHandle | select -First 1).MainWindowHandle
|
||||
if (-not \$h) { exit }
|
||||
|
||||
Add-Type -TypeDefinition 'using System; using System.Runtime.InteropServices;
|
||||
public static class F {
|
||||
[StructLayout(LayoutKind.Sequential)] public struct I { public uint cb; public IntPtr h; public uint f; public uint c; public uint t; }
|
||||
[DllImport(\"user32.dll\")] public static extern bool FlashWindowEx(ref I i);
|
||||
}'
|
||||
\$i = New-Object F+I
|
||||
\$i.cb = [Runtime.InteropServices.Marshal]::SizeOf(\$i)
|
||||
\$i.h = [IntPtr]\$h
|
||||
\$i.f = 2 -bor 12
|
||||
\$i.c = 0
|
||||
\$i.t = 0
|
||||
[F]::FlashWindowEx([ref]\$i) | Out-Null
|
||||
"
|
||||
else
|
||||
echo "flash_taskbar not implemented for this platform"
|
||||
fi
|
||||
}
|
||||
|
||||
##################
|
||||
# Building code
|
||||
##################
|
||||
@@ -184,7 +222,7 @@ if [[ $platform == 'Darwin' ]]; then
|
||||
alias trash='rmtrash'
|
||||
alias tt='rmtrash'
|
||||
|
||||
elif [[ "${platform,,}" == *'ming'* ]]; then # convert to lowercase then compare with wildcard
|
||||
elif [[ ${platform,,} == *'ming'* ]]; then # convert to lowercase then compare with wildcard
|
||||
#alias rm='echo "use trash command instead!"'
|
||||
#alias rmr='echo "use trash command instead!"'
|
||||
alias trash='remove_windows_file'
|
||||
@@ -212,17 +250,19 @@ mkcd() {
|
||||
alias aliases='vim ~/.aliases'
|
||||
alias al='aliases'
|
||||
|
||||
if [[ "${platform,,}" == *'ming'* ]]; then
|
||||
if [[ ${platform,,} == *'ming'* ]]; then
|
||||
_checksum() {
|
||||
local algo="$1"
|
||||
local file="$2"
|
||||
certutil -hashfile $file $algo
|
||||
certutil -hashfile "$file" $algo
|
||||
}
|
||||
alias checksum='certutil -hashfile'
|
||||
alias checksum-md5='_checksum MD5'
|
||||
alias checksum-sha1='_checksum SHA1'
|
||||
alias checksum-sha256='_checksum SHA256'
|
||||
alias checksum-sha512='_checksum SHA512'
|
||||
|
||||
# I use delegating to certutil via _checksum() but these programs are faster.
|
||||
alias checksum-md5='md5sum.exe'
|
||||
alias checksum-sha1='sha1sum.exe'
|
||||
alias checksum-sha256='sha256sum.exe'
|
||||
alias checksum-sha512='sha512sum.exe'
|
||||
fi
|
||||
|
||||
check_signature() {
|
||||
@@ -264,7 +304,6 @@ dos2unix_all() {
|
||||
alias d2u='dos2unix_all'
|
||||
|
||||
alias e='open_explorer'
|
||||
alias exp='echo "Use e instead."'
|
||||
alias f='fg'
|
||||
alias hist='history'
|
||||
alias histroy='history'
|
||||
@@ -397,6 +436,7 @@ function my_transcribe_video() {
|
||||
else
|
||||
transcribe-video "$file" "$output" $start_time $end_time tiny base
|
||||
fi
|
||||
flash_taskbar
|
||||
}
|
||||
|
||||
function my_transcribe_video_all_models() {
|
||||
@@ -418,6 +458,7 @@ function my_transcribe_video_all_models() {
|
||||
if [[ $end_time == "" ]]; then end_time="0"; fi
|
||||
|
||||
transcribe-video "$file" "$output" $start_time $end_time tiny base small medium
|
||||
flash_taskbar
|
||||
}
|
||||
|
||||
|
||||
@@ -494,6 +535,7 @@ download_youtube_vid() {
|
||||
if [[ $make_folder == "1" ]]; then cd ..; fi
|
||||
|
||||
printf "${BOLD}Finished downloading ${YELLOW}$filename${NORMAL}\n"
|
||||
flash_taskbar
|
||||
}
|
||||
|
||||
|
||||
@@ -515,9 +557,6 @@ download_youtube_playlist() {
|
||||
return
|
||||
fi
|
||||
|
||||
printf "${BOLD}${RED}USING TEMP FIX FOR YOUTUBE FORMAT ISSUES BY SETTING THE CLIENT TO tv_simply. SEE https://github.com/yt-dlp/yt-dlp/issues/13930\n\n${NORMAL}"
|
||||
opts+=" --extractor-args youtube:player-client=default,tv_simply"
|
||||
|
||||
printf "${BOLD}Downloading Youtube playlist\n\n${NORMAL}"
|
||||
|
||||
if [[ $format == "" ]]; then
|
||||
@@ -543,6 +582,7 @@ download_youtube_playlist() {
|
||||
cd ..
|
||||
|
||||
printf "${BOLD}Finished downloading the playlist\n${NORMAL}"
|
||||
flash_taskbar
|
||||
}
|
||||
|
||||
download_youtube_playlist_list() {
|
||||
@@ -562,6 +602,7 @@ download_youtube_playlist_list() {
|
||||
eval $cmd 1>"${output_name}.txt" # Need to eval in order to preserve the quotes wrapping the filename format string.
|
||||
|
||||
printf "${BOLD}Finished downloading the playlist video list\n${NORMAL}"
|
||||
flash_taskbar
|
||||
}
|
||||
|
||||
download_youtube_uploads_list() {
|
||||
@@ -590,6 +631,7 @@ download_youtube_uploads_list() {
|
||||
eval $cmd 1>"${output_name}.txt" # Need to eval in order to preserve the quotes wrapping the filename format string.
|
||||
|
||||
printf "${BOLD}Finished downloading the upload list\n${NORMAL}"
|
||||
flash_taskbar
|
||||
}
|
||||
|
||||
function download_youtube_audio() {
|
||||
@@ -603,9 +645,6 @@ function download_youtube_audio() {
|
||||
return
|
||||
fi
|
||||
|
||||
printf "${BOLD}${RED}USING TEMP FIX FOR YOUTUBE FORMAT ISSUES BY SETTING THE CLIENT TO tv_simply. SEE https://github.com/yt-dlp/yt-dlp/issues/13930\n\n${NORMAL}"
|
||||
opts+=" --extractor-args youtube:player-client=default,tv_simply"
|
||||
|
||||
printf "${BOLD}Downloading Youtube audio\n\n${NORMAL}"
|
||||
|
||||
if [[ $make_folder == "1" ]]; then
|
||||
@@ -637,6 +676,7 @@ function download_youtube_audio() {
|
||||
if [[ $make_folder == "1" ]]; then cd ..; fi
|
||||
|
||||
printf "${BOLD}Finished downloading ${YELLOW}$filename${NORMAL}\n"
|
||||
flash_taskbar
|
||||
}
|
||||
|
||||
# Download Twitch chat transcript
|
||||
@@ -690,9 +730,13 @@ download_twitch_chat() {
|
||||
# To extract a portion of a video, you have to first download the entire file and then use the
|
||||
# `trim-video` or `compress-video' with a time range.
|
||||
#
|
||||
# To download the portion of a stream:
|
||||
# To download a partial stream use one of these commands. We need to reencode to remove extra frames from the start/end with a negative timeline.
|
||||
#
|
||||
# yt-dlp -f "b" --external-downloader ffmpeg --external-downloader-args "ffmpeg_i:-ss 5:25:38.00 -to 5:56:50.00" URL
|
||||
# This reencodes during the download, slightly faster than the next option:
|
||||
# yt-dlp -f "b" --external-downloader ffmpeg --external-downloader-args "ffmpeg_i:-ss 0:7:10.00 -to 0:8:06.00" --external-downloader-args "ffmpeg_o:-c:v libx264 -c:a aac" URL
|
||||
#
|
||||
# Download then re-encode:
|
||||
# yt-dlp -f "b" --external-downloader ffmpeg --external-downloader-args "ffmpeg_i:-ss 5:25:38.00 -to 5:56:50.00" URL -o temp.mp4 ; trim-video-cpu temp.mp4 "FINAL_NAME" 0
|
||||
#
|
||||
download_twitch_vid() {
|
||||
local format="$1"
|
||||
@@ -803,6 +847,7 @@ download_twitch_vid() {
|
||||
if [[ $make_folder == "1" ]]; then cd ..; fi
|
||||
|
||||
printf "${BOLD}Finished downloading ${YELLOW}$filename${NORMAL}\n"
|
||||
flash_taskbar
|
||||
}
|
||||
|
||||
# Download Vimeo videos.
|
||||
@@ -889,6 +934,7 @@ download_vimeo_vid() {
|
||||
if [[ $make_folder == "1" ]]; then cd ..; fi
|
||||
|
||||
printf "${BOLD}Finished downloading ${YELLOW}$filename${NORMAL}\n"
|
||||
flash_taskbar
|
||||
}
|
||||
|
||||
# Download Twitter videos.
|
||||
@@ -957,9 +1003,12 @@ download_twitter_vid() {
|
||||
if [[ $make_folder == "1" ]]; then cd ..; fi
|
||||
|
||||
printf "${BOLD}Finished downloading ${YELLOW}$filename${NORMAL}\n"
|
||||
flash_taskbar
|
||||
}
|
||||
|
||||
# Download Instagram videos.
|
||||
# If the download fails because you need to be authenticated then don't use the cookies arg because IG will flag your
|
||||
# account as a bot and might ban you. Instead, use the instagram download code from private dotfiles.
|
||||
download_instagram_vid() {
|
||||
local transcribe="$1"
|
||||
local make_folder="$2"
|
||||
@@ -1028,6 +1077,7 @@ download_instagram_vid() {
|
||||
if [[ $make_folder == "1" ]]; then cd ..; fi
|
||||
|
||||
printf "${BOLD}Finished downloading ${YELLOW}$filename${NORMAL}\n"
|
||||
flash_taskbar
|
||||
}
|
||||
|
||||
# Download MP4 video.
|
||||
@@ -1051,6 +1101,7 @@ download_mp4() {
|
||||
fi
|
||||
|
||||
mv $temp_name "$filename.mp4"
|
||||
flash_taskbar
|
||||
}
|
||||
|
||||
# Download a stream to mp4. Can be from an m3u8 file, an mpd, etc. Whatever the
|
||||
@@ -1087,6 +1138,7 @@ download_mp4_from_stream() {
|
||||
fi
|
||||
|
||||
printf "${BOLD}Finished downloading ${YELLOW}$filename${NORMAL}\n"
|
||||
flash_taskbar
|
||||
}
|
||||
|
||||
# Same notes from above regarding cookies/headers.
|
||||
@@ -1108,6 +1160,7 @@ download_aac_from_stream() {
|
||||
fi
|
||||
|
||||
printf "${BOLD}Finished downloading ${YELLOW}$filename${NORMAL}\n"
|
||||
flash_taskbar
|
||||
}
|
||||
|
||||
|
||||
@@ -1131,8 +1184,8 @@ alias yt-1440-shortname='download_youtube_vid "620+234" $SHORTNAME_OFF $TRANSC
|
||||
alias yt-1080p='download_youtube_vid "616+234" $SHORTNAME_OFF $TRANSCRIBE_OFF'
|
||||
alias yt-1080p-shortname='download_youtube_vid "616+234" $SHORTNAME_ON $TRANSCRIBE_OFF'
|
||||
# Normal
|
||||
alias yt-1080='download_youtube_vid "270+234" $SHORTNAME_OFF $TRANSCRIBE_OFF'
|
||||
alias yt-1080-shortname='download_youtube_vid "270+234" $SHORTNAME_ON $TRANSCRIBE_OFF'
|
||||
alias yt-1080='download_youtube_vid "137+ba[ext=m4a]" $SHORTNAME_OFF $TRANSCRIBE_OFF'
|
||||
alias yt-1080-shortname='download_youtube_vid "137+ba[ext=m4a]" $SHORTNAME_ON $TRANSCRIBE_OFF'
|
||||
|
||||
alias yt-720='download_youtube_vid "136+234" $SHORTNAME_OFF $TRANSCRIBE_OFF'
|
||||
alias yt-720-shortname='download_youtube_vid "136+234" $SHORTNAME_ON $TRANSCRIBE_OFF'
|
||||
@@ -1278,11 +1331,13 @@ alias tv='echo can just do a cv with a time range...' #trim-video-vbr'
|
||||
|
||||
function compress_and_normalize_volume() {
|
||||
local final_name="$1"
|
||||
shift 1
|
||||
local opts="$@"
|
||||
if [[ $final_name == "" ]]; then
|
||||
error "Provide a final file name"
|
||||
error "Provide a final file name and optional args for compress-video"
|
||||
return
|
||||
fi
|
||||
compress-video f.mp4 ff ; normalize-volume ff.mp4 "$final_name"
|
||||
compress-video f.mp4 ff $opts ; normalize-volume ff.mp4 "$final_name" ; flash_taskbar
|
||||
}
|
||||
|
||||
alias cvn='compress_and_normalize_volume'
|
||||
@@ -1291,7 +1346,7 @@ alias cvn='compress_and_normalize_volume'
|
||||
# Git
|
||||
####################################################################################################
|
||||
|
||||
if [[ '${platform,,}' == *'ming'* ]]; then
|
||||
if [[ ${platform,,} == *'ming'* ]]; then
|
||||
# Fix a weird mingw 'not a valid identifierline' error.
|
||||
# Got the fix from https://github.com/Alexpux/MSYS2-packages/issues/735#issuecomment-328938800
|
||||
alias git="PATH=/usr/bin git"
|
||||
@@ -1402,8 +1457,11 @@ alias gf='git fetch'
|
||||
alias gfa='git fetch --all'
|
||||
alias gfd='git fetch --prune' # Removes remote branches that don't have a counterpart branch on the remote.
|
||||
alias gfix='git commit --amend -C HEAD'
|
||||
alias gfx='git commit --amend -C HEAD'
|
||||
alias gfixs='git commit -S -a --amend -C HEAD' # signed
|
||||
alias gfxs='git commit -S -a --amend -C HEAD' # signed
|
||||
alias gfixno='git_fix_nocheckin'
|
||||
alias gfxno='git_fix_nocheckin'
|
||||
alias gfo='git fetch origin'
|
||||
alias gfu='git fetch up'
|
||||
alias gfm='git fetch origin master'
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
[include]
|
||||
path = ~/.gitconfig.private
|
||||
# Shared config from private dotfiles
|
||||
path = ~/.private-dotfiles.common/gitconfig
|
||||
# Computer-specific config from private dotfiles (might not exist)
|
||||
path = ~/.private-dotfiles/gitconfig
|
||||
[init]
|
||||
defaultBranch = master
|
||||
[merge]
|
||||
summary = true
|
||||
tool = vimdiff
|
||||
[core]
|
||||
excludesfile = ~/.gitignore.global
|
||||
excludesfile = ~/.private-dotfiles.common/gitignore
|
||||
hookspath = ~/.git_hooks
|
||||
preloadindex = true
|
||||
fscache = true
|
||||
|
||||
6
.vimrc
6
.vimrc
@@ -1555,11 +1555,9 @@ fu! Search(path, search_args, case_insensitive=0, token="")
|
||||
|
||||
" Some characters need to be escaped.
|
||||
let l:escaped_term = substitute(l:term, '[#%]', '\\\\\\&', 'g')
|
||||
let l:escaped_path = substitute(a:path, '[#%]', '\\\\\\&', 'g')
|
||||
|
||||
let l:format = 'Rg ' . l:rg_args . ' ' . a:path . ' -e %s'
|
||||
let l:cmd = printf(l:format, shellescape(l:escaped_term))
|
||||
|
||||
exec l:cmd
|
||||
exec printf("Rg " . l:rg_args . " %s -e %s", shellescape(l:escaped_path), shellescape(l:escaped_term))
|
||||
|
||||
call ConvertQuickfixPathsToUnixSlashes()
|
||||
endfu
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#
|
||||
# Inspired by https://superuser.com/a/323127 and https://superuser.com/a/1312885
|
||||
|
||||
source "$HOME/dotfiles/script_helpers/windows.sh"
|
||||
|
||||
if which tput >/dev/null 2>&1; then
|
||||
ncolors=$(tput colors)
|
||||
fi
|
||||
@@ -50,3 +52,4 @@ eval $cmd
|
||||
printf "\n${GREEN}${BOLD}Done analyzing audio in $filename\n${NORMAL}"
|
||||
printf "\n${YELLOW}${BOLD}Look at the reported max_volume value. If != 0 then call the change-volume script, passing it the filename, an output name and the delta to bring the volume to 0.\ne.g. if the max_volume is -5 db, then you would pass 5.${NORMAL}\n\n"
|
||||
|
||||
flash_taskbar
|
||||
|
||||
@@ -1,22 +1,32 @@
|
||||
@setlocal enableextensions enabledelayedexpansion
|
||||
@echo off
|
||||
|
||||
rem Make sure we're running as admin. Got this garbage from https://stackoverflow.com/a/40388766
|
||||
if not "%1"=="am_admin" (
|
||||
powershell -Command "Start-Process -Verb RunAs -FilePath '%0' -ArgumentList 'am_admin'"
|
||||
exit /b
|
||||
)
|
||||
setlocal enableextensions enabledelayedexpansion
|
||||
|
||||
rem NOTE: Defender may see this file as malware, so you might need to exclude this before things can be disabled.
|
||||
rem
|
||||
rem Modified version of
|
||||
rem https://raw.githubusercontent.com/mattreecebentley/win10_disable_defender/main/win10_enable_defender.bat
|
||||
rem https://gist.github.com/xezrunner/a7a42dbc1096a40b0c78f09488fe5a2b
|
||||
|
||||
rem Modified version of:
|
||||
rem https://github.com/ggannann/win10_disable_defender
|
||||
rem https://gist.github.com/xezrunner/a7a42dbc1096a40b0c78f09488fe5a2b (as of Jan 2026 this seems to have been deleted or made private)
|
||||
|
||||
rem ============================
|
||||
rem Self-elevate via UAC if needed
|
||||
rem - Detect admin by checking membership in Administrators (SID S-1-5-32-544)
|
||||
rem - Relaunch this script elevated using PowerShell Start-Process -Verb RunAs
|
||||
rem ============================
|
||||
rem Test for membership in Administrators group
|
||||
whoami /groups | find "S-1-5-32-544" >nul
|
||||
if errorlevel 1 (
|
||||
echo Requesting administrative privileges...
|
||||
rem Relaunch the same script elevated, preserving args and working directory
|
||||
powershell -NoProfile -Command ^
|
||||
"Start-Process -FilePath '%~f0' -ArgumentList '%*' -Verb RunAs -WorkingDirectory (Get-Location).Path"
|
||||
exit /b
|
||||
)
|
||||
echo Running with administrative privileges.
|
||||
echo.
|
||||
|
||||
reg query HKLM\SYSTEM\Setup /v DisabledDefenderServices | find "0x1"
|
||||
if %errorlevel% == 0 goto already_patched
|
||||
|
||||
echo.
|
||||
echo Please note that Defender can only be disabled in Win10 v2004 and upwards if Tamper Protection is disabled.
|
||||
echo This setting can be found in Window settings (hint: search for 'tamper'). Please do this now and then,
|
||||
pause
|
||||
@@ -104,3 +114,4 @@ echo Defender has already been disabled by this script.
|
||||
:eof
|
||||
echo.
|
||||
pause
|
||||
|
||||
|
||||
@@ -1,17 +1,11 @@
|
||||
@setlocal enableextensions enabledelayedexpansion
|
||||
@echo off
|
||||
setlocal enableextensions enabledelayedexpansion
|
||||
|
||||
rem Make sure we're running as admin. Got this garbage from https://stackoverflow.com/a/40388766
|
||||
if not "%1"=="am_admin" (
|
||||
powershell -Command "Start-Process -Verb RunAs -FilePath '%0' -ArgumentList 'am_admin'"
|
||||
exit /b
|
||||
)
|
||||
rem NOTE: Defender may see this file as malware, so you might need to exclude this before things can be disabled.
|
||||
|
||||
rem USE AT OWN RISK AS IS WITHOUT WARRANTY OF ANY KIND !!!!!
|
||||
rem
|
||||
rem Modified version of
|
||||
rem https://raw.githubusercontent.com/mattreecebentley/win10_disable_defender/main/win10_enable_defender.bat
|
||||
rem https://gist.github.com/xezrunner/a7a42dbc1096a40b0c78f09488fe5a2b
|
||||
rem Modified version of:
|
||||
rem https://github.com/ggannann/win10_disable_defender
|
||||
rem https://gist.github.com/xezrunner/a7a42dbc1096a40b0c78f09488fe5a2b (as of Jan 2026 this seems to have been deleted or made private)
|
||||
rem
|
||||
rem Resources:
|
||||
rem https://docs.microsoft.com/en-us/powershell/module/defender/set-mppreference?view=win10-ps
|
||||
@@ -19,7 +13,23 @@ rem https://docs.microsoft.com/en-us/windows/threat-protection/windows-defender-
|
||||
rem https://github.com/AndyFul/ConfigureDefender
|
||||
rem https://github.com/AndyFul/Hard_Configurator
|
||||
|
||||
rem ============================
|
||||
rem Self-elevate via UAC if needed
|
||||
rem - Detect admin by checking membership in Administrators (SID S-1-5-32-544)
|
||||
rem - Relaunch this script elevated using PowerShell Start-Process -Verb RunAs
|
||||
rem ============================
|
||||
rem Test for membership in Administrators group
|
||||
whoami /groups | find "S-1-5-32-544" >nul
|
||||
if errorlevel 1 (
|
||||
echo Requesting administrative privileges...
|
||||
rem Relaunch the same script elevated, preserving args and working directory
|
||||
powershell -NoProfile -Command ^
|
||||
"Start-Process -FilePath '%~f0' -ArgumentList '%*' -Verb RunAs -WorkingDirectory (Get-Location).Path"
|
||||
exit /b
|
||||
)
|
||||
echo Running with administrative privileges.
|
||||
echo.
|
||||
|
||||
echo Enabling Windows Defender
|
||||
reg query HKLM\SYSTEM\Setup /v DisabledDefenderServices | find "0x0"
|
||||
if %errorlevel% == 0 goto already_patched
|
||||
@@ -106,3 +116,4 @@ echo Defender has already been enabled by this script.
|
||||
:eof
|
||||
echo.
|
||||
pause
|
||||
|
||||
|
||||
72
dotfiles/bin/aws-check-restore-status
Normal file
72
dotfiles/bin/aws-check-restore-status
Normal file
@@ -0,0 +1,72 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Shows you the status of an object restore job.
|
||||
#
|
||||
# e.g. aws-check-restore-status my-deep-glacier-bucket object/path.png
|
||||
#
|
||||
# You know it's ready when ongoing-request is false and there's a date. If that field is null then the file isn't being restored.
|
||||
#
|
||||
# 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 <undefined>" 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
|
||||
if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then
|
||||
RED="$(tput setaf 1)"
|
||||
GREEN="$(tput setaf 2)"
|
||||
YELLOW="$(tput setaf 3)"
|
||||
BLUE="$(tput setaf 4)"
|
||||
MAGENTA="$(tput setaf 5)"
|
||||
CYAN="$(tput setaf 6)"
|
||||
BOLD="$(tput bold)"
|
||||
NORMAL="$(tput sgr0)"
|
||||
else
|
||||
RED=""
|
||||
GREEN=""
|
||||
YELLOW=""
|
||||
BLUE=""
|
||||
MAGENTA=""
|
||||
CYAN=""
|
||||
BOLD=""
|
||||
NORMAL=""
|
||||
fi
|
||||
|
||||
error() {
|
||||
printf "${BOLD}${RED}$1${NORMAL}\n"
|
||||
}
|
||||
|
||||
abort() {
|
||||
error "\nAborting...\n"
|
||||
exit 1
|
||||
}
|
||||
|
||||
set -e
|
||||
|
||||
bucket="$1"
|
||||
path="$2"
|
||||
|
||||
if [[ $bucket == "" || $path == "" ]]; then
|
||||
error "Usage: aws-check-restore-status <bucket-name> <path-in-bucket>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
aws s3api head-object --bucket $bucket --key "$path" --query "{Restore:Restore, StorageClass:StorageClass}" --output json
|
||||
@@ -52,11 +52,6 @@ error() {
|
||||
printf "${BOLD}${RED}$1${NORMAL}\n"
|
||||
}
|
||||
|
||||
abort() {
|
||||
error "\nAborting...\n"
|
||||
exit 1
|
||||
}
|
||||
|
||||
set -e
|
||||
|
||||
bucket="$1"
|
||||
@@ -68,4 +63,24 @@ if [[ $bucket == "" || $path == "" || $output_file == "" ]]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
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' > "$output_file"
|
||||
# .Key gives us just the object paths. If you want the other metadata then remove that from the query.
|
||||
|
||||
items="$(aws s3api list-objects-v2 --bucket $bucket --prefix "$path" --query "Contents[?StorageClass=='DEEP_ARCHIVE'].Key" --output text | tr '\t' '\n' | tr -d '\r')"
|
||||
|
||||
error=$?
|
||||
if [[ ! $error -eq 0 ]]; then
|
||||
error "Error: failed to run the aws command. Aborting."
|
||||
exit 1
|
||||
fi
|
||||
if [[ $items == "None" ]]; then
|
||||
error "Didn't find any files. Check that your bucket name and path is correct."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mapfile -t lines_array <<< "$items"
|
||||
item_count="${#lines_array[@]}"
|
||||
|
||||
echo "$items" > "$output_file"
|
||||
|
||||
printf "Number of items: ${BOLD}${YELLOW}$item_count${NORMAL}\n"
|
||||
printf "Wrote file list to ${BOLD}${YELLOW}$output_file${NORMAL}\n"
|
||||
|
||||
@@ -1,28 +1,44 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Restores all objects recursively from a specific bucket path. If want to
|
||||
# restore objects from an rclone crypt (encrypted remote), then you'll need to
|
||||
# do some manual steps first. See the `# Rclone Crypt` section for details.
|
||||
#
|
||||
# Restores all files/folders inside a particular bucket path for the next 7 days. This uses the bulk retrieval tier:
|
||||
# You can set how long restore files are available for download and the AWS
|
||||
# retrieval tier. The defaults are 7 days and the bulk tier respectively.
|
||||
#
|
||||
# Available tiers: bulk, standard, and expedited.
|
||||
#
|
||||
# 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.
|
||||
# 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
|
||||
# aws-restore-deep-glacier-folder my-deep-glacier-bucket path/to/images restored_images 14 expedited
|
||||
#
|
||||
# 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.
|
||||
# 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 from the
|
||||
# my-deep-glacier bucket. Restored objects will be available for 14 days and
|
||||
# retrieved using the expedited tier.
|
||||
#
|
||||
# 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:
|
||||
# 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
|
||||
# aws s3api head-object --bucket my-deep-glacier-bucket --key "path/to/images/photo1.jpg" --query "{Restore:Restore, StorageClass:StorageClass}"
|
||||
#
|
||||
# (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.
|
||||
# Or use the aws-check-restore-status script.
|
||||
# You know it's ready when ongoing-request is false and there's a date. If that
|
||||
# field is null then the file isn't being restored.
|
||||
#
|
||||
# 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.
|
||||
@@ -44,6 +60,67 @@
|
||||
# You can enable the UTF-8 locale with:
|
||||
#
|
||||
# win+r -> intl.cpl -> Administrative tab -> Change system locale -> Beta: Use Unicode UTF-8 box.
|
||||
|
||||
##########################
|
||||
# Rclone Crypt
|
||||
##########################
|
||||
#
|
||||
# To restore an rclone crypt, you need to first find the encrypted name that
|
||||
# maps to the parent folder or the file you want to restore. To do this you
|
||||
# need to use rclone. There are two ways to go about this.
|
||||
#
|
||||
# 1. The simple way is to use `cryptdecode` to convert your object path to its
|
||||
# encrypted form.
|
||||
#
|
||||
# For example, say you have an rclone crypt called `s3-deep-glacier-encrypted`
|
||||
# that is stored in S3 at `my-deep-glacier-bucket:encrypted/` You have a folder
|
||||
# called `dev/fonts` that you want to restore. To get its path, run the following
|
||||
# command:
|
||||
#
|
||||
# rclone cryptdecode --reverse s3-deep-glacier-encrypted: dev/fonts
|
||||
#
|
||||
# This will give you the encrypted path, e.g. "44ildo3grlk44jmfr96nb5r56o/oatuh75ej3l4re96nvq2qbj8ik"
|
||||
#
|
||||
# You can now restore this by running:
|
||||
#
|
||||
# aws-restore-deep-glacier-folder my-deep-glacier-bucket 44ildo3grlk44jmfr96nb5r56o/oatuh75ej3l4re96nvq2qbj8ik restore_dev_fonts
|
||||
#
|
||||
# You should be able to simply download the dev/fonts folder after its
|
||||
# restored. The easiest way is using rclone browser because it'll decrypt them
|
||||
# for you. Alternatively you can download the encrypted files using whatever
|
||||
# method you want and then decrypt them locally with rclone.
|
||||
#
|
||||
# 2. You can also get the encrypted names by enabling the 'show_mapping' option
|
||||
# in the rclone remote config. This will log the encrytped names of folders and
|
||||
# files with the original name in the same log line. This makes it easy to
|
||||
# parse the output.
|
||||
#
|
||||
# To enable the option, edit your rclone config, edit the remote you want to
|
||||
# restore from, edit the advanced config and set `show_mapping` to true.
|
||||
#
|
||||
# Now you can list the directories and files with rclone and get the mapping
|
||||
# output on stderr. e.g. let's capture all folders and files in a txt file:
|
||||
#
|
||||
# rclone lsf s3-deep-glacier-encrypted: -R &> keys.txt
|
||||
#
|
||||
# If your rclone config has password protection then you'll be prompted for it
|
||||
# but won't see the output since it's being written to the file. Just paste it
|
||||
# and hit enter.
|
||||
#
|
||||
# Now you have a listing of all objects and the encrypted keys that they map
|
||||
# to. If you want to scope the output to a specific path in the crypt then add
|
||||
# it after the remote name, e.g. `s3-deep-glacier-encrypted:dev/fonts`
|
||||
#
|
||||
# If you scope it like that then be aware that the output won't contain the
|
||||
# mapping for the parent path, i.e. `dev/fonts`, but you can get that using
|
||||
# `cryptdecode` (see above) or with some non-recursive outputs of the parent
|
||||
# parts using `lsd`, e.g.
|
||||
#
|
||||
# // First call will include the dev/ key
|
||||
# rclone lsd s3-deep-glacier-encrypted:
|
||||
#
|
||||
# // Second call has the fonts key
|
||||
# rclone lsd s3-deep-glacier-encrypted:dev
|
||||
#
|
||||
|
||||
if which tput >/dev/null 2>&1; then
|
||||
@@ -73,57 +150,177 @@ error() {
|
||||
printf "${BOLD}${RED}$1${NORMAL}\n"
|
||||
}
|
||||
|
||||
abort() {
|
||||
error "\nAborting...\n"
|
||||
exit 1
|
||||
}
|
||||
|
||||
set -e
|
||||
|
||||
bucket="$1"
|
||||
path="$2"
|
||||
temp_dir="$3"
|
||||
number_of_objects_per_file=100
|
||||
days_available=7
|
||||
restore_tier="Bulk" # Can also be "Standard" or "Expedited"
|
||||
restore_tier="bulk" # Can also be "standard" or "expedited"
|
||||
|
||||
if [[ $bucket == "" || $path == "" || $temp_dir == "" ]]; then
|
||||
error "Usage: aws-restore-deep-glacier-folder <bucket-name> <path-in-bucket> <local-temp-dir>"
|
||||
error "Usage: aws-restore-deep-glacier-folder <bucket-name> <path-in-bucket> <local-temp-dir> <optional: days available> <optional: restore tier>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf "Restoring ${BOLD}${GREEN}$bucket:$path${NORMAL} with local temp folder ${BOLD}${GREEN}$temp_dir${NORMAL}\n"
|
||||
# Get the days available.
|
||||
if [[ $4 != "" ]]; then
|
||||
days_available=$4
|
||||
fi
|
||||
|
||||
# Get the restore tier.
|
||||
if [[ $5 != "" ]]; then
|
||||
restore_tier="$5"
|
||||
fi
|
||||
if ! grep -qiE '\b(bulk|standard|expedited)\b' <<<"$restore_tier"; then
|
||||
error "Restore tier is invalid. Accepted values is \"bulk\", \"standard\" and \"expedited\""
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Normalize the tier; lowercase it then capitalize the first character.
|
||||
restore_tier="${restore_tier,,}"
|
||||
restore_tier="${restore_tier^}"
|
||||
|
||||
printf "Restoring ${BOLD}${YELLOW}$bucket:$path${NORMAL} for ${BOLD}${YELLOW}$days_available${NORMAL} days using the ${BOLD}${YELLOW}\"$restore_tier\"${NORMAL} restore tier.\nSaving the restoration script in ${BOLD}${YELLOW}$temp_dir${NORMAL}\n"
|
||||
|
||||
mkdir -p "$temp_dir"
|
||||
pushd "$temp_dir" &>/dev/null
|
||||
|
||||
items="$(aws s3api list-objects-v2 --bucket $bucket --prefix $path --query "Contents[?StorageClass=='DEEP_ARCHIVE']" --output text)"
|
||||
# .Key gives us just the object paths. If you want the other metadata then remove that from the query.
|
||||
items="$(aws s3api list-objects-v2 --bucket $bucket --prefix "$path" --query "Contents[?StorageClass=='DEEP_ARCHIVE'].Key" --output text | tr '\t' '\n' | tr -d '\r')"
|
||||
|
||||
error=$?
|
||||
if [[ ! $error -eq 0 ]]; then
|
||||
error "Error: failed to run the aws command. Aborting."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ $items == "None" ]]; then
|
||||
error "Didn't find any files. Check that your bucket name and path is correct."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Format the items list.
|
||||
output="$(echo "$items" | LC_ALL=C awk '{print substr($0, index($0, $2))}' | awk '{NF-=3};3')"
|
||||
|
||||
mapfile -t lines_array <<< "$output"
|
||||
num_items="${#lines_array[@]}"
|
||||
|
||||
printf "Number of items to restore: ${BOLD}${YELLOW}$num_items${NORMAL}\n"
|
||||
printf "${BOLD}${RED}Proceed?\n> ${NORMAL}"
|
||||
read -e proceed
|
||||
if [[ $proceed == "1" || $proceed == "y" || $proceed == "Y" || $proceed == "yes" || $proceed == "YES" ]]; then
|
||||
echo "$output" > all_objects_list.txt
|
||||
mapfile -t lines_array <<< "$items"
|
||||
item_count="${#lines_array[@]}"
|
||||
|
||||
# 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.\\\\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
|
||||
printf "Number of items to restore: ${BOLD}${YELLOW}$item_count${NORMAL}\n"
|
||||
printf "${BOLD}${RED}Create the restore script?\n> ${NORMAL}"
|
||||
|
||||
read -e proceed
|
||||
if [[ $proceed == "1" || $proceed == "y" || $proceed == "Y" || $proceed == "yes" || $proceed == "YES" ]]; then
|
||||
echo "$items" > all_objects_list.txt
|
||||
|
||||
RUN_TEMPLATE=$(cat <<EOF
|
||||
if which tput >/dev/null 2>&1; then
|
||||
ncolors=\$(tput colors)
|
||||
fi
|
||||
if [ -t 1 ] && [ -n "\$ncolors" ] && [ "\$ncolors" -ge 8 ]; then
|
||||
RED="\$(tput setaf 1)"
|
||||
GREEN="\$(tput setaf 2)"
|
||||
YELLOW="\$(tput setaf 3)"
|
||||
BLUE="\$(tput setaf 4)"
|
||||
MAGENTA="\$(tput setaf 5)"
|
||||
CYAN="\$(tput setaf 6)"
|
||||
BOLD="\$(tput bold)"
|
||||
NORMAL="\$(tput sgr0)"
|
||||
else
|
||||
RED=""
|
||||
GREEN=""
|
||||
YELLOW=""
|
||||
BLUE=""
|
||||
MAGENTA=""
|
||||
CYAN=""
|
||||
BOLD=""
|
||||
NORMAL=""
|
||||
fi
|
||||
|
||||
# Open an output file.
|
||||
exec 3>>output.txt
|
||||
|
||||
fail_count=0
|
||||
failed_filename="failed_keys_\$(printf '%%04x' \$((RANDOM * RANDOM))).txt"
|
||||
|
||||
before_sleep_count=0
|
||||
sleep_every_n_requests=25
|
||||
sleep_duration=0.2
|
||||
|
||||
printf "Files are being restored for $days_available days using the $restore_tier tier\\\n\\\n"
|
||||
printf "Files are being restored for $days_available days using the $restore_tier tier\\\n\\\n" >&3
|
||||
|
||||
printf "\${BOLD}NOTE: Request failures will be saved to \${YELLOW}\$failed_filename\${NORMAL}\${BOLD} as they happen. If this script terminates prematurely then check this file for failures.\\\n\\\n"
|
||||
printf "NOTE: Request failures will be saved to \$failed_filename as they happen. If this script terminates prematurely then check this file for failures.\\\n\\\n" >&3
|
||||
|
||||
index=1
|
||||
while read key; do
|
||||
printf "* [\$index/$item_count] \${BOLD}\$key\${NORMAL}\\\n"
|
||||
printf "* [\$index/$item_count] \$key\\\n" >&3
|
||||
err=\$(
|
||||
aws s3api restore-object \\
|
||||
--bucket mcampagnaro-deep-glacier \\
|
||||
--key \\"\$key\\" \\
|
||||
--restore-request '{\\"Days\\":$days_available,\\"GlacierJobParameters\\":{\\"Tier\\":\\"$restore_tier\\"}}' \\
|
||||
2>&1 >/dev/null
|
||||
)
|
||||
index=\$((index + 1))
|
||||
before_sleep_count=\$((before_sleep_count + 1))
|
||||
|
||||
# strip newlines
|
||||
err="\${err//[$'\\\t\\\r\\\n']}"
|
||||
|
||||
if [[ \$err != "" ]]; then
|
||||
if ! grep -qE 'RestoreAlreadyInProgress|ObjectAlreadyInActiveTierError' <<<"\$err"; then
|
||||
printf "\${BOLD}\${RED}FAILED! \$err\${NORMAL}"
|
||||
printf "FAILED! \$err\" >&3
|
||||
|
||||
# Save the failure to a file now in case the script exits prematurely.
|
||||
fail_count=\$((fail_count + 1))
|
||||
printf "%%s\\\n" "\$key" >> \$failed_filename
|
||||
else
|
||||
if grep -qE 'RestoreAlreadyInProgress' <<<"\$err"; then
|
||||
printf "\${BOLD}\${YELLOW}SKIPPING! File restore is already in progress.\${NORMAL}"
|
||||
printf "SKIPPING! File restore is already in progress." >&3
|
||||
else
|
||||
printf "\${BOLD}\${YELLOW}SKIPPING! File is already restored. You can now download it.\${NORMAL}"
|
||||
printf "SKIPPING! File is already restored. You can now download it." >&3
|
||||
fi
|
||||
fi
|
||||
else
|
||||
printf "\${BOLD}\${GREEN}SUCCESS!\${NORMAL}"
|
||||
printf "SUCCESS!" >&3
|
||||
fi
|
||||
printf "\\\n\\\n"
|
||||
printf "\\\n\\\n" >&3
|
||||
|
||||
if [[ \$before_sleep_count -eq sleep_every_n_requests ]]; then
|
||||
printf "SLEEPING...\\\n\\\n"
|
||||
printf "SLEEPING...\\\n\\\n" >&3
|
||||
sleep \$sleep_duration
|
||||
before_sleep_count=0
|
||||
fi
|
||||
|
||||
done < all_objects_list.txt
|
||||
|
||||
printf "\${BOLD}\${GREEN}Done!\${NORMAL}\\\n\\\n"
|
||||
printf "Done!\\\n\\\n" >&3
|
||||
|
||||
if [[ \$fail_count > 0 ]]; then
|
||||
printf "\${BOLD}\${RED}There were \$fail_count failures!\\\nSee \${NORMAL}\${BOLD}\$filename\${RED} for the list. You can replace the contents of \${NORMAL}\${BOLD}all_objects_list.txt\${RED} with the list of failures and re-run this script to process them.\${NORMAL}\\\n\\\n"
|
||||
printf "There were \$fail_count failures!\\\nSee \$filename for the list. You can replace the contents of all_objects_list.txt with the list of failures and re-run this script to process them.\\\n\\\n" >&3
|
||||
else
|
||||
printf "There were no failures. All the files are being restored. You can now delete this folder.\\\n\\\n"
|
||||
printf "There were no failures. All the files are being restored. You can now delete this folder.\\\n\\\n" >&3
|
||||
fi
|
||||
|
||||
printf "(Note: the time it takes to restore an object 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"
|
||||
printf "You can check the status of a file using the aws-check-restore-status script)\\\n"
|
||||
|
||||
exec 3>&-
|
||||
|
||||
EOF
|
||||
)
|
||||
|
||||
printf "$RUN_TEMPLATE" > 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"
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
#
|
||||
# Inspired by https://superuser.com/a/323127 and https://superuser.com/a/1312885
|
||||
|
||||
source "$HOME/dotfiles/script_helpers/windows.sh"
|
||||
|
||||
if which tput >/dev/null 2>&1; then
|
||||
ncolors=$(tput colors)
|
||||
fi
|
||||
@@ -57,3 +59,4 @@ eval $cmd
|
||||
|
||||
printf "\n${GREEN}${BOLD}Done modifying volume in $filename.$extension | output: $output | delta: $delta_db${NORMAL}\n"
|
||||
|
||||
flash_taskbar
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Bigger crf values == bigger compression.
|
||||
|
||||
source "$HOME/dotfiles/script_helpers/windows.sh"
|
||||
|
||||
if which tput >/dev/null 2>&1; then
|
||||
ncolors=$(tput colors)
|
||||
fi
|
||||
@@ -24,9 +28,12 @@ else
|
||||
fi
|
||||
|
||||
use_gpu=1
|
||||
# Found the following to work best with vids containing text (e.g. programming vids). These give similar bitrates.
|
||||
cpu_crf=20
|
||||
gpu_crf=33
|
||||
|
||||
if [[ $# < 2 || $# > 5 ]]; then
|
||||
printf "${BOLD}${RED}Usage: compress-video <filename> <output name> <optional: use-gpu (1|0), defaults to $use_gpu> <optional: start time HH:MM:SS> <optional: end time HH:MM:SS> ${NORMAL}\n"
|
||||
printf "${BOLD}${RED}Usage: compress-video <filename> <output name> <optional: use-gpu (1|0), defaults to $use_gpu> <optional: start time HH:MM:SS> <optional: end time HH:MM:SS> (NOTE: gpu crf is $gpu_crf and cpu crf is $cpu_crf - change it by calling compress-video-with-crf)${NORMAL}\n"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -37,11 +44,12 @@ if [[ $# > 2 ]]; then
|
||||
use_gpu=$3
|
||||
fi
|
||||
|
||||
# Found the following to work best with vids containing text (e.g. programming vid): 21 for CPU encoding and 28 for GPU (similar bitrates).
|
||||
use_crf=21
|
||||
use_crf=$cpu_crf
|
||||
if [[ $use_gpu -eq 1 ]]; then
|
||||
use_crf=33
|
||||
use_crf=$gpu_crf
|
||||
fi
|
||||
|
||||
compress-video-with-crf $use_crf "$filename" "$output_name" $use_gpu $4 $5
|
||||
|
||||
flash_taskbar
|
||||
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Bigger crf values == bigger compression.
|
||||
|
||||
source "$HOME/dotfiles/script_helpers/windows.sh"
|
||||
|
||||
if which tput >/dev/null 2>&1; then
|
||||
ncolors=$(tput colors)
|
||||
fi
|
||||
@@ -93,3 +97,5 @@ else
|
||||
encode $crf
|
||||
done
|
||||
fi
|
||||
|
||||
flash_taskbar
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
# This is for reencoding a non-mp4 video to mp4 using an mpeg4 encoder.
|
||||
# Can optionally compress the video.
|
||||
|
||||
source "$HOME/dotfiles/script_helpers/windows.sh"
|
||||
|
||||
if which tput >/dev/null 2>&1; then
|
||||
ncolors=$(tput colors)
|
||||
fi
|
||||
@@ -94,3 +96,5 @@ else
|
||||
fi
|
||||
|
||||
printf "${GREEN}${BOLD}Done encoding '$filename.$extension' to '$output'${NORMAL}\n\n"
|
||||
|
||||
flash_taskbar
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
# Re-encodes the video to get a more accurate timeline. Same settings as trim-video-vbr.
|
||||
# If you want fast video joining at the expense of accuracy then use join-video-fast.
|
||||
|
||||
source "$HOME/dotfiles/script_helpers/windows.sh"
|
||||
|
||||
if which tput >/dev/null 2>&1; then
|
||||
ncolors=$(tput colors)
|
||||
fi
|
||||
@@ -31,17 +33,17 @@ output="$2"
|
||||
target_crf="$3"
|
||||
max_bitrate_mb="$4"
|
||||
|
||||
default_crf="20"
|
||||
default_crf="33" # if you want to compress then use the same gpu compression level from compress-video (i.e. 33, but verify it's still set to this)
|
||||
default_max_bitrate="6"
|
||||
|
||||
if [[ $filename == "" || $output == "" ]]; then
|
||||
printf "${BOLD}${RED}Usage: create a text file that lists the input video paths on separate lines using the format: file '/path/to/video'. Then call:\n\njoin-video <list filename> <output name> <optional: crf (quality, w/ lower = more compression) - defaults to $default_crf, use 0 for no value> <optional: max bitrate in MB - defaults to ${default_max_bitrate}M><${NORMAL}\n"
|
||||
printf "${BOLD}${RED}Usage: create a text file that lists the input video paths on separate lines using the format: file '/path/to/video'. Then call:\n\njoin-video <list filename> <output name> <optional: crf (quality, value = compression level) - defaults to $default_crf, use 0 for no value> <optional: max bitrate in MB - defaults to ${default_max_bitrate}M>${NORMAL}\n"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
extension="${output##*.}"
|
||||
if [[ $extension == $output ]]; then
|
||||
printf "${BOLD}${RED}output arg should have an extension!\n\nUsage: join-video <list filename> <output name> <optional: crf (quality, w/ lower = more compression) - defaults to $default_crf, use 0 for no value> <optional: max bitrate in MB - defaults to ${default_max_bitrate}M><${NORMAL}\n"
|
||||
printf "${BOLD}${RED}output arg should have an extension!\n\nUsage: join-video <list filename> <output name> <optional: crf (quality, value = compression level) - defaults to $default_crf, use 0 for no value> <optional: max bitrate in MB - defaults to ${default_max_bitrate}M>${NORMAL}\n"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -64,3 +66,4 @@ time ffmpeg -y -stats -loglevel level+error -hwaccel cuda -hwaccel_output_format
|
||||
|
||||
printf "\n${GREEN}${BOLD}Finished joining${NORMAL}\n\n"
|
||||
|
||||
flash_taskbar
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
# playback time might oscillate a bit. Use join-video for accurate joining at
|
||||
# the cost of a much slower processing time.
|
||||
|
||||
source "$HOME/dotfiles/script_helpers/windows.sh"
|
||||
|
||||
if which tput >/dev/null 2>&1; then
|
||||
ncolors=$(tput colors)
|
||||
fi
|
||||
@@ -44,3 +46,4 @@ ffmpeg -y -stats -loglevel level+error -f concat -safe 0 -i "$filename" -c copy
|
||||
|
||||
printf "\n${GREEN}${BOLD}Finished joining${NORMAL}\n\n"
|
||||
|
||||
flash_taskbar
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#
|
||||
# Inspired by https://superuser.com/a/323127 and https://superuser.com/a/1312885
|
||||
|
||||
source "$HOME/dotfiles/script_helpers/windows.sh"
|
||||
|
||||
if which tput >/dev/null 2>&1; then
|
||||
ncolors=$(tput colors)
|
||||
fi
|
||||
@@ -78,3 +80,4 @@ eval "$cmd"
|
||||
printf "\n${GREEN}${BOLD}Done normalizing volume in $filename.$extension | output: $output${NORMAL}\n"
|
||||
rm $temp_file
|
||||
|
||||
flash_taskbar
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
# Re-encodes the audio to get a more accurate seek time.
|
||||
|
||||
source "$HOME/dotfiles/script_helpers/windows.sh"
|
||||
|
||||
if which tput >/dev/null 2>&1; then
|
||||
ncolors=$(tput colors)
|
||||
fi
|
||||
@@ -58,3 +60,4 @@ ffmpeg -y -stats -loglevel level+error $timing_args -accurate_seek -i "$filename
|
||||
|
||||
printf "\n${GREEN}${BOLD}Finished trimming${NORMAL}\n\n"
|
||||
|
||||
flash_taskbar
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
# Re-encodes the video to get a more accurate seek time. If you want fast trimming at the expense of accuracy then use trim-video-fast.
|
||||
|
||||
source "$HOME/dotfiles/script_helpers/windows.sh"
|
||||
|
||||
if which tput >/dev/null 2>&1; then
|
||||
ncolors=$(tput colors)
|
||||
fi
|
||||
@@ -62,3 +64,4 @@ ffmpeg -y -stats -loglevel level+error $timing_args -accurate_seek -async 1 -i "
|
||||
|
||||
printf "\n${GREEN}${BOLD}Finished trimming${NORMAL}\n\n"
|
||||
|
||||
flash_taskbar
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
# time might oscillate a bit. Use trim-video for accurate trimming at the cost
|
||||
# of a much slower processing time.
|
||||
|
||||
source "$HOME/dotfiles/script_helpers/windows.sh"
|
||||
|
||||
if which tput >/dev/null 2>&1; then
|
||||
ncolors=$(tput colors)
|
||||
fi
|
||||
@@ -64,3 +66,4 @@ ffmpeg -y -stats -loglevel level+error $timing_args -i "$filename.$extension" -c
|
||||
|
||||
printf "\n${GREEN}${BOLD}Finished trimming${NORMAL}\n\n"
|
||||
|
||||
flash_taskbar
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Re-encodes the video using a constrained bitrate/output size. If you want to
|
||||
# To target the visual quality with a variable bitrate, use trim-video-vbr
|
||||
# control the visual quality with a variable bitrate then use trim-video-vbr
|
||||
|
||||
source "$HOME/dotfiles/script_helpers/windows.sh"
|
||||
|
||||
if which tput >/dev/null 2>&1; then
|
||||
ncolors=$(tput colors)
|
||||
@@ -90,3 +92,4 @@ ffmpeg -y -stats -loglevel level+error -hwaccel cuda -hwaccel_output_format cuda
|
||||
|
||||
printf "\n${GREEN}${BOLD}Finished trimming${NORMAL}\n\n"
|
||||
|
||||
flash_taskbar
|
||||
|
||||
@@ -4,6 +4,10 @@
|
||||
# To have a mostly fixed bitrate with no variable quality, use trim-video-target-rate
|
||||
# Just note that it'll result in larger files for a similar max bitrate target and the
|
||||
# quality won't really be noticeably better.
|
||||
#
|
||||
# The higher the CRF value, the higher the compression.
|
||||
|
||||
source "$HOME/dotfiles/script_helpers/windows.sh"
|
||||
|
||||
if which tput >/dev/null 2>&1; then
|
||||
ncolors=$(tput colors)
|
||||
@@ -35,11 +39,11 @@ end_time="$4"
|
||||
target_crf="$5"
|
||||
max_bitrate_mb="$6"
|
||||
|
||||
default_crf="20"
|
||||
default_crf="33" # if you want to compress then use the same gpu compression level from compress-video (i.e. 33, but verify it's still set to this)
|
||||
default_max_bitrate="6"
|
||||
|
||||
if [[ $filename == "" || $output_name == "" || $start_time == "" ]]; then
|
||||
printf "${BOLD}${RED}Usage: trim-video <filename> <output name> <start time HH:MM:SS> <optional: end time HH:MM:SS, use empty string or 0 for no value> <optional: crf (quality, w/ lower = more compression) - defaults to $default_crf, use 0 for no value> <optional: max bitrate in MB - defaults to ${default_max_bitrate}M>${NORMAL}\n"
|
||||
printf "${BOLD}${RED}Usage: trim-video-vbr <filename> <output name> <start time HH:MM:SS> <optional: end time HH:MM:SS, use empty string or 0 for no value> <optional: crf (quality, value = compression level) - defaults to $default_crf, use 0 for no value> <optional: max bitrate in MB - defaults to ${default_max_bitrate}M>${NORMAL}\n"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -122,3 +126,4 @@ time ffmpeg -y -stats -loglevel level+error -hwaccel cuda -hwaccel_output_format
|
||||
|
||||
printf "\n${GREEN}${BOLD}Finished trimming${NORMAL}\n\n"
|
||||
|
||||
flash_taskbar
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
NOTE: Best option is to create/store private keys in Bitwarden.
|
||||
|
||||
# Creating an elliptic curve keypair (ed25519)
|
||||
|
||||
* Create: `ssh-keygen -a 100 -t ed25519 -f ~/.ssh/filename`
|
||||
|
||||
@@ -60,6 +60,12 @@
|
||||
* Desktop: turn off hibernation
|
||||
* Open admin cmd prompt: `powercfg.exe /hibernate off`
|
||||
|
||||
* Enable long paths:
|
||||
* winkey+r -> `gpedit.msc`.
|
||||
* Computer Configuration > Administrative Templates > System > Filesystem
|
||||
* Double-click the `Enable Win32 long paths` policy.
|
||||
* Select Enabled.
|
||||
|
||||
* Disable power throttling:
|
||||
* winkey+r -> `gpedit.msc`.
|
||||
* Computer Configuration > Administrative Templates > System > Power Management > Power Throttling Settings
|
||||
|
||||
Reference in New Issue
Block a user