Skip to content

Commit

Permalink
Fix not compatible "--" specification problem (BSD versions chmod) | fix
Browse files Browse the repository at this point in the history
  • Loading branch information
uru2 committed Apr 20, 2024
1 parent 394d3cf commit ae31378
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
12 changes: 6 additions & 6 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ _variables() {
_download_file() {
cd "${INSTALL_PATH}" 2>| /dev/null 1>&2 || exit 1
# make the file writable if present
[ -f "${INSTALL_PATH}/${COMMAND_NAME}" ] && chmod u+w -- "${INSTALL_PATH}/${COMMAND_NAME}"
[ -f "${INSTALL_PATH}/${COMMAND_NAME}" ] && chmod -- u+w "${INSTALL_PATH}/${COMMAND_NAME}"
_print_center "justify" "${COMMAND_NAME}" "-"
# now download the binary
if script_download_file="$(curl -Ls --compressed "https://github.com/${REPO}/raw/${LATEST_CURRENT_SHA}/release/${INSTALLATION:-}/gupload")"; then
Expand All @@ -350,7 +350,7 @@ _download_file() {

[ -n "${SKIP_SYNC}" ] && return 0
# make the file writable if present
[ -f "${INSTALL_PATH}/${SYNC_COMMAND_NAME}" ] && chmod u+w -- "${INSTALL_PATH}/${SYNC_COMMAND_NAME}"
[ -f "${INSTALL_PATH}/${SYNC_COMMAND_NAME}" ] && chmod -- u+w "${INSTALL_PATH}/${SYNC_COMMAND_NAME}"
_print_center "justify" "${SYNC_COMMAND_NAME}" "-"
# now download the binary
if script_download_file="$(curl -Ls --compressed "https://github.com/${REPO}/raw/${LATEST_CURRENT_SHA}/release/${INSTALLATION:-}/gsync")"; then
Expand Down Expand Up @@ -418,8 +418,8 @@ _start() {
exit 1
fi

chmod "a-w-r-x,${PERM_MODE:-u}+x+r" -- "${INSTALL_PATH}/${COMMAND_NAME}"
chmod "a-w-r-x,${PERM_MODE:-u}+x+r" -- "${INSTALL_PATH}/${SYNC_COMMAND_NAME}"
chmod -- "a-w-r-x,${PERM_MODE:-u}+x+r" "${INSTALL_PATH}/${COMMAND_NAME}"
chmod -- "a-w-r-x,${PERM_MODE:-u}+x+r" "${INSTALL_PATH}/${SYNC_COMMAND_NAME}"

for _ in 1 2; do _clear_line 1; done

Expand Down Expand Up @@ -465,11 +465,11 @@ _start() {
_uninstall() {
_print_center "justify" "Uninstalling.." "-"

chmod -f u+w -- "${INSTALL_PATH}/${COMMAND_NAME}"
chmod -f -- u+w "${INSTALL_PATH}/${COMMAND_NAME}"
rm -f -- "${INSTALL_PATH:?}/${COMMAND_NAME:?}"

[ -z "${SKIP_SYNC}" ] && command -v "${SYNC_COMMAND_NAME}" 2>| /dev/null 1>&2 && {
chmod -f u+w -- "${INSTALL_PATH}/${SYNC_COMMAND_NAME}"
chmod -f -- u+w "${INSTALL_PATH}/${SYNC_COMMAND_NAME}"
rm -f -- "${INSTALL_PATH:?}/${SYNC_COMMAND_NAME:?}"
}

Expand Down
8 changes: 4 additions & 4 deletions src/common/auth-utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ _delete_account() {
if _account_exists "${account_delete_account}"; then
regex_delete_account="^ACCOUNT_${account_delete_account}_(CLIENT_ID=|CLIENT_SECRET=|REFRESH_TOKEN=|ROOT_FOLDER=|ROOT_FOLDER_NAME=|ACCESS_TOKEN=|ACCESS_TOKEN_EXPIRY=)|DEFAULT_ACCOUNT=\"${account_delete_account}\""
config_without_values_delete_account="$(grep -vE "${regex_delete_account}" -- "${CONFIG}")"
chmod u+w -- "${CONFIG}" || return 1 # change perms to edit
chmod -- u+w "${CONFIG}" || return 1 # change perms to edit
printf "%s\n" "${config_without_values_delete_account}" >| "${CONFIG}" || return 1
chmod "a-w-r-x,u+r" -- "${CONFIG}" || return 1 # restore perms
chmod -- "a-w-r-x,u+r" "${CONFIG}" || return 1 # restore perms
"${QUIET:-_print_center}" "normal" " Successfully deleted account ( ${account_delete_account} ) from config. " "-"
else
"${QUIET:-_print_center}" "normal" " Error: Cannot delete account ( ${account_delete_account} ) from config. No such account exists " "-" 1>&2
Expand All @@ -132,7 +132,7 @@ _handle_old_config() {
done
regex_check_handle_old_config="^(CLIENT_ID=|CLIENT_SECRET=|REFRESH_TOKEN=|ROOT_FOLDER=|ROOT_FOLDER_NAME=|ACCESS_TOKEN=|ACCESS_TOKEN_EXPIRY=)"
config_without_values_handle_old_config="$(grep -vE "${regex_check_handle_old_config}" -- "${CONFIG}")"
chmod u+w -- "${CONFIG}" || return 1 # change perms to edit
chmod -- u+w "${CONFIG}" || return 1 # change perms to edit
printf "%s\n%s\n%s\n%s\n%s\n%s\n" \
"ACCOUNT_${account_name_handle_old_config}_CLIENT_ID=\"${CLIENT_ID}\"" \
"ACCOUNT_${account_name_handle_old_config}_CLIENT_SECRET=\"${CLIENT_SECRET}\"" \
Expand All @@ -141,7 +141,7 @@ _handle_old_config() {
"ACCOUNT_${account_name_handle_old_config}_ROOT_FOLDER_NAME=\"${ROOT_FOLDER_NAME}\"" \
"${config_without_values_handle_old_config}" >| "${CONFIG}" || return 1

chmod "a-w-r-x,u+r" -- "${CONFIG}" || return 1 # restore perms
chmod -- "a-w-r-x,u+r" "${CONFIG}" || return 1 # restore perms

_reload_config || return 1 # reload config file
}
Expand Down
4 changes: 2 additions & 2 deletions src/common/common-utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -407,9 +407,9 @@ _update_config() {
[ $# -lt 3 ] && printf "Missing arguments\n" && return 1
value_name_update_config="${1}" value_update_config="${2}" config_path_update_config="${3}"
! [ -f "${config_path_update_config}" ] && : >| "${config_path_update_config}" # If config file doesn't exist.
chmod u+w -- "${config_path_update_config}" || return 1
chmod -- u+w "${config_path_update_config}" || return 1
printf "%s\n%s\n" "$(grep -v -e "^$" -e "^${value_name_update_config}=" -- "${config_path_update_config}" || :)" \
"${value_name_update_config}=\"${value_update_config}\"" >| "${config_path_update_config}" || return 1
chmod a-w-r-x,u+r -- "${config_path_update_config}" || return 1
chmod -- a-w-r-x,u+r "${config_path_update_config}" || return 1
return 0
}
2 changes: 1 addition & 1 deletion src/common/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,6 @@ _update_value() {
printf "%s\n" "Update downloaded but malformed, try again and if the issue persists open an issue on github."
return 1
}
chmod u+w -- "${command_path}" && printf "%s\n" "${new_script}" >| "${command_path}" && chmod "a-w-r-x,${PERM_MODE:-u}+r+x" -- "${command_path}"
chmod -- u+w "${command_path}" && printf "%s\n" "${new_script}" >| "${command_path}" && chmod -- "a-w-r-x,${PERM_MODE:-u}+r+x" "${command_path}"
return 0
}
4 changes: 2 additions & 2 deletions src/common/upload-common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ _cleanup_config() {
$(grep -F ACCESS_TOKEN_EXPIRY -- "${config}" || :)
EOF

chmod u+w -- "${config}" &&
chmod -- u+w "${config}" &&
printf "%s\n" "$(grep -Ev "^\$${values_regex:+|${values_regex}}" -- "${config}")" >| "${config}" &&
chmod "a-w-r-x,u+r" -- "${config}"
chmod -- "a-w-r-x,u+r" "${config}"
return 0
}

Expand Down

0 comments on commit ae31378

Please sign in to comment.