๐Ÿ“ฆโž”๐Ÿฆ‹ Store and retrieve files on the Atmosphere
34
fork

Configure Feed

Select the types of activity you want to include in your feed.

remove atfile-install

Ducky 2d625678 62e6911b

-131
-131
atfile-install.sh
··· 1 - #!/usr/bin/env bash 2 - 3 - function die() { 4 - echo -e "\033[1;31mError: $1\033[0m" 5 - exit 255 6 - } 7 - 8 - function check_prog() { 9 - prog="$1" 10 - ! [ -x "$(command -v "$prog")" ] && die "'$prog' not installed" 11 - } 12 - 13 - function get_os() { 14 - os="$OSTYPE" 15 - 16 - case $os in 17 - # Linux 18 - "linux-gnu") echo "linux" ;; 19 - "cygwin"|"msys") echo "linux-mingw" ;; 20 - "linux-musl") echo "linux-musl" ;; 21 - "linux-android") echo "linux-termux" ;; 22 - # BSD 23 - "FreeBSD"*|"freebsd"*) echo "bsd-freebsd" ;; 24 - "netbsd"*) echo "bsd-netbsd" ;; 25 - "openbsd"*) echo "bsd-openbsd" ;; 26 - *"bsd"*) echo "bsd-unknown" ;; 27 - # Misc. 28 - "haiku") echo "haiku" ;; 29 - "darwin"*) echo "macos" ;; 30 - "solaris"*) echo "solaris" ;; 31 - # Unknown 32 - *) echo "unknown-$OSTYPE" ;; 33 - esac 34 - } 35 - 36 - function parse_version() { 37 - version="$1" 38 - version="$(echo "$version" | cut -d "+" -f 1)" 39 - v_major="$(printf "%04d\n" "$(echo "$version" | cut -d "." -f 1)")" 40 - v_minor="$(printf "%04d\n" "$(echo "$version" | cut -d "." -f 2)")" 41 - v_rev="$(printf "%04d\n" "$(echo "$version" | cut -d "." -f 3)")" 42 - echo "${v_major}${v_minor}${v_rev}" | sed 's/^0*//' 43 - } 44 - 45 - function xrpc_get() { 46 - lexi="$1" 47 - collection="$2" 48 - key="$3" 49 - 50 - curl -s -L -X GET "$pds/xrpc/$lexi?collection=$collection&repo=$did&rkey=$key" 51 - } 52 - 53 - check_prog "curl" 54 - check_prog "jq" 55 - 56 - uid="$(id -u)" 57 - did="did:web:zio.sh" 58 - pds="https://zio.blue" 59 - install_file="atfile" 60 - conf_file="atfile.env" 61 - unset install_dir 62 - unset conf_dir 63 - 64 - latest_version_record="$(xrpc_get "com.atproto.repo.getRecord" "self.atfile.latest" "self")" 65 - [[ $? != 0 ]] && die "Unable to get latest version" 66 - 67 - latest_version="$(echo "$latest_version_record" | jq -r '.value.version')" 68 - parsed_latest_version="$(parse_version "$latest_version")" 69 - found_version_record="$(xrpc_get "com.atproto.repo.getRecord" "blue.zio.atfile.upload" "atfile-$parsed_latest_version")" 70 - [[ $? != 0 ]] && die "Unable to fetch record for '$parsed_latest_version'" 71 - 72 - found_version_blob="$(echo "$found_version_record" | jq -r ".value.blob.ref.\"\$link\"")" 73 - url="$pds/blob/$did/$found_version_blob" 74 - 75 - if [[ $(get_os) == "haiku" ]]; then 76 - install_dir="/boot/system/non-packaged/bin" 77 - conf_dir="$HOME/config/settings" 78 - else 79 - if [[ $uid == 0 ]]; then 80 - install_dir="/usr/local/bin" 81 - 82 - if [[ -z $SUDO_DIR ]]; then 83 - conf_dir="/root/.config" 84 - else 85 - if [[ $(get_os) == "macos" ]]; then 86 - conf_dir="$(eval echo ~"$SUDO_USER")/Library/Application Support" 87 - else 88 - conf_dir="$(eval echo ~"$SUDO_USER")/.config" 89 - fi 90 - fi 91 - else 92 - install_dir="$(eval echo ~"$USER")/.local/bin" 93 - conf_dir="$(eval echo ~"$USER")/.config" 94 - 95 - if [[ $(get_os) == "macos" ]]; then 96 - conf_dir="$(eval echo ~"$USER")/Library/Application Support" 97 - else 98 - conf_dir="$(eval echo ~"$USER")/.config" 99 - fi 100 - fi 101 - 102 - # INVESTIGATE: What happens during `sudo`? 103 - if [[ -n "$XDG_CONFIG_HOME" ]]; then 104 - conf_dir="$XDG_CONFIG_HOME" 105 - fi 106 - fi 107 - 108 - mkdir -p "$install_dir" 109 - [[ $? != 0 ]] && die "Unable to create install directory ($install_dir)" 110 - 111 - curl -s -o "${install_dir}/$install_file" "$url" 112 - [[ $? != 0 ]] && die "Unable to download" 113 - 114 - chmod +x "${install_dir}/$install_file" 115 - [[ $? != 0 ]] && die "Unable to set as executable" 116 - 117 - mkdir -p "$conf_dir" 118 - [[ $? != 0 ]] && die "Unable to create config directory ($conf_dir)" 119 - 120 - if [[ ! -f "$conf_dir/$conf_file" ]]; then 121 - echo -e "ATFILE_USERNAME=<your-username>\nATFILE_PASSWORD=<your-password>" > "$conf_dir/$conf_file" 122 - [[ $? != 0 ]] && die "Unable to create config file ($conf_dir/$conf_file)" 123 - fi 124 - 125 - echo -e "๐Ÿ˜Ž Installed ATFile" 126 - echo -e " โ†ณ Path: $install_dir/$install_file" 127 - echo -e " โ†ณ Config: $conf_dir/$conf_file" 128 - echo -e " ---" 129 - echo -e " Before running, set your credentials in the config file!" 130 - echo -e " Run '$install_file help' to get started" 131 - # ------------------------------------------------------------------------------