Skip to content

Commit

Permalink
secret: fix op perm issue, improve performance
Browse files Browse the repository at this point in the history
also improve display of code notices throughout
  • Loading branch information
balupton committed Feb 2, 2024
1 parent 34bd7a0 commit 14ab231
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 24 deletions.
2 changes: 1 addition & 1 deletion commands.beta/video-merge
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function video_merge() (

# check if the output file already exists, if it does, prompt for removal otherwise fail
if is-present -- "$output"; then
if confirm --positive --ppid=$$ -- "The output file already exists, remove it?" "$(echo-style --code="$output")"; then
if confirm --positive --ppid=$$ -- "The output file already exists, remove it?" "$(echo-style --code_notice="$output")"; then
rm "$output"
else
help "The output file already exists: $output"
Expand Down
4 changes: 1 addition & 3 deletions commands/cpr
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,7 @@ function cpr_() (
Using rsync with a remote directory that is mounted locally can be slow.
It is recommended to use its remote location instead, which autodetection implies it as:
$(echo-style --code="$suggestion")
$(echo-style --code_notice="$suggestion")
Alternatively, attempt a different tool as they can be better under these circumstances.
EOF
)"
Expand Down
14 changes: 6 additions & 8 deletions commands/secret
Original file line number Diff line number Diff line change
Expand Up @@ -195,18 +195,16 @@ function secret_() (
local sudo_reason='Secret is requesting your sudo/root/login password to securely store and access its secrets.'
local database="$DOROTHY/user/config.local/secrets.json"
function correct_database_permission {
sudo-helper --reason="$sudo_reason" -- chown "$USER" "$database"
sudo-helper --reason="$sudo_reason" -- chmod 600 "$database"
fs-own --user="$USER" --permissions='a-xrw,u+rw' --optional -- "$database" >"$tty_target"
fs-own --user="$USER" --permissions='a-xrw,u+rwX' --optional -- "$XDG_CONFIG_HOME/op" >"$tty_target"
}
function correct_key_permission {
local state_key="$1"
sudo-helper --reason="$sudo_reason" -- chown root: "$state_key"
sudo-helper --reason="$sudo_reason" -- chmod 600 "$state_key"
fs-own --owner="root:" --permissions='a-xrw,u+rw' -- "$state_key" >"$tty_target"
}
if ! sudo-helper --reason="$sudo_reason" -- test -f "$database"; then
print_line '{}' | sudo tee "$database" &>/dev/null
fi
correct_database_permission

# move old state location to new state location
local state="$XDG_STATE_HOME/secrets"
Expand Down Expand Up @@ -370,7 +368,9 @@ function secret_() (

# secret_signin
function secret_signin {
local email key status
local email='' key='' status
# setup permissions
correct_database_permission
# signout
secret_signout
# session
Expand Down Expand Up @@ -707,7 +707,6 @@ function secret_() (
'.[$secret] = [$vault, $item, $field]' \
"$database")"
print_line "$result" | sudo tee "$database" &>/dev/null
correct_database_permission
print_lines \
"Sucessfully updated [$database] so that [$secret] fetches [$vault].[$item].[$field]" \
"Fetching [$secret]..." >"$tty_target"
Expand All @@ -728,7 +727,6 @@ function secret_() (
'del(.[$secret])' \
"$database")"
print_line "$result" | sudo tee "$database"
correct_database_permission
cache_delete "$secret"
print_line "Sucessfully unmapped [$secret]" >"$tty_target"
}
Expand Down
14 changes: 4 additions & 10 deletions commands/setup-git
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,8 @@ function setup_git() (
cat <<-EOF >/dev/stderr
$(echo-style --e2="Git Configuration: Signing: 1Password")
GPG using 1Password was desired, however 1Password does not appear to be installed on this system. Install it first via:
$(echo-style --code="setup-util-1password")
$(echo-style --code="setup-util-1password-cli")
$(echo-style --code_notice='setup-util-1password')
$(echo-style --code_notice='setup-util-1password-cli')
Will continue without this.
EOF
GPG_SIGNING_KEY=''
Expand Down Expand Up @@ -305,9 +303,7 @@ function setup_git() (
cat <<-EOF >/dev/stderr
$(echo-style --e2="Git Configuration: Signing:")
Signing was desired, however there was no key specified.
$(echo-style --notice="Run the following to configure it accordingly:")
$(echo-style --code="setup-git --configure")
$(echo-style --notice='Run the' ' ' --code_notice='setup-git --configure' ' ' --notice='to configure.')
EOF
return 29 # ESPIPE 29 Illegal seek
fi
Expand All @@ -317,9 +313,7 @@ function setup_git() (
cat <<-EOF >/dev/stderr
$(echo-style --e2="Git Configuration: Signing:")
Signing was desired, however the key does not exist: $key
$(echo-style --notice="Run the following to configure it accordingly:")
$(echo-style --code="setup-git --configure")
$(echo-style --notice='Run the' ' ' --code_notice='setup-git --configure' ' ' --notice='to configure.')
EOF
return 29 # ESPIPE 29 Illegal seek
fi
Expand Down
2 changes: 1 addition & 1 deletion commands/setup-util-starship
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function setup_util_starship() (
fi
cat <<-EOF
If you see unknown icons while using Starship, then you need to run:
$(echo-style --code="$fonts_instruction")
$(echo-style --code_notice="$fonts_instruction")
then set your terminal to use the Fira Code Nerd font, or another monospace nerd font that was installed.
EOF
fi
Expand Down
2 changes: 1 addition & 1 deletion commands/setup-util-vim
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function setup_util_vim() (
if test ! -f "$HOME/.vimrc"; then
cat <<-EOF
Vim configuration missing, applying the fancy defaults from:
$(echo-style --dim='https://github.com/amix/vimrc')
$(echo-style --code='https://github.com/amix/vimrc')
EOF
github-download \
--slug='amix/vimrc' \
Expand Down

0 comments on commit 14ab231

Please sign in to comment.