···4141 * [MediaInfo (`mediainfo`)](https://mediaarea.net/en/MediaInfo) _(optional: set `ATFILE_DISABLE_NI_MEDIAINFO=1` to ignore)_
4242 * `md5sum` _(optional: set `ATFILE_DISABLE_NI_MD5SUM=1` to ignore)_
4343 * Both GNU and BusyBox versions supported
4444+ * `sed`
4545+ * Only GNU version supported
4446 * [`websocat`](https://github.com/vi/websocat) _(optional: needed for `stream`)_
4547* **ATProto account**
4648 * Limit the amount of files you upload, and avoid copyrighted files, if using a managed PDS<br /><em>(e.g. [Blacksky](https://pds.blacksky.app), [Bluesky](https://bsky.social), [Spark](https://pds.sprk.so), [Tangled](https://tngl.sh), or any other independent PDS you don't own)</eM>
···6769* __Linux/*BSD/Solaris/SerenityOS__
6870 * Install: `$HOME/.local/bin/atfile`
6971 * As `sudo`/`root`: `/usr/local/bin/atfile`
7272+ * On **Termux:** `/usr/bin/atfile`
7073 * Config: `$HOME/.config/atfile.env`, **or** `$XDG_CONFIG_HOME/atfile.env` (if set)
7174* **macOS**
7275 * Install: `$HOME/.local/bin/atfile`
···102105103106Various environment variables can be exported to control various aspects of the development version. These are as follows:
104107108108+* `ATFILE_DEVEL_DIST_USERNAME` <em><string></em><br />_(Todo)_. During runtime, this is set to `$did` in `atfile.sh` (see **๐๏ธ Building โ Meta**). Ideally, you should not set this variable as updates in the built version will not be fetched from the correct place
109109+* `ATFILE_DEVEL_DIST_PASSWORD` <em><string></em><br />_(Todo)_
105110* `ATFILE_DEVEL_ENABLE_PIPING` <em><int> (default: `0`)</em><br />Allow piping (useful to test installation) _(e.g. `cat ./atfile.sh | bash`)_
106106-* `ATFILE_DEVEL_ENABLE_PUBLISH` <em><int> (default: `0`)</em><br />Publish build to ATProto repository (to allow for updating) as the last step when running `release`. Several requirements must be fulfilled to succeed:
107107- * `ATFILE_DEVEL_DIST_USERNAME` must be set<br />By default, this is set to `$did` in `atfile.sh` (see **๐๏ธ Building โ Meta**). Ideally, you should not set this variable as updates in the built version will not be fetched from the correct place
111111+* `ATFILE_DEVEL_ENABLE_PUBLISH` <em><int> (default: `0`)</em><br />Publish build to ATProto repository (to allow for updating) as the last step when running `build`. Several requirements must be fulfilled:
112112+ * `ATFILE_DEVEL_DIST_USERNAME` must be set
108113 * `ATFILE_DEVEL_DIST_PASSWORD` must be set
109114 * No tests should return an **Error** (**Warning** is acceptable)
110115 * Git commit must be <a href="https://git-scm.com/docs/git-tag">tagged</a>
···119124120125### Meta
121126122122-Various meta variables can be set to be available in the final compiled build (usually found in `help`). These are found in `atfile.sh` under `# Meta`. These variables are as follows:
127127+Various meta variables can be set to be available in the final compiled build (usually found in `help`). These are found in `atfile.sh` under `# Meta`. These are as follows:
123128124129* `author` <em><string></em><br />Copyright author
125130* `did` <em><did></em><br />DID of copyright author. Also used as the source for published builds, unless `ATFILE_DEVEL_DIST_USERNAME` is set (see **๐๏ธ Building โ Environment variables**)
···137142138143* **Paul Frazee** — [๐ฆ @pfrazee.com](https://bsky.app/profile/did:plc:ragtjsm2j2vknwkz3zp4oxrd)<br /><a href="https://bsky.app/profile/did:plc:ragtjsm2j2vknwkz3zp4oxrd/post/3l63zzvthqj2o">His kind words</a>
139144* **Laurens Hof** — [๐ฆ @laurenshof.online](https://bsky.app/profile/did:plc:mdjhvva6vlrswsj26cftjttd)<br />Featuring ATFile on [The Fediverse Report](https://fediversereport.com): _["Last Week in the ATmosphere โ Oct 2024 week 4"](https://fediversereport.com/last-week-in-the-atmosphere-oct-2024-week-4/)_
140140-* **Samir** — [๐ @bdotsamir](https://github.com/bdotsamir)<br />Testing, and diagnosing problems with, support for macOS (`macos`)
141141-* **Astra** — [๐ฆ @astra.blue](https://bsky.app/profile/did:plc:ejy6lkhb72rxvkk57tnrmpjl)<br />[Various PRs](https://github.com/ziodotsh/atfile/pulls?q=is%3Apr+author%3Aastravexton); testing, and diagnosing problems with, support for MinGW (`linux-mingw`) and Termux (`linux-termux`)
145145+* All contributors on [Tangled](https://tangled.org/@zio.sh/atfile/pulls) and [GitHub](https://github.com/ziodotsh/atfile/pulls)
142146* _(Forgot about you? [You know what to do](https://tangled.sh/@zio.sh/atfile/pulls/new))_
143147144148---
···149153* **ยฒ** musl-powered distros do not use GNU/glibc packages, and have problems currently
150154 * Known musl distros: Alpine, Chimera, Dragora, Gentoo (musl), Morpheus, OpenWrt, postmarketOS, Sabotage, Void
151155 * Bypassing OS detection (see ยน) will cause unintended behavior
152152-* **ยณ** As long as you have Bash installed, running from another shell will not be problematic ([`#!/usr/bin/env bash`](https://tangled.sh/@zio.sh/atfile/blob/main/atfile-install.sh#L1) forces Bash)
156156+* **ยณ** As long as you have Bash installed, running from another shell will not be problematic ([`#!/usr/bin/env bash`](https://tangled.sh/@zio.sh/atfile/blob/main/atfile.sh#L1) forces Bash)
···11+#!/usr/bin/env bash
22+33+function atfile.handle() {
44+ uri="$1"
55+ handler="$2"
66+77+ function atfile.handle.is_temp_file_needed() {
88+ handler="${1//.desktop/}"
99+ type="$2"
1010+1111+ handlers_needing_tmp_file=(
1212+ "app.drey.EarTag"
1313+ "com.github.neithern.g4music"
1414+ )
1515+1616+ if [[ ${handlers_needing_tmp_file[*]} =~ $handler ]]; then
1717+ echo 1
1818+ elif [[ $type == "text/"* ]]; then
1919+ echo 1
2020+ else
2121+ echo 0
2222+ fi
2323+ }
2424+2525+ # shellcheck disable=SC2154
2626+ [[ $_output_json == 1 ]] && atfile.die "Command not available as JSON"
2727+2828+ actor="$(echo "$uri" | cut -d "/" -f 3)"
2929+ key="$(echo "$uri" | cut -d "/" -f 4)"
3030+3131+ # shellcheck disable=SC2154
3232+ atfile.util.create_dir "$_path_blobs_tmp"
3333+3434+ if [[ -n "$actor" && -n "$key" ]]; then
3535+ atfile.util.override_actor "$actor"
3636+3737+ # shellcheck disable=SC2154
3838+ atfile.say.debug "Getting record...\nโณ NSID: $_nsid_upload\nโณ Repo: $_username\nโณ Key: $key"
3939+ record="$(com.atproto.repo.getRecord "$_username" "$_nsid_upload" "$key")"
4040+ error="$(atfile.util.get_xrpc_error $? "$record")"
4141+ [[ -n "$error" ]] && atfile.die.gui.xrpc_error "Unable to get '$key'" "$error"
4242+4343+ blob_cid="$(echo "$record" | jq -r ".value.blob.ref.\"\$link\"")"
4444+ blob_uri="$(atfile.util.build_blob_uri "$_username" "$blob_cid")"
4545+ file_type="$(echo "$record" | jq -r '.value.file.mimeType')"
4646+4747+ # shellcheck disable=SC2154
4848+ if [[ $_os == "linux"* ]] && \
4949+ [ -x "$(command -v xdg-mime)" ] && \
5050+ [ -x "$(command -v xdg-open)" ] && \
5151+ [ -x "$(command -v gtk-launch)" ]; then
5252+5353+ # HACK: Open with browser if $file_type isn't set
5454+ [[ -z $file_type ]] && file_type="text/html"
5555+5656+ if [[ -z $handler ]]; then
5757+ atfile.say.debug "Querying for handler '$file_type'..."
5858+ handler="$(xdg-mime query default "$file_type")"
5959+ else
6060+ handler="$handler.desktop"
6161+ atfile.say.debug "Handler manually set to '$handler'"
6262+ fi
6363+6464+ # shellcheck disable=SC2319
6565+ # shellcheck disable=SC2181
6666+ if [[ -n $handler ]] || [[ $? != 0 ]]; then
6767+ atfile.say.debug "Opening '$key' ($file_type) with '${handler//.desktop/}'..."
6868+6969+ # HACK: Some apps don't like http(s)://; we'll need to handle these
7070+ if [[ $(atfile.handle.is_temp_file_needed "$handler" "$file_type") == 1 ]]; then
7171+ atfile.say.debug "Unsupported for streaming"
7272+7373+ download_success=1
7474+ # shellcheck disable=SC2154
7575+ tmp_path="$_path_blobs_tmp/$blob_cid"
7676+7777+ if ! [[ -f "$tmp_path" ]]; then
7878+ atfile.say.debug "Downloading '$blob_cid'..."
7979+ atfile.http.download "$blob_uri" "$tmp_path"
8080+ [[ $? != 0 ]] && download_success=0
8181+ else
8282+ atfile.say.debug "Blob '$blob_cid' already exists"
8383+ fi
8484+8585+ if [[ $download_success == 1 ]]; then
8686+ atfile.say.debug "Launching '$handler'..."
8787+ gtk-launch "$handler" "$tmp_path" </dev/null &>/dev/null &
8888+ else
8989+ atfile.die.gui \
9090+ "Unable to download '$key'"
9191+ fi
9292+ else
9393+ atfile.say.debug "Launching '$handler'..."
9494+ gtk-launch "$handler" "$blob_uri" </dev/null &>/dev/null &
9595+ fi
9696+ else
9797+ atfile.say.debug "No handler for '$file_type'. Launching URI..."
9898+ atfile.util.launch_uri "$blob_uri"
9999+ fi
100100+ else
101101+ atfile.say.debug "Relevant tools not installed. Launching URI..."
102102+ atfile.util.launch_uri "$blob_uri"
103103+ fi
104104+ else
105105+ atfile.die.gui \
106106+ "Invalid ATFile URI\nโณ Must be 'atfile://<actor>/<key>'" \
107107+ "Invalid ATFile URI"
108108+ fi
109109+}
+6-4
src/commands/help.sh
···7575 bsky [<actor>]
7676 Get Bluesky profile for <actor>\n
7777 handle <at-uri>
7878- Open at:// URI with relevant App\n
7878+ Open at:// URI with PDSls\n
7979 handle <atfile-uri> [<handler>]
8080 Open atfile:// URI with relevant App
8181 โน๏ธ Set <handler> to a .desktop entry (with '.desktop') to force the
···132132 Endpoint of the PDS
133133 โน๏ธ Your PDS is resolved from your username. Set to override it (or if
134134 resolving fails)
135135+ ${_envvar_prefix}_ENDPOINT_PDSLS <url> (default: ${_endpoint_pdsls_default})
136136+ Endpoint of PDSls
135137 ${_envvar_prefix}_ENDPOINT_PLC_DIRECTORY <url> (default: ${_endpoint_plc_directory_default}$([[ $_endpoint_plc_directory_default == *"zio.blue" ]] && echo "ยฒ"))
136138 Endpoint of the PLC directory
137139 ${_envvar_prefix}_ENDPOINT_SOCIAL_APP <url> (default: ${_endpoint_social_app_default})
···162164 Disable periodic update checking when command finishes
163165 ${_envvar_prefix}_DISABLE_UPDATE_COMMAND <boolยน> (default: $_disable_update_command_default)
164166 Disable \`update\` command\n
165165- ${_envvar_prefix}_DEBUG <boolยน> (default: 0)
167167+ ${_envvar_prefix}_DEBUGยณ <boolยน> (default: 0)
166168 Print debug outputs
167169 โ ๏ธ When output is JSON (${_envvar_prefix}_OUTPUT_JSON=1), sets to 0\n
168170 ยน A bool in Bash is 1 (true) or 0 (false)
169169- ยฒ These servers are ran by @$handle. You can trust us!"
171171+ ยฒ These servers are ran by @$handle. You can trust us!
172172+ ยณ Cannot be set by config file"
170173171174 usage_paths="Paths
172175 $_path_envvar
···190193191194Usage
192195 $_prog <command> [<arguments>]
193193- $_prog at://<actor>[/<collection>/<rkey>]
194196 $_prog atfile://<actor>/<key>\n\n"
195197196198 [[ $ATFILE_DEVEL == 1 ]] && usage+="$usage_commands_devel\n\n"
+12-2
src/commands/install.sh
···2525 fi
26262727 case $_os in
2828+ "linux-termux")
2929+ # NOTE: The correct path of '$PREFIX/local/bin' would be more correct,
3030+ # however, '$PREFIX/local' doesn't exist by default on Termux (and thus,
3131+ # not in $PATH), so we'll install it in '$PREFIX/bin' instead
3232+ # shellcheck disable=SC2153
3333+ install_dir="$PREFIX/bin"
3434+ ;;
2835 "haiku")
2936 install_dir="/boot/system/non-packaged/bin"
3037 ;;
···3946 esac
40474148 if [[ $# -gt 0 ]]; then
4242- atfile.say.debug "Overriden variables\nโณ Path: $override_path\nโณ Version: $override_version\nโณ DID: $override_did"
4949+ atfile.say.debug "Overridden variables\nโณ Path: $override_path\nโณ Version: $override_version\nโณ DID: $override_did"
4350 fi
44514552 atfile.say.debug "Setting up..."
46534754 [[ -n "$override_path" ]] && install_dir="$override_path"
5555+ mkdir -p "$install_dir"
4856 mkdir -p "$conf_dir"
4957 # shellcheck disable=SC2154
5058 touch "$conf_dir/$_file_envvar"
···9410295103 atfile.say.debug "Found latest version\nโณ Version: $found_version ($parsed_found_version)\nโณ Source: $source_did\nโณ Blob: $found_version_blob"
961049797- atfile.say.debug "Download '$blob_url'..."
105105+ atfile.say.debug "Downloading...\nโณ Source: $blob_url\nโณ Dest.: ${install_dir}/$install_file"
9810699107 curl -s -o "${install_dir}/$install_file" "$blob_url"
108108+ # shellcheck disable=SC2181
100109 [[ $? != 0 ]] && atfile.die "Unable to download"
101110102111 atfile.say.debug "Installing...\nโณ OS: $_os\nโณ Install: $install_dir/$install_file\nโณ Config: $conf_dir/$_file_envvar"
···108117 atfile.say.debug "Creating config file..."
109118110119 echo -e "ATFILE_USERNAME=<your-username>\nATFILE_PASSWORD=<your-password>" > "$conf_dir/$_file_envvar"
120120+ # shellcheck disable=SC2320
111121 [[ $? != 0 ]] && die "Unable to create config file ($conf_dir/$_file_envvar)"
112122 fi
113123
-172
src/commands/old_cmds.sh
···289289 fi
290290}
291291292292-function atfile.invoke.handle_atfile() {
293293- uri="$1"
294294- handler="$2"
295295-296296- function atfile.invoke.handle_atfile.is_temp_file_needed() {
297297- handler="${1//.desktop/}"
298298- type="$2"
299299-300300- handlers=(
301301- "app.drey.EarTag"
302302- "com.github.neithern.g4music"
303303- )
304304-305305- if [[ ${handlers[*]} =~ $handler ]]; then
306306- echo 1
307307- elif [[ $type == "text/"* ]]; then
308308- echo 1
309309- else
310310- echo 0
311311- fi
312312- }
313313-314314- [[ $_output_json == 1 ]] && atfile.die "Command not available as JSON"
315315-316316- actor="$(echo "$uri" | cut -d "/" -f 3)"
317317- key="$(echo "$uri" | cut -d "/" -f 4)"
318318-319319- if [[ -n "$actor" && -n "$key" ]]; then
320320- atfile.util.override_actor "$actor"
321321-322322- atfile.say.debug "Getting record...\nโณ NSID: $_nsid_upload\nโณ Repo: $_username\nโณ Key: $key"
323323- record="$(com.atproto.repo.getRecord "$_username" "$_nsid_upload" "$key")"
324324- error="$(atfile.util.get_xrpc_error $? "$record")"
325325- [[ -n "$error" ]] && atfile.die.gui.xrpc_error "Unable to get '$key'" "$error"
326326-327327- blob_cid="$(echo "$record" | jq -r ".value.blob.ref.\"\$link\"")"
328328- blob_uri="$(atfile.util.build_blob_uri "$_username" "$blob_cid")"
329329- file_type="$(echo "$record" | jq -r '.value.file.mimeType')"
330330-331331- if [[ $_os == "linux"* ]] && \
332332- [ -x "$(command -v xdg-mime)" ] && \
333333- [ -x "$(command -v xdg-open)" ] && \
334334- [ -x "$(command -v gtk-launch)" ]; then
335335-336336- # HACK: Open with browser if $file_type isn't set
337337- [[ -z $file_type ]] && file_type="text/html"
338338-339339- if [[ -z $handler ]]; then
340340- atfile.say.debug "Querying for handler '$file_type'..."
341341- handler="$(xdg-mime query default "$file_type")"
342342- else
343343- handler="$handler.desktop"
344344- atfile.say.debug "Handler manually set to '$handler'"
345345- fi
346346-347347- # shellcheck disable=SC2319
348348- # shellcheck disable=SC2181
349349- if [[ -n $handler ]] || [[ $? != 0 ]]; then
350350- atfile.say.debug "Opening '$key' ($file_type) with '${handler//.desktop/}'..."
351351-352352- # HACK: Some apps don't like http(s)://; we'll need to handle these
353353- if [[ $(atfile.invoke.handle_atfile.is_temp_file_needed "$handler" "$file_type") == 1 ]]; then
354354- atfile.say.debug "Unsupported for streaming"
355355-356356- download_success=1
357357- # shellcheck disable=SC2154
358358- tmp_path="$_path_blobs_tmp/$blob_cid"
359359-360360- if ! [[ -f "$tmp_path" ]]; then
361361- atfile.say.debug "Downloading '$blob_cid'..."
362362- atfile.http.download "$blob_uri" "$tmp_path"
363363- [[ $? != 0 ]] && download_success=0
364364- else
365365- atfile.say.debug "Blob '$blob_cid' already exists"
366366- fi
367367-368368- if [[ $download_success == 1 ]]; then
369369- atfile.say.debug "Launching '$handler'..."
370370- gtk-launch "$handler" "$tmp_path" </dev/null &>/dev/null &
371371- else
372372- atfile.die.gui \
373373- "Unable to download '$key'"
374374- fi
375375- else
376376- atfile.say.debug "Launching '$handler'..."
377377- gtk-launch "$handler" "$blob_uri" </dev/null &>/dev/null &
378378- fi
379379- else
380380- atfile.say.debug "No handler for '$file_type'. Launching URI..."
381381- atfile.util.launch_uri "$blob_uri"
382382- fi
383383- else
384384- atfile.say.debug "Relevant tools not installed. Launching URI..."
385385- atfile.util.launch_uri "$blob_uri"
386386- fi
387387- else
388388- atfile.die.gui \
389389- "Invalid ATFile URI\nโณ Must be 'atfile://<actor>/<key>'" \
390390- "Invalid ATFile URI"
391391- fi
392392-}
393393-394394-function atfile.invoke.handle_aturi() {
395395- uri="$1"
396396-397397- [[ $_output_json == 1 ]] && atfile.die "Command not available as JSON"
398398- [[ "$uri" != "at://"* ]] && atfile.die.gui \
399399- "Invalid AT URI\nโณ Must be 'at://<actor>[/<collection>/<rkey>]'" \
400400- "Invalid AT URI"
401401-402402- atfile.say.debug "Resolving '$uri'..."
403403- app_uri="$(atfile.util.get_app_url_for_at_uri "$uri")"
404404- [[ -z "$app_uri" ]] && atfile.die.gui \
405405- "Unable to resolve AT URI to App"
406406-407407- app_proto="$(echo "$app_uri" | cut -d ":" -f 1)"
408408-409409- atfile.say.debug "Opening '$app_uri' ($app_proto)..."
410410-411411- if [[ $app_proto == "atfile" ]]; then
412412- atfile.invoke.handle_atfile "$app_uri"
413413- else
414414- atfile.util.launch_uri "$app_uri"
415415- fi
416416-}
417417-418292function atfile.invoke.list() {
419293 cursor="$1"
420294 unset error
···539413540414 if [[ -n "$error" ]]; then
541415 atfile.die "Unable to cat '$key'" "$error"
542542- fi
543543-}
544544-545545-function atfile.invoke.toggle_desktop() {
546546- unset desktop_dir
547547- unset mime_dir
548548-549549- [[ $_os == "haiku" ]] && atfile.die "Not available on Haiku"
550550- [[ $_os == "macos" ]] && atfile.die "Not available on macOS\nThink you could help? See: https://tangled.sh/@zio.sh/atfile/issues/9"
551551-552552- uid="$(id -u)"
553553- if [[ $uid == 0 ]]; then
554554- desktop_dir="/usr/local/share/applications"
555555- mime_dir="/usr/local/share/mime"
556556- else
557557- desktop_dir="$HOME/.local/share/applications"
558558- mime_dir="$HOME/.local/share/mime"
559559- fi
560560-561561- desktop_path="$desktop_dir/atfile-handler.desktop"
562562- mkdir -p "$desktop_dir"
563563- mkdir -p "$mime_dir"
564564-565565- if [[ -f "$desktop_path" ]]; then
566566- atfile.say "Removing '$desktop_path'..."
567567- rm "$desktop_path"
568568- else
569569- atfile.say "Installing '$desktop_path'..."
570570-571571- echo "[Desktop Entry]
572572-Name=ATFile (Handler)
573573-Description=Handle atfile:/at: URIs with ATFile
574574-Exec=$_prog_path handle %U
575575-Terminal=false
576576-Type=Application
577577-MimeType=x-scheme-handler/at;x-scheme-handler/atfile;
578578-NoDisplay=true" > "$desktop_path"
579579- fi
580580-581581- if [ -x "$(command -v xdg-mime)" ] &&\
582582- [ -x "$(command -v update-mime-database)" ]; then
583583- atfile.say "Updating mime database..."
584584-585585- update-mime-database "$mime_dir"
586586- xdg-mime default atfile-handler.desktop x-scheme-handler/at
587587- xdg-mime default atfile-handler.desktop x-scheme-handler/atfile
588416 fi
589417}
590418
+2
src/commands/record.sh
···4848 at_collection="$(atfile.util.parse_at_uri "$at_uri" "collection")"
4949 at_rkey="$(atfile.util.parse_at_uri "$at_uri" "rkey")"
50505151+ atfile.say.debug "Resolved AT URI\nโณ Actor: $at_actor\nโณ Collection: $at_collection\nโณ RKey: $at_rkey"
5252+5153 case "$sub_command" in
5254 "create")
5355 if [[ -z "$at_rkey" ]]; then
-186
src/commands/release.sh
···11-#!/usr/bin/env bash
22-# atfile-devel=ignore-build
33-44-function atfile.release() {
55- # shellcheck disable=SC2154
66- [[ $_os != "linux" ]] && atfile.die "Only available on Linux (GNU)\nโณ Detected OS: $_os"
77-88- function atfile.release.get_devel_value() {
99- local file="$1"
1010- local value="$2"
1111- local found_line
1212-1313- found_line="$(grep '^# atfile-devel=' "$file" | head -n1)"
1414- if [[ -n "$found_line" ]]; then
1515- local devel_values="${found_line#*=}"
1616- IFS=',' read -ra arr <<< "$devel_values"
1717- for v in "${arr[@]}"; do
1818- if [[ "$v" == "$value" ]]; then
1919- echo 1
2020- fi
2121- done
2222- fi
2323- }
2424-2525- function atfile.release.replace_template_var() {
2626- string="$1"
2727- key="$2"
2828- value="$3"
2929-3030- sed -s "s|{:$key:}|$value|g" <<< "$string"
3131- }
3232-3333- atfile.util.check_prog "git"
3434- atfile.util.check_prog "md5sum"
3535- atfile.util.check_prog "shellcheck"
3636-3737- id="$(atfile.util.get_random 13)"
3838- commit_author="$(git config user.name) <$(git config user.email)>"
3939- commit_hash="$(git rev-parse HEAD)"
4040- commit_date="$(git show --no-patch --format=%ci "$commit_hash")"
4141- # shellcheck disable=SC2154
4242- dist_file="$(echo "$_prog" | cut -d "." -f 1)-${_version}.sh"
4343- # shellcheck disable=SC2154
4444- dist_dir="$_prog_dir/bin"
4545- dist_path="$dist_dir/$dist_file"
4646- dist_path_relative="$(realpath --relative-to="$(pwd)" "$dist_path")"
4747- parsed_version="$(atfile.util.parse_version "$_version")"
4848- version_record_id="atfile-$parsed_version"
4949-5050- test_error_count=0
5151- test_info_count=0
5252- test_style_count=0
5353- test_warning_count=0
5454- test_ignore_count=0
5555-5656- atfile.say "โ๏ธ Building..."
5757-5858- echo "โณ Creating '$dist_file'..."
5959- mkdir -p "$dist_dir"
6060- echo "#!/usr/bin/env bash" > "$dist_path"
6161-6262- echo "โณ Generating header..."
6363- echo -e "\n# ATFile <${ATFILE_FORCE_META_REPO}>
6464-# ---
6565-# Version: $_version
6666-# Commit: $commit_hash
6767-# Author: $commit_author
6868-# Build: $id ($(hostname):$(atfile.util.get_os))
6969-# ---
7070-# Psst! You can \`source atfile\` in your own Bash scripts!
7171-" >> "$dist_path"
7272-7373- for s in "${ATFILE_DEVEL_INCLUDES[@]}"
7474- do
7575- if [[ -f "$s" ]]; then
7676- if [[ $(atfile.release.get_devel_value "$s" "ignore-build" == 1 ) ]]; then
7777- echo "โณ Ignoring: $s"
7878- else
7979- echo "โณ Compiling: $s"
8080-8181- while IFS="" read -r line
8282- do
8383- include_line=1
8484-8585- if [[ $line == "#"* ]] ||\
8686- [[ $line == *" #"* ]] ||\
8787- [[ $line == " " ]] ||\
8888- [[ $line == "" ]]; then
8989- include_line=0
9090- fi
9191-9292- if [[ $line == *"# shellcheck disable"* ]]; then
9393- if [[ $line == *"=SC2154"* ]]; then
9494- include_line=0
9595- else
9696- include_line=1
9797- (( test_ignore_count++ ))
9898- fi
9999- fi
100100-101101- if [[ $include_line == 1 ]]; then
102102- if [[ $line == *"{:"* && $line == *":}"* ]]; then
103103- # NOTE: Not using atfile.util.get_envvar() here, as confusion can arise from config file
104104- line="$(atfile.release.replace_template_var "$line" "meta_author" "$ATFILE_FORCE_META_AUTHOR")"
105105- line="$(atfile.release.replace_template_var "$line" "meta_did" "$ATFILE_FORCE_META_DID")"
106106- line="$(atfile.release.replace_template_var "$line" "meta_repo" "$ATFILE_FORCE_META_REPO")"
107107- line="$(atfile.release.replace_template_var "$line" "meta_year" "$ATFILE_FORCE_META_YEAR")"
108108- line="$(atfile.release.replace_template_var "$line" "version" "$ATFILE_FORCE_VERSION")"
109109- fi
110110-111111- echo "$line" >> "$dist_path"
112112- fi
113113- done < "$s"
114114- fi
115115- fi
116116- done
117117-118118- echo -e "\n# \"Four million lines of BASIC\"\n# - Kif Kroker (3003)" >> "$dist_path"
119119-120120- checksum="$(atfile.util.get_md5 "$dist_path" | cut -d "|" -f 1)"
121121-122122- echo "๐งช Testing..."
123123- shellcheck_output="$(shellcheck --format=json "$dist_path" 2>&1)"
124124-125125- while read -r item; do
126126- code="$(echo "$item" | jq -r '.code')"
127127- col="$(echo "$item" | jq -r '.column')"
128128- line="$(echo "$item" | jq -r '.line')"
129129- level="$(echo "$item" | jq -r '.level')"
130130- message="$(echo "$item" | jq -r '.message')"
131131-132132- case "$level" in
133133- "error") level="๐ Error"; (( test_error_count++ )) ;;
134134- "info") level="โน๏ธ Info"; (( test_info_count++ )) ;;
135135- "style") level="๐จ Style"; (( test_style_count++ )) ;;
136136- "warning") level="โ ๏ธ Warning"; (( test_warning_count++ )) ;;
137137- esac
138138-139139- echo "โณ $level ($line:$col): [SC$code] $message"
140140- done <<< "$(echo "$shellcheck_output" | jq -c '.[]')"
141141-142142- test_total_count=$(( test_error_count + test_info_count + test_style_count + test_warning_count ))
143143-144144- echo -e "---\nโ Built: $_version
145145-โณ Path: ./$dist_path_relative
146146- โณ Check: $checksum
147147- โณ Size: $(atfile.util.get_file_size_pretty "$(stat -c %s "$dist_path")")
148148- โณ Lines: $(atfile.util.fmt_int "$(wc -l < "$dist_path")")
149149-โณ Issues: $(atfile.util.fmt_int "$test_total_count")
150150- โณ Error: $(atfile.util.fmt_int "$test_error_count")
151151- โณ Warning: $(atfile.util.fmt_int "$test_warning_count")
152152- โณ Info: $(atfile.util.fmt_int "$test_info_count")
153153- โณ Style: $(atfile.util.fmt_int "$test_style_count")
154154- โณ Ignored: $(atfile.util.fmt_int "$test_ignore_count")
155155-โณ ID: $id"
156156-157157- chmod +x "$dist_path"
158158-159159- # shellcheck disable=SC2154
160160- if [[ $_devel_enable_publish == 1 ]]; then
161161- if [[ $test_error_count -gt 0 ]]; then
162162- atfile.die "Unable to publish ($test_error_count errors detected)"
163163- fi
164164-165165- atfile.say "---\nโจ Updating..."
166166- atfile.auth "$_devel_dist_username" "$_devel_dist_password"
167167- [[ $_version == *"+"* ]] && atfile.die "Cannot publish a Git version ($_version)"
168168-169169- atfile.say "โณ Uploading '$dist_path'..."
170170- atfile.invoke.upload "$dist_path" "" "$version_record_id"
171171- # shellcheck disable=SC2181
172172- [[ $? != 0 ]] && atfile.die "Unable to upload '$dist_path'"
173173-174174- latest_release_record="{
175175- \"version\": \"$_version\",
176176- \"releasedAt\": \"$(atfile.util.get_date "$commit_date")\",
177177- \"commit\": \"$commit_hash\",
178178- \"id\": \"$id\",
179179- \"checksum\": \"$checksum\"
180180-}"
181181-182182- atfile.say "โณ Bumping current version..."
183183- # shellcheck disable=SC2154
184184- atfile.invoke.manage_record put "at://$_devel_dist_username/self.atfile.latest/self" "$latest_release_record" &> /dev/null
185185- fi
186186-}