diff --git a/atfile-install.sh b/atfile-install.sh index bf66c21..baf9c7d 100755 --- a/atfile-install.sh +++ b/atfile-install.sh @@ -38,7 +38,7 @@ function parse_version() { v_major="$(printf "%04d\n" "$(echo "$version" | cut -d "." -f 1)")" v_minor="$(printf "%04d\n" "$(echo "$version" | cut -d "." -f 2)")" v_rev="$(printf "%04d\n" "$(echo "$version" | cut -d "." -f 3)")" - echo "$(echo ${v_major}${v_minor}${v_rev} | sed 's/^0*//')" + echo "$(echo "${v_major}${v_minor}${v_rev}" | sed 's/^0*//')" } function xrpc_get() { diff --git a/atfile.sh b/atfile.sh index 0595623..42ca297 100755 --- a/atfile.sh +++ b/atfile.sh @@ -69,6 +69,7 @@ if [ ! -x "$(command -v git)" ]; then fi git describe --exact-match --tags > /dev/null 2>&1 +# shellcheck disable=SC2181 [[ $? != 0 ]] && version+="+git.$(git rev-parse --short HEAD)" # BUG: Clobbers variables from config file diff --git a/src/commands/old_cmds.sh b/src/commands/old_cmds.sh index 028073f..0c70855 100644 --- a/src/commands/old_cmds.sh +++ b/src/commands/old_cmds.sh @@ -32,8 +32,8 @@ function atfile.invoke.blob_list() { json_output="{\"blobs\":[" fi - while IFS=$"\n" read -r c; do - cid="$(echo $c | jq -r ".")" + while IFS=$'\n' read -r c; do + cid="$(echo "$c" | jq -r ".")" blob_uri="$(atfile.util.build_blob_uri "$_username" "$cid")" last_cid="$cid" ((record_count++)) @@ -127,6 +127,7 @@ function atfile.invoke.download() { downloaded_file="$(atfile.util.build_out_filename "$key" "$file_name")" curl -H "User-Agent: $(atfile.util.get_uas)" --silent "$blob_uri" -o "$downloaded_file" + # shellcheck disable=SC2181 [[ $? != 0 ]] && success=0 fi @@ -135,6 +136,7 @@ function atfile.invoke.download() { gpg --quiet --output "$new_downloaded_file" --decrypt "$downloaded_file" + # shellcheck disable=SC2181 if [[ $? != 0 ]]; then success=0 else @@ -169,7 +171,7 @@ function atfile.invoke.get() { if [[ $success == 1 ]]; then file_type="$(echo "$record" | jq -r '.value.file.mimeType')" - did="$(echo $record | jq -r ".uri" | cut -d "/" -f 3)" + did="$(echo "$record" | jq -r ".uri" | cut -d "/" -f 3)" key="$(atfile.util.get_rkey_from_at_uri "$(echo "$record" | jq -r ".uri")")" blob_uri="$(atfile.util.build_blob_uri "$did" "$(echo "$record" | jq -r ".value.blob.ref.\"\$link\"")")" cdn_uri="$(atfile.util.get_cdn_uri "$did" "$(echo "$record" | jq -r ".value.blob.ref.\"\$link\"")" "$file_type")" @@ -180,6 +182,7 @@ function atfile.invoke.get() { # shellcheck disable=SC2154 atfile.say.debug "Getting record...\n↳ NSID: $_nsid_lock\n↳ Repo: $_username\n↳ Key: $key" locked_record="$(com.atproto.repo.getRecord "$_username" "$_nsid_lock" "$key")" + # shellcheck disable=SC2181 if [[ $? == 0 ]] && [[ -n "$locked_record" ]]; then if [[ $(echo "$locked_record" | jq -r ".value.lock") == true ]]; then locked="$(atfile.util.get_yn 1)" @@ -237,7 +240,7 @@ function atfile.invoke.get() { else case $finger_type in "browser") - finger_browser_uas="$(echo $record | jq -r ".value.finger.userAgent")" + finger_browser_uas="$(echo "$record" | jq -r ".value.finger.userAgent")" [[ -z $finger_browser_uas || $finger_browser_uas == "null" ]] && finger_browser_uas="(Unknown)" @@ -291,7 +294,7 @@ function atfile.invoke.handle_atfile() { handler="$2" function atfile.invoke.handle_atfile.is_temp_file_needed() { - handler="$(echo $1 | sed s/.desktop$//g)" + handler="$(echo "$1" | sed s/.desktop$//g)" type="$2" handlers=( @@ -340,8 +343,10 @@ function atfile.invoke.handle_atfile() { atfile.say.debug "Handler manually set to '$handler'" fi + # shellcheck disable=SC2319 + # shellcheck disable=SC2181 if [[ -n $handler ]] || [[ $? != 0 ]]; then - atfile.say.debug "Opening '$key' ($file_type) with '$(echo $handler | sed s/.desktop$//g)'..." + atfile.say.debug "Opening '$key' ($file_type) with '$(echo "$handler" | sed s/.desktop$//g)'..." # HACK: Some apps don't like http(s)://; we'll need to handle these if [[ $(atfile.invoke.handle_atfile.is_temp_file_needed "$handler" "$file_type") == 1 ]]; then @@ -438,8 +443,8 @@ function atfile.invoke.list() { json_output="{\"uploads\":[" fi - while IFS=$"\n" read -r c; do - key=$(atfile.util.get_rkey_from_at_uri "$(echo $c | jq -r ".uri")") + while IFS=$'\n' read -r c; do + key=$(atfile.util.get_rkey_from_at_uri "$(echo "$c" | jq -r ".uri")") name="$(echo "$c" | jq -r '.value.file.name')" type_emoji="$(atfile.util.get_file_type_emoji "$(echo "$c" | jq -r '.value.file.mimeType')")" last_key="$key" @@ -529,6 +534,7 @@ function atfile.invoke.manage_record() { [[ -z "$record" ]] && atfile.die " not set" record_json="$(echo "$record" | jq)" + # shellcheck disable=SC2181 [[ $? != 0 ]] && atfile.die "Invalid JSON" com.atproto.repo.createRecord "$_username" "$collection" "$record_json" | jq @@ -583,6 +589,7 @@ function atfile.invoke.manage_record() { [[ -z "$record" ]] && atfile.die " not set" record_json="$(echo "$record" | jq)" + # shellcheck disable=SC2181 [[ $? != 0 ]] && atfile.die "Invalid JSON" if [[ "$key" == at:* ]]; then @@ -612,6 +619,7 @@ function atfile.invoke.print() { file_type="$(echo "$record" | jq -r '.value.file.mimeType')" curl -H "$(atfile.util.get_uas)" -s -L "$blob_uri" --output - + # shellcheck disable=SC2181 [[ $? != 0 ]] && error="?" fi @@ -627,6 +635,7 @@ function atfile.invoke.toggle_desktop() { [[ $_os == "haiku" ]] && atfile.die "Not available on Haiku" [[ $_os == "macos" ]] && atfile.die "Not available on macOS\nThink you could help? See: https://tangled.sh/@zio.sh/atfile/issues/9" + uid="$(id -u)" if [[ $uid == 0 ]]; then desktop_dir="/usr/local/share/applications" mime_dir="/usr/local/share/mime" @@ -690,6 +699,7 @@ function atfile.invoke.upload() { [[ $_output_json == 0 ]] && echo -e "Encrypting '$file_crypt'..." gpg --yes --quiet --recipient "$recipient" --output "$file_crypt" --encrypt "$file" + # shellcheck disable=SC2181 if [[ $? == 0 ]]; then file="$file_crypt" else @@ -711,6 +721,7 @@ function atfile.invoke.upload() { ;; "haiku") haiku_file_attr="$(catattr BEOS:TYPE "$file" 2> /dev/null)" + # shellcheck disable=SC2181 [[ $? == 0 ]] && file_type="$(echo "$haiku_file_attr" | cut -d ":" -f 3 | xargs)" file_date="$(atfile.util.get_date "$(stat -c '%y' "$file")")" @@ -787,7 +798,7 @@ function atfile.invoke.upload() { if [[ -z "$error" ]]; then unset recipient_key - blob_uri="$(atfile.util.build_blob_uri "$(echo "$record" | jq -r ".uri" | cut -d "/" -f 3)" "$(echo $blob | jq -r ".ref.\"\$link\"")")" + blob_uri="$(atfile.util.build_blob_uri "$(echo "$record" | jq -r ".uri" | cut -d "/" -f 3)" "$(echo "$blob" | jq -r ".ref.\"\$link\"")")" key="$(atfile.util.get_rkey_from_at_uri "$(echo "$record" | jq -r ".uri")")" if [[ -n "$recipient" ]]; then diff --git a/src/commands/release.sh b/src/commands/release.sh index fccac86..75df4b1 100644 --- a/src/commands/release.sh +++ b/src/commands/release.sh @@ -29,13 +29,19 @@ function atfile.release() { parsed_version="$(atfile.util.parse_version "$_version")" version_record_id="atfile-$parsed_version" - atfile.say "Building..." + test_error_count=0 + test_info_count=0 + test_style_count=0 + test_warning_count=0 + test_ignore_count=0 - mkdir -p "$dist_dir" + atfile.say "⚒️ Building..." - echo "↳ Compiling '$dist_file'..." + echo "↳ Creating '$dist_file'..." + mkdir -p "$dist_dir" echo "#!/usr/bin/env bash" > "$dist_path" + echo "↳ Generating header..." echo -e "\n# ATFile # --- # Version: $_version @@ -50,7 +56,7 @@ function atfile.release() { do if [[ "$s" != *"/src/commands/release.sh" ]]; then if [[ -f "$s" ]]; then - echo " ↳ Adding: $s" + echo "↳ Adding: $s" while IFS="" read -r line do @@ -65,9 +71,9 @@ function atfile.release() { if [[ $line == *"# shellcheck disable"* ]]; then include_line=1 + (( test_ignore_count++ )) fi - if [[ $include_line == 1 ]]; then if [[ $line == *"{:"* && $line == *":}"* ]]; then # NOTE: Not using atfile.util.get_envvar() here, as confusion can arise from config file @@ -91,14 +97,9 @@ function atfile.release() { echo "$dist_path" - echo "Testing..." + echo "🧪 Testing..." shellcheck_output="$(shellcheck --format=json "$dist_path" 2>&1)" - test_error_count=0 - test_info_count=0 - test_style_count=0 - test_warning_count=0 - while read -r item; do code="$(echo "$item" | jq -r '.code')" col="$(echo "$item" | jq -r '.column')" @@ -118,16 +119,17 @@ function atfile.release() { test_total_count=$(( test_error_count + test_info_count + test_style_count + test_warning_count )) - echo -e "Built: $_version + echo -e "---\n✅ Built: $_version ↳ Path: ./$dist_path_relative ↳ Check: $checksum ↳ Size: $(atfile.util.get_file_size_pretty "$(stat -c %s "$dist_path")") ↳ Lines: $(atfile.util.fmt_int "$(wc -l < "$dist_path")") ↳ Issues: $(atfile.util.fmt_int "$test_total_count") - ↳ Error: $(atfile.util.fmt_int "$test_error_count") - ↳ Warn: $(atfile.util.fmt_int "$test_warning_count") - ↳ Info: $(atfile.util.fmt_int "$test_info_count") - ↳ Style: $(atfile.util.fmt_int "$test_style_count") + ↳ Error: $(atfile.util.fmt_int "$test_error_count") + ↳ Warning: $(atfile.util.fmt_int "$test_warning_count") + ↳ Info: $(atfile.util.fmt_int "$test_info_count") + ↳ Style: $(atfile.util.fmt_int "$test_style_count") + ↳ Ignored: $(atfile.util.fmt_int "$test_ignore_count") ↳ ID: $id" chmod +x "$dist_path" @@ -138,14 +140,14 @@ function atfile.release() { atfile.die "Unable to publish ($test_error_count errors detected)" fi - echo "---" + atfile.say "---\n✨ Updating..." atfile.auth "$_dist_username" "$_dist_password" [[ $_version == *"+"* ]] && atfile.die "Cannot publish a Git version ($_version)" - atfile.say "Uploading '$dist_path'..." + atfile.say "↳ Uploading '$dist_path'..." atfile.invoke.upload "$dist_path" "" "$version_record_id" + # shellcheck disable=SC2181 [[ $? != 0 ]] && atfile.die "Unable to upload '$dist_path'" - echo "---" latest_release_record="{ \"version\": \"$_version\", @@ -155,7 +157,7 @@ function atfile.release() { \"checksum\": \"$checksum\" }" - atfile.say "Updating latest record to $_version..." + atfile.say "↳ Bumping current version..." # shellcheck disable=SC2154 atfile.invoke.manage_record put "at://$_username/self.atfile.latest/self" "$latest_release_record" &> /dev/null fi diff --git a/src/commands/resolve.sh b/src/commands/resolve.sh index ad77849..73d7eb2 100644 --- a/src/commands/resolve.sh +++ b/src/commands/resolve.sh @@ -76,7 +76,7 @@ function atfile.resolve() { atfile.say " $i" fi - first_alias="$a" + first_alias="${a[0]}" done done <<< "$aliases" diff --git a/src/commands/something_broke.sh b/src/commands/something_broke.sh index 54b94a2..9f61f65 100644 --- a/src/commands/something_broke.sh +++ b/src/commands/something_broke.sh @@ -65,7 +65,7 @@ function atfile.something_broke() { ↳ UAS: $(atfile.util.get_uas) ↳ Path: $_prog_path Variables -$(atfile.something_broke.print_envvar "DEBUG" $_debug_default) +$(atfile.something_broke.print_envvar "DEBUG" "$_debug_default") $(atfile.something_broke.print_envvar "DEVEL") $(atfile.something_broke.print_envvar "DEVEL_DIR") $(atfile.something_broke.print_envvar "DEVEL_ENTRY") diff --git a/src/commands/update.sh b/src/commands/update.sh index 2401e83..47b98bf 100644 --- a/src/commands/update.sh +++ b/src/commands/update.sh @@ -45,8 +45,8 @@ function atfile.update() { latest_version="$(echo "$latest_release_record" | jq -r '.value.version')" latest_version_commit="$(echo "$latest_release_record" | jq -r '.value.commit')" latest_version_date="$(echo "$latest_release_record" | jq -r '.value.releasedAt')" - parsed_latest_version="$(atfile.util.parse_version $latest_version)" - parsed_running_version="$(atfile.util.parse_version $_version)" + parsed_latest_version="$(atfile.util.parse_version "$latest_version")" + parsed_running_version="$(atfile.util.parse_version "$_version")" latest_version_record_id="atfile-$parsed_latest_version" update_available=0 @@ -65,6 +65,7 @@ function atfile.update() { echo "---" if [[ $_os == "haiku" ]]; then + # shellcheck disable=SC2154 atfile.say "Update available ($latest_version)\n↳ Run \`$_prog update\` to update" # BUG: Haiku Terminal has issues with emojis else atfile.say "😎 Update available ($latest_version)\n ↳ Run \`$_prog update\` to update" @@ -86,16 +87,21 @@ function atfile.update() { atfile.say.debug "Touching temporary path ($temp_updated_path)..." touch "$temp_updated_path" + # shellcheck disable=SC2181 [[ $? != 0 ]] && atfile.die "Unable to create temporary file (do you have permission?)" atfile.say.debug "Getting blob URL for $latest_version ($latest_version_record_id)..." - blob_url="$(atfile.invoke.get_url $latest_version_record_id)" + blob_url="$(atfile.invoke.get_url "$latest_version_record_id")" + # shellcheck disable=SC2181 [[ $? != 0 ]] && atfile.die "Unable to get blob URL" atfile.say.debug "Downloading latest release..." curl -H "User-Agent: $(atfile.util.get_uas)" -s -o "$temp_updated_path" "$blob_url" + # shellcheck disable=SC2181 if [[ $? == 0 ]]; then + # shellcheck disable=SC2154 mv "$temp_updated_path" "$_prog_path" + # shellcheck disable=SC2181 if [[ $? != 0 ]]; then atfile.die "Unable to update (do you have permission?)" else diff --git a/src/entry.sh b/src/entry.sh index c52c9b3..5051791 100644 --- a/src/entry.sh +++ b/src/entry.sh @@ -219,7 +219,7 @@ fi if [[ $is_os_supported == 0 ]]; then if [[ $_skip_unsupported_os_warn == 0 ]]; then - atfile.die "Unsupported OS ($(echo $_os | sed s/unknown-//g))\n↳ Set ${_envvar_prefix}_SKIP_UNSUPPORTED_OS_WARN=1 to ignore" + atfile.die "Unsupported OS ($(echo "$_os" | sed s/unknown-//g))\n↳ Set ${_envvar_prefix}_SKIP_UNSUPPORTED_OS_WARN=1 to ignore" else atfile.say.debug "Skipping unsupported OS warning\n↳ ${_envvar_prefix}_SKIP_UNSUPPORTED_OS_WARN is set ($_skip_unsupported_os_warn)" fi @@ -241,7 +241,7 @@ fi atfile.say.debug "Checking required programs..." atfile.util.check_prog "curl" "https://curl.se" -[[ $os != "haiku" && $os != "solaris" ]] && atfile.util.check_prog "file" "https://www.darwinsys.com/file" +[[ $_os != "haiku" && $_os != "solaris" ]] && atfile.util.check_prog "file" "https://www.darwinsys.com/file" atfile.util.check_prog "jq" "$_prog_hint_jq" [[ $_skip_ni_md5sum == 0 ]] && atfile.util.check_prog "md5sum" "" "${_envvar_prefix}_SKIP_NI_MD5SUM" diff --git a/src/lexi/blue_zio_atfile.sh b/src/lexi/blue_zio_atfile.sh index f5064aa..8da177c 100644 --- a/src/lexi/blue_zio_atfile.sh +++ b/src/lexi/blue_zio_atfile.sh @@ -187,7 +187,7 @@ function blue.zio.atfile.meta__video() { \"gps\": { \"alt\": $gps_alt, \"lat\": $gps_lat, - \"long\": "$gps_long" + \"long\": $gps_long }, \"title\": \"$title\", \"video\": [ $video ] @@ -211,6 +211,7 @@ function blue.zio.atfile.finger__machine() { unset machine_id unset machine_os + # shellcheck disable=SC2154 if [[ $_enable_fingerprint == 1 ]]; then machine_id_file="/etc/machine-id" os_release_file="/etc/os-release" diff --git a/src/shared/cache.sh b/src/shared/cache.sh index d6aa2e6..b353cd1 100644 --- a/src/shared/cache.sh +++ b/src/shared/cache.sh @@ -1,17 +1,17 @@ #!/usr/bin/env bash function atfile.cache.del() { - key="$(atfile.util.get_cache_path $1)" + key="$(atfile.util.get_cache_path "$1")" [[ -f "$key" ]] && rm "$key" } function atfile.cache.get() { - key="$(atfile.util.get_cache_path $1)" + key="$(atfile.util.get_cache_path "$1")" [[ -f "$key" ]] && cat "$key" } function atfile.cache.set() { - key="$(atfile.util.get_cache_path $1)" + key="$(atfile.util.get_cache_path "$1")" value="$2" # shellcheck disable=SC2154 diff --git a/src/shared/http.sh b/src/shared/http.sh index 9cd835a..1d28e71 100644 --- a/src/shared/http.sh +++ b/src/shared/http.sh @@ -56,7 +56,8 @@ function atfile.http.upload() { atfile.say.debug "$uri\n↳ $file" "POST: " - curl -s -X POST $_server/xrpc/$lexi \ + # shellcheck disable=SC2154 + curl -s -X POST "$_server/xrpc/$lexi" \ -H "$auth" \ -H "Content-Type: $type" \ -H "User-Agent: $(atfile.util.get_uas)" \ diff --git a/src/shared/say.sh b/src/shared/say.sh index 51e62da..5e3297c 100644 --- a/src/shared/say.sh +++ b/src/shared/say.sh @@ -40,7 +40,7 @@ function atfile.say() { fi fi - message="$(echo "$message" | sed -e "s|\\\n|\\\n$(atfile.util.repeat_char " " $prefix_length)|g")" + message="$(echo "$message" | sed -e "s|\\\n|\\\n$(atfile.util.repeat_char " " "$prefix_length")|g")" echo -n -e "${prefix}${color_message}$message\033[0m${suffix}" } @@ -64,5 +64,5 @@ function atfile.say.die() { function atfile.say.inline() { message="$1" color="$2" - atfile.say "$message" "" "" $color "" "\\" + atfile.say "$message" "" "" "$color" "" "\\" } diff --git a/src/shared/util.sh b/src/shared/util.sh index 74b6010..29f91d4 100644 --- a/src/shared/util.sh +++ b/src/shared/util.sh @@ -37,7 +37,7 @@ function atfile.util.check_prog() { download_hint="$2" skip_hint="$3" - if ! [ -x "$(command -v $command)" ]; then + if ! [ -x "$(command -v "$command")" ]; then message="'$command' not installed" if [[ -n "$download_hint" ]]; then @@ -61,7 +61,9 @@ function atfile.util.check_prog_gpg() { } function atfile.util.check_prog_optional_metadata() { + # shellcheck disable=SC2154 [[ $_skip_ni_exiftool == 0 ]] && atfile.util.check_prog "exiftool" "https://exiftool.org" "${_envvar_prefix}_SKIP_NI_EXIFTOOL" + # shellcheck disable=SC2154 [[ $_skip_ni_mediainfo == 0 ]] && atfile.util.check_prog "mediainfo" "https://mediaarea.net/en/MediaInfo" "${_envvar_prefix}_SKIP_NI_MEDIAINFO" } @@ -70,6 +72,7 @@ function atfile.util.create_dir() { if ! [[ -d $dir ]]; then mkdir -p "$dir" + # shellcheck disable=SC2181 [[ $? != 0 ]] && atfile.die "Unable to create directory '$dir'" fi } @@ -81,9 +84,9 @@ function atfile.util.fmt_int() { function atfile.util.get_app_url_for_at_uri() { uri="$1" - actor="$(echo $uri | cut -d / -f 3)" - collection="$(echo $uri | cut -d / -f 4)" - rkey="$(echo $uri | cut -d / -f 5)" + actor="$(echo "$uri" | cut -d / -f 3)" + collection="$(echo "$uri" | cut -d / -f 4)" + rkey="$(echo "$uri" | cut -d / -f 5)" ignore_url_validation=0 resolved_actor="$(atfile.util.resolve_identity "$actor")" @@ -94,6 +97,7 @@ function atfile.util.get_app_url_for_at_uri() { unset actor_pds unset resolved_url + # shellcheck disable=SC2181 if [[ $? == 0 ]]; then actor="$(echo "$resolved_actor" | cut -d "|" -f 1)" actor_handle="$(echo "$resolved_actor" | cut -d "|" -f 3 | cut -d "/" -f 3)" @@ -172,6 +176,7 @@ function atfile.util.get_app_url_for_at_uri() { } function atfile.util.get_cache_path() { + # shellcheck disable=SC2154 echo "$_path_cache/$1" } @@ -213,7 +218,7 @@ function atfile.util.get_date() { if [[ $_os == "linux-musl" || $_os == "solaris" ]]; then echo "" else - date -u +$format + date -u +"$format" fi else if [[ $_os == "linux-musl" || $_os == "solaris" ]]; then @@ -233,6 +238,7 @@ function atfile.util.get_date_json() { if [[ -z "$parsed" ]]; then if [[ -n "$date" ]]; then parsed_date="$(atfile.util.get_date "$date" 2> /dev/null)" + # shellcheck disable=SC2181 [[ $? == 0 ]] && parsed="$parsed_date" fi fi @@ -262,7 +268,7 @@ function atfile.util.get_didplc_doc() { didplc_doc="$(atfile.util.get_didplc_doc.request_doc "$didplc_endpoint" "$actor")" fi - echo "$(echo $didplc_doc | jq ". += {\"directory\": \"$didplc_endpoint\"}")" + echo "$(echo "$didplc_doc" | jq ". += {\"directory\": \"$didplc_endpoint\"}")" } function atfile.util.get_didweb_doc_url() { @@ -380,7 +386,7 @@ function atfile.util.get_file_name_pretty() { output_last_line_length="${#output_last_line}" echo -e "$output" - echo -e "$(atfile.util.repeat_char "-" $output_last_line_length)" + echo -e "$(atfile.util.repeat_char "-" "$output_last_line_length")" } function atfile.util.get_file_size_pretty() { @@ -411,7 +417,7 @@ function atfile.util.get_file_size_surplus_for_pds() { *".host.bsky.network") max_filesize=1073741824 ;; esac - if [[ -z $max_filesize ]] || [[ $max_filesize == 0 ]] || (( $size < $max_filesize )); then + if [[ -z $max_filesize ]] || [[ $max_filesize == 0 ]] || (( size < max_filesize )); then echo 0 else echo $(( size - max_filesize )) @@ -420,8 +426,8 @@ function atfile.util.get_file_size_surplus_for_pds() { function atfile.util.get_file_type_emoji() { mime_type="$1" - short_type="$(echo $mime_type | cut -d "/" -f 1)" - desc_type="$(echo $mime_type | cut -d "/" -f 2)" + short_type="$(echo "$mime_type" | cut -d "/" -f 1)" + desc_type="$(echo "$mime_type" | cut -d "/" -f 2)" case $short_type in "application") @@ -496,7 +502,7 @@ function atfile.util.get_line() { input="$1" index=$(( $2 + 1 )) - echo "$(echo -e "$input" | sed -n "$(( $index ))"p)" + echo "$(echo -e "$input" | sed -n "$(( index ))"p)" } function atfile.util.get_mediainfo_field() { @@ -535,13 +541,13 @@ function atfile.util.get_mediainfo_audio_json() { samplings=$(atfile.util.get_mediainfo_field "$file" "Audio" "SamplingRate" 0) titles="$(atfile.util.get_mediainfo_field "$file" "Audio" "Title" "")" - lines="$(echo "$bitrates" | wc -l)" + lines="$(echo "$bitRates" | wc -l)" output="" - for ((i = 0 ; i < $lines ; i++ )); do + for (( i = 0 ; i < lines ; i++ )); do lossy=true - [[ \"$(atfile.util.get_line "$compressions" $i)\" == "Lossless" ]] && lossy=false + [[ $(atfile.util.get_line "$compressions" $i) == "Lossless" ]] && lossy=false output+="{ \"bitRate\": $(atfile.util.get_line "$bitRates" $i), @@ -576,7 +582,7 @@ function atfile.util.get_mediainfo_video_json() { frameRate_modes="$(atfile.util.get_mediainfo_field "$file" "Video" "FrameRate_Mode" "")" titles="$(atfile.util.get_mediainfo_field "$file" "Video" "Title" "")" - lines="$(echo "$bitrates" | wc -l)" + lines="$(echo "$bitRates" | wc -l)" output="" for ((i = 0 ; i < lines ; i++ )); do @@ -692,11 +698,15 @@ function atfile.util.get_realpath() { path="$1" if [[ $_os == "solaris" ]]; then - # INVESTIGATE: Use this for every OS? What does this even do? + # SEE: https://stackoverflow.com/a/11554895 + # INVESTIGATE: Use this for every OS? + # shellcheck disable=SC2015 [ -d "$path" ] && ( + # shellcheck disable=SC1007 cd_path= \cd "$1" /bin/pwd ) || ( + # shellcheck disable=SC1007 cd_path= \cd "$(dirname "$1")" && printf "%s/%s\n" "$(/bin/pwd)" "$(basename "$1")" ) @@ -761,7 +771,7 @@ function atfile.util.get_var_from_file() { found_line="$(cat "$file" | grep "\b${variable}=")" if [[ -n "$found_line" ]] && [[ ! "$found_line" == \#* ]]; then - output="$(echo $found_line | sed "s|${variable}=||g")" + output="$(echo "$found_line" | sed "s|${variable}=||g")" output="${output%\"}" output="${output#\"}" @@ -871,7 +881,7 @@ function atfile.util.get_uri_segment() { case $segment in "host") echo "$uri" | cut -d "/" -f 3 ;; "protocol") echo "$uri" | cut -d ":" -f 1 ;; - *) echo "$uri" | cut -d "/" -"f $segme"nt ;; + *) echo "$uri" | cut -d "/" -f "$segment" ;; esac } @@ -904,7 +914,7 @@ function atfile.util.map_http_to_at() { fi fi - echo $at_uri + echo "$at_uri" } # HACK: This essentially breaks the entire session (it overrides $_username and @@ -956,7 +966,7 @@ function atfile.util.parse_version() { v_major="$(printf "%04d\n" "$(echo "$version" | cut -d "." -f 1)")" v_minor="$(printf "%04d\n" "$(echo "$version" | cut -d "." -f 2)")" v_rev="$(printf "%04d\n" "$(echo "$version" | cut -d "." -f 3)")" - echo "$(echo ${v_major}${v_minor}${v_rev} | sed 's/^0*//')" + echo "$(echo "${v_major}${v_minor}${v_rev}" | sed 's/^0*//')" } function atfile.util.print_blob_url_output() { @@ -1047,7 +1057,7 @@ function atfile.util.resolve_identity() { didplc_dir="$(echo "$did_doc" | jq -r ".directory")" pds="$(echo "$did_doc" | jq -r '.service[] | select(.id == "#atproto_pds") | .serviceEndpoint')" - while IFS=$"\n" read -r a; do + while IFS=$'\n' read -r a; do aliases+="$a;" if [[ -z $handle && "$a" == "at://"* && "$a" != "at://did:"* ]]; then @@ -1074,5 +1084,7 @@ function atfile.util.write_cache() { atfile.util.get_cache "$file" echo -e "$content" > "$file_path" + # shellcheck disable=SC2320 + # shellcheck disable=SC2181 [[ $? != 0 ]] && atfile.die "Unable to write to cache file ($file)" } diff --git a/src/shared/xrpc.sh b/src/shared/xrpc.sh index 662ce03..abaef96 100644 --- a/src/shared/xrpc.sh +++ b/src/shared/xrpc.sh @@ -34,7 +34,7 @@ function atfile.xrpc.pds.get() { function atfile.xrpc.pds.jwt() { atfile.http.post \ "$_server/xrpc/com.atproto.server.createSession" \ - '{"identifier": "'$_username'", "password": "'$_password'"}' | jq -r ".accessJwt" + '{"identifier": "'"$_username"'", "password": "'"$_password"'"}' | jq -r ".accessJwt" } function atfile.xrpc.pds.post() { @@ -44,7 +44,7 @@ function atfile.xrpc.pds.post() { [[ -z $type ]] && type="application/json" - curl -s -X POST $_server/xrpc/$lexi \ + curl -s -X POST "$_server/xrpc/$lexi" \ -H "Authorization: Bearer $(atfile.xrpc.pds.jwt)" \ -H "Content-Type: $type" \ -H "User-Agent: $(atfile.util.get_uas)" \