this repo has no description
1
fork

Configure Feed

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

feat: add `--from` and `--to`

- change env names
- restructure main

Reviewed-on: https://codeberg.org/comfysage/ebil/pulls/6
Reviewed-by: june <me@koi.rip>

robin 238ebedf edbd39cb

+68 -37
+68 -37
ebil.sh
··· 38 38 you can set certain options using environment variables. 39 39 40 40 EBIL_SITE="robin.ebil.club" | --site robin.ebil.club 41 - EBIL_PATH="dist/" | --path dist/ 41 + EBIL_PATH="dist/" | push --from dist/ 42 + pull --to dist/ 43 + EBIL_PATH_REMOTE="root" | push --to root 44 + pull --from root 42 45 EBIL_HOST="ebil.club" 43 46 EBIL_REMOTE="/var/ebil.club/\${name}/\${site}" 44 47 ··· 61 64 [[ "$site" =~ $pat ]] || die 'malformed site url' "(expected form '${pat}'):" "$site" 62 65 } 63 66 64 - checkpath() { 65 - [[ -d "$1" ]] || die 'path does not exist' 67 + checkfrom() { 68 + [[ -d "$1" ]] || die 'from does not exist' 66 69 } 67 70 68 71 rcopy() { ··· 76 79 77 80 push() { 78 81 local site="$1" 79 - local path="$2" 80 - local host="$3" 81 - local remote="$4" 82 + local from="$2" 83 + local to="$3" 84 + local host="$4" 85 + local remote="$5" 82 86 local name 83 87 84 - checkpath "$path" 88 + from="$(realpath "$from")" 89 + checkfrom "$from" 85 90 86 91 if [[ ! -n "$remote" ]]; then 87 92 checksite "$site" 88 93 name="${site%.ebil.club}" 89 94 msg 'user:' "$name" 90 - remote="/var/ebil.club/${name}/${site}" 95 + remote="/var/ebil.club/${name}/${site}/${to}" 91 96 fi 92 97 93 - [[ -f "${path}/index.txt" ]] && msg 'custom curl message configured' "(${path}/index.txt)" 94 - [[ -f "${path}/index.html" ]] || warn 'index.html not found' "(${path}/index.html)" 98 + [[ -f "${from}/index.txt" ]] && msg 'custom curl message configured' "(${from}/index.txt)" 99 + [[ -f "${from}/index.html" ]] || warn 'index.html not found' "(${from}/index.html)" 95 100 96 - msg 'pushing to' "${site:-${remote}}" 'from' "$path" 97 - rcopy "$path" "${host}:${remote}" --delete --chmod=D755,F644 101 + msg 'pushing to' "${site:-${remote}}" 'from' "$from" 102 + rcopy "$from" "${host}:${remote}" --delete --chmod=D755,F644 98 103 } 99 104 100 105 pull() { 101 106 local site="$1" 102 - local path="$2" 103 - local host="$3" 104 - local remote="$4" 107 + local from="$2" 108 + local to="$3" 109 + local host="$4" 110 + local remote="$5" 105 111 106 - if [ ! -d "$path" ]; then 107 - msg 'creating destination directory' "$path" 108 - mkdir -p "$path" 112 + to="$(realpath "$to")" 113 + 114 + if [ ! -d "$to" ]; then 115 + msg 'creating destination directory' "$to" 116 + mkdir -p "$to" 109 117 fi 110 118 111 - if [[ ! -n "$(find "$path" -maxdepth 0 -empty)" ]]; then 112 - warn 'destination directory is not empty' "(${path})" 119 + if [[ ! -n "$(find "$to" -maxdepth 0 -empty)" ]]; then 120 + warn 'destination directory is not empty' "(${to})" 113 121 confirm 'are you sure you want to use this directory?' 114 122 fi 115 123 ··· 117 125 checksite "$site" 118 126 name="${site%.ebil.club}" 119 127 msg 'user:' "$name" 120 - remote="/var/ebil.club/${name}/${site}" 128 + remote="/var/ebil.club/${name}/${site}/${from}" 121 129 fi 122 130 123 - msg 'pulling from' "${site:-${remote}}" 'to' "$path" 124 - rcopy "${host}:${remote}" "$path" 131 + msg 'pulling from' "${site:-${remote}}" 'to' "$to" 132 + rcopy "${host}:${remote}" "$to" 125 133 } 126 134 127 135 main() { 128 136 sourceenv 129 137 130 - local cmd='' 131 138 local site="${EBIL_SITE:-}" 132 - local path="${EBIL_PATH:-.}" 133 139 local host="${EBIL_HOST:-ebil.club}" 134 140 local remote="${EBIL_REMOTE:-}" 135 - local path_opt='' 141 + 142 + local cmd='' 136 143 137 144 if [ "$#" -gt 0 ]; then 138 145 cmd="${1#-}" 139 146 shift 140 147 fi 141 148 149 + local from_opt='' 150 + local to_opt='' 151 + 142 152 while [ "$#" -gt 0 ]; do 143 153 case "$1" in 144 154 --site) 145 155 site="$2" 146 156 shift 147 157 ;; 148 - --path) 149 - path_opt="$2" 158 + --from) 159 + from_opt="$2" 160 + shift 161 + ;; 162 + --to) 163 + to_opt="$2" 150 164 shift 151 165 ;; 152 166 --help) ··· 157 171 shift 158 172 done 159 173 160 - if [[ -n "$path_opt" ]]; then 161 - path="$path_opt" 162 - else 163 - [[ -n "${1:-}" ]] && path="$1" 164 - fi 165 - 166 - path="$(realpath "$path")" 174 + local from 175 + local to 167 176 168 177 case "$cmd" in 169 - push) push "$site" "$path" "$host" "$remote" ;; 170 - pull) pull "$site" "$path" "$host" "$remote" ;; 178 + push) 179 + from="${EBIL_PATH:-dist}" 180 + to="${EBIL_PATH_REMOTE:-root}" 181 + 182 + if [[ -n "$from_opt" ]]; then 183 + from="$from_opt" 184 + else 185 + [[ -n "${1:-}" ]] && from="$1" 186 + fi 187 + 188 + push "$site" "$from" "$to" "$host" "$remote" 189 + ;; 190 + pull) 191 + from="${EBIL_PATH_REMOTE:-root}" 192 + to="${EBIL_PATH:-dst}" 193 + 194 + if [[ -n "$to_opt" ]]; then 195 + to="$to_opt" 196 + else 197 + [[ -n "${1:-}" ]] && to="$1" 198 + fi 199 + 200 + pull "$site" "$from" "$to" "$host" "$remote" 201 + ;; 171 202 '') phelp ;; 172 203 *) die 'command not found' ;; 173 204 esac