-
-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve security and reliability of macOS updates
This commit introduces several improvements to the macOS update process, primarily focusing on enhancing security and reliability: - Add data integrity checks to ensure downloaded updates haven't been tampered with. - Optimize update progress logging in `streamWithProgress` by limiting amount of logs during the download process. - Improve resource management by ensuring proper closure of file read/write streams. - Add retry logic with exponential back-off during integrity checks to handle occasional file system preparation delays on macOS. - Improve decision-making based on user responses. - Improve clarity and informativeness of log messages. - Update error dialogs for better user guidance when updates fail to download, unexpected errors occur or the installer can't be opened. - Add handling for unexpected errors during the update process. - Move to asynchronous functions for more efficient operation. - Move to scoped imports for better code clarity. - Update `Readable` stream type to a more modern variant in Node. - Refactor `ManualUpdater` for improved separation of concerns. - Document the secure update process, and log directory locations. - Rename files to more accurately reflect their purpose. - Add `.DS_Store` in `.gitignore` to avoid unintended files in commits.
- Loading branch information
1 parent
25e23c8
commit 5b91b6f
Showing
14 changed files
with
721 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,6 @@ node_modules | |
# draw.io | ||
*.bkp | ||
*.dtmp | ||
|
||
# macOS | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#!/usr/bin/env bash | ||
# bash: `bash ./alias.sh` (requires sudo in macOS) | ||
# zsh: `zsh ./alias.sh` | ||
|
||
main() { | ||
# ----- | ||
# gitgo | ||
# ----- | ||
# Alias for git add, commit with amend, update commit date and force push | ||
set_persistent_alias "alias gitgo='git add . && git commit --amend --no-edit --reset-author && git push -f'" | ||
|
||
# ----- | ||
# gitc | ||
# ----- | ||
# Alias for counting total characters in last commi heading | ||
set_persistent_alias "alias gitc='git log --pretty='format:%Creset%s' --no-merges -1 | wc -c'" | ||
|
||
# ----- | ||
# gita | ||
# ----- | ||
# Alias for amending to latest commit | ||
set_persistent_alias "alias gita='git add . && git commit --amend --no-edit --allow-empty'" | ||
} | ||
|
||
set_persistent_alias() { | ||
local -r alias="$1" | ||
local -r file="$(get_alias_file)" | ||
if ! create_file "$file"; then | ||
log_error "Failed to create the file: $file." | ||
return 1 | ||
fi | ||
if grep -Fxq "$alias" "$file"; then | ||
echo "[$file] Alias already exists: $alias" | ||
else | ||
command="echo \"$alias\" >> \"$file\"" | ||
if type "sudo" &> /dev/null; then # Git Bash on Windows does not have sudo | ||
command="sudo $command" | ||
fi | ||
if eval "$command"; then | ||
echo "[$file] Saved alias" | ||
else | ||
log_error "[$file] Failed to save alias" | ||
fi | ||
fi | ||
# shellcheck disable=SC1090 | ||
source "$file" | ||
} | ||
|
||
get_alias_file() { | ||
if [ -n "${ZSH_VERSION+x}" ]; then | ||
echo "$HOME/.zshrc" | ||
elif [ -n "${BASH_VERSION+x}" ]; then | ||
if [ "$(uname -s)" == "Darwin" ]; then | ||
echo "$HOME/.bash_profile" | ||
else # tested on Windows | ||
echo "$HOME/.bashrc" | ||
fi | ||
else | ||
log_error 'Unkown shell' | ||
exit 1 | ||
fi | ||
} | ||
|
||
create_file() { | ||
local file_path="$1" | ||
if [ -z "$file_path" ]; then | ||
log_error 'Missing file path.' | ||
return 1 | ||
fi | ||
local parent_dir | ||
if ! parent_dir=$(dirname "$file_path"); then | ||
log_error "Could not determine the parent directory for the path: $file_path" | ||
return 1 | ||
fi | ||
if [ ! -d "$parent_dir" ]; then | ||
echo "Creating directory: $parent_dir" | ||
if ! mkdir -p "$parent_dir"; then | ||
log_error "Failed to create the parent directory: $parent_dir" | ||
return 1 | ||
fi | ||
fi | ||
if [ ! -f "$file_path" ]; then | ||
echo "Creating file: $file_path" | ||
if ! touch "$file_path"; then | ||
log_error "Failed to create the file: $file_path" | ||
return 1 | ||
fi | ||
fi | ||
} | ||
|
||
log_error() { | ||
local -r message="$1" | ||
>&2 echo "Error: $message" | ||
} | ||
|
||
main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.