lib.sh 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708
  1. #!/usr/bin/env bash
  2. # -*- coding: utf-8; mode: sh indent-tabs-mode: nil -*-
  3. # SPDX-License-Identifier: AGPL-3.0-or-later
  4. # shellcheck disable=SC2059,SC1117
  5. ADMIN_NAME="${ADMIN_NAME:-$(git config user.name)}"
  6. ADMIN_NAME="${ADMIN_NAME:-$USER}"
  7. ADMIN_EMAIL="${ADMIN_EMAIL:-$(git config user.email)}"
  8. ADMIN_EMAIL="${ADMIN_EMAIL:-$USER@$(hostname)}"
  9. if [[ -z "${REPO_ROOT}" ]]; then
  10. REPO_ROOT=$(dirname "${BASH_SOURCE[0]}")
  11. while [ -h "${REPO_ROOT}" ] ; do
  12. REPO_ROOT=$(readlink "${REPO_ROOT}")
  13. done
  14. REPO_ROOT=$(cd "${REPO_ROOT}/.." && pwd -P )
  15. fi
  16. if [[ -z ${TEMPLATES} ]]; then
  17. TEMPLATES="${REPO_ROOT}/utils/templates"
  18. fi
  19. if [[ -z "$CACHE" ]]; then
  20. CACHE="${REPO_ROOT}/cache"
  21. fi
  22. if [[ -z "$SYSTEMD_UNITS" ]]; then
  23. SYSTEMD_UNITS="/lib/systemd/system"
  24. fi
  25. if [[ -z ${DIFF_CMD} ]]; then
  26. DIFF_CMD="diff -u"
  27. if command -v colordiff >/dev/null; then
  28. DIFF_CMD="colordiff -u"
  29. fi
  30. fi
  31. DOT_CONFIG="${DOT_CONFIG:-${REPO_ROOT}/.config}"
  32. source_dot_config() {
  33. if [[ ! -e "$DOT_CONFIG" ]]; then
  34. info_msg "installing $DOT_CONFIG"
  35. cp "$(dirname "${BASH_SOURCE[0]}")/dot_config" "$DOT_CONFIG"
  36. if [[ ! -z ${SUDO_USER} ]]; then
  37. chown "${SUDO_USER}:${SUDO_USER}" "$DOT_CONFIG"
  38. fi
  39. fi
  40. # shellcheck disable=SC1090
  41. source "${REPO_ROOT}/.config"
  42. }
  43. sudo_or_exit() {
  44. # usage: sudo_or_exit
  45. if [ ! "$(id -u)" -eq 0 ]; then
  46. err_msg "this command requires root (sudo) privilege!" >&2
  47. exit 42
  48. fi
  49. }
  50. required_commands() {
  51. # usage: requires_commands [cmd1 ...]
  52. local exit_val=0
  53. while [ ! -z "$1" ]; do
  54. if ! command -v "$1" &>/dev/null; then
  55. err_msg "missing command $1"
  56. exit_val=42
  57. fi
  58. shift
  59. done
  60. return $exit_val
  61. }
  62. rst_title() {
  63. # usage: rst_title <header-text> [part|chapter|section]
  64. case ${2-chapter} in
  65. part) printf "\n${1//?/=}\n$1\n${1//?/=}\n";;
  66. chapter) printf "\n${1}\n${1//?/=}\n";;
  67. section) printf "\n${1}\n${1//?/-}\n";;
  68. *)
  69. err_msg "invalid argument '${2}' in line $(caller)"
  70. return 42
  71. ;;
  72. esac
  73. }
  74. if command -v fmt >/dev/null; then
  75. export FMT="fmt -u"
  76. else
  77. export FMT="cat"
  78. fi
  79. rst_para() {
  80. # usage: RST_INDENT=1 rst_para "lorem ipsum ..."
  81. local prefix=''
  82. if ! [[ -z $RST_INDENT ]] && [[ $RST_INDENT -gt 0 ]]; then
  83. prefix="$(for i in $(seq 1 "$RST_INDENT"); do printf " "; done)"
  84. echo -en "\n$*\n" | $FMT | prefix_stdout "$prefix"
  85. else
  86. echo -en "\n$*\n" | $FMT
  87. fi
  88. }
  89. err_msg() { echo -e "ERROR: $*" >&2; }
  90. warn_msg() { echo -e "WARN: $*" >&2; }
  91. info_msg() { echo -e "INFO: $*"; }
  92. clean_stdin() {
  93. if [[ $(uname -s) != 'Darwin' ]]; then
  94. while read -r -n1 -t 0.1; do : ; done
  95. fi
  96. }
  97. wait_key(){
  98. # usage: waitKEY [<timeout in sec>]
  99. clean_stdin
  100. local _t=$1
  101. [[ ! -z $FORCE_TIMEOUT ]] && _t=$FORCE_TIMEOUT
  102. [[ ! -z $_t ]] && _t="-t $_t"
  103. # shellcheck disable=SC2086
  104. read -r -s -n1 $_t -p "** press any [KEY] to continue **"
  105. echo
  106. clean_stdin
  107. }
  108. ask_yn() {
  109. # usage: ask_yn <prompt-text> [Ny|Yn] [<timeout in sec>]
  110. local EXIT_YES=0 # exit status 0 --> successful
  111. local EXIT_NO=1 # exit status 1 --> error code
  112. local _t=$3
  113. [[ ! -z $FORCE_TIMEOUT ]] && _t=$FORCE_TIMEOUT
  114. [[ ! -z $_t ]] && _t="-t $_t"
  115. case "${2}" in
  116. Yn)
  117. local exit_val=${EXIT_YES}
  118. local choice="[YES/no]"
  119. local default="Yes"
  120. ;;
  121. *)
  122. local exit_val=${EXIT_NO}
  123. local choice="[NO/yes]"
  124. local default="No"
  125. ;;
  126. esac
  127. echo
  128. while true; do
  129. clean_stdin
  130. printf "$1 ${choice} "
  131. # shellcheck disable=SC2086
  132. read -r -n1 $_t
  133. if [[ -z $REPLY ]]; then
  134. printf "$default\n"; break
  135. elif [[ $REPLY =~ ^[Yy]$ ]]; then
  136. exit_val=${EXIT_YES}
  137. printf "\n"
  138. break
  139. elif [[ $REPLY =~ ^[Nn]$ ]]; then
  140. exit_val=${EXIT_NO}
  141. printf "\n"
  142. break
  143. fi
  144. _t=""
  145. err_msg "invalid choice"
  146. done
  147. clean_stdin
  148. return $exit_val
  149. }
  150. tee_stderr () {
  151. # usage::
  152. # tee_stderr 1 <<EOF | python -i
  153. # print("hello")
  154. # EOF
  155. # ...
  156. # >>> print("hello")
  157. # hello
  158. local _t="0";
  159. if [[ ! -z $1 ]] ; then _t="$1"; fi
  160. (while read -r line; do
  161. # shellcheck disable=SC2086
  162. sleep $_t
  163. echo -e "$line" >&2
  164. echo "$line"
  165. done)
  166. }
  167. prefix_stdout () {
  168. # usage: <cmd> | prefix_stdout [prefix]
  169. local prefix=" | "
  170. if [[ ! -z $1 ]] ; then prefix="$1"; fi
  171. # shellcheck disable=SC2162
  172. (while IFS= read line; do
  173. echo -e "${prefix}$line"
  174. done)
  175. }
  176. append_line() {
  177. # usage: append_line <line> <file>
  178. #
  179. # Append line if not exists, create file if not exists. E.g::
  180. #
  181. # append_line 'source ~/.foo' ~/bashrc
  182. local LINE=$1
  183. local FILE=$2
  184. grep -qFs -- "$LINE" "$FILE" || echo "$LINE" >> "$FILE"
  185. }
  186. cache_download() {
  187. # usage: cache_download <url> <local-filename>
  188. local exit_value=0
  189. if [[ ! -z ${SUDO_USER} ]]; then
  190. sudo -u "${SUDO_USER}" mkdir -p "${CACHE}"
  191. else
  192. mkdir -p "${CACHE}"
  193. fi
  194. if [[ -f "${CACHE}/$2" ]] ; then
  195. info_msg "already cached: $1"
  196. info_msg " --> ${CACHE}/$2"
  197. fi
  198. if [[ ! -f "${CACHE}/$2" ]]; then
  199. info_msg "caching: $1"
  200. info_msg " --> ${CACHE}/$2"
  201. if [[ ! -z ${SUDO_USER} ]]; then
  202. sudo -u "${SUDO_USER}" wget --progress=bar -O "${CACHE}/$2" "$1" ; exit_value=$?
  203. else
  204. wget --progress=bar -O "${CACHE}/$2" "$1" ; exit_value=$?
  205. fi
  206. if [[ $exit_value = 0 ]]; then
  207. err_msg "failed to download: $1"
  208. fi
  209. fi
  210. }
  211. choose_one() {
  212. # usage:
  213. #
  214. # DEFAULT_SELECT= 2 \
  215. # choose_one <name> "your selection?" "Coffee" "Coffee with milk"
  216. local default=${DEFAULT_SELECT-1}
  217. local REPLY
  218. local env_name=$1 && shift
  219. local choice=$1;
  220. local max="${#@}"
  221. local _t
  222. [[ ! -z $FORCE_TIMEOUT ]] && _t=$FORCE_TIMEOUT
  223. [[ ! -z $_t ]] && _t="-t $_t"
  224. list=("$@")
  225. echo -e "Menu::"
  226. for ((i=1; i<= $((max -1)); i++)); do
  227. if [[ "$i" == "$default" ]]; then
  228. echo -e " $i.) ${list[$i]} [default]"
  229. else
  230. echo -e " $i.) ${list[$i]}"
  231. fi
  232. done
  233. while true; do
  234. clean_stdin
  235. printf "$1 [$default] "
  236. if (( 10 > max )); then
  237. # shellcheck disable=SC2086
  238. read -r -n1 $_t
  239. else
  240. # shellcheck disable=SC2086,SC2229
  241. read -r $_t
  242. fi
  243. # selection fits
  244. [[ $REPLY =~ ^-?[0-9]+$ ]] && (( REPLY > 0 )) && (( REPLY < max )) && break
  245. # take default
  246. [[ -z $REPLY ]] && REPLY=$default && break
  247. _t=""
  248. err_msg "invalid choice"
  249. done
  250. eval "$env_name"='${list[${REPLY}]}'
  251. echo
  252. clean_stdin
  253. }
  254. install_template() {
  255. # usage:
  256. #
  257. # install_template [--no-eval] [--variant=<name>] \
  258. # {file} [{owner} [{group} [{chmod}]]]
  259. #
  260. # E.g. the origin of variant 'raw' of /etc/updatedb.conf is::
  261. #
  262. # ${TEMPLATES}/etc/updatedb.conf:raw
  263. #
  264. # To install variant 'raw' of /etc/updatedb.conf without evaluated
  265. # replacements you can use::
  266. #
  267. # install_template --variant=raw --no-eval \
  268. # /etc/updatedb.conf root root 644
  269. local _reply=""
  270. local do_eval=1
  271. local variant=""
  272. local pos_args=("$0")
  273. for i in "$@"; do
  274. case $i in
  275. --no-eval) do_eval=0; shift ;;
  276. --variant=*) variant=":${i#*=}"; shift ;;
  277. *) pos_args+=("$i") ;;
  278. esac
  279. done
  280. local dst="${pos_args[1]}"
  281. local template_origin="${TEMPLATES}${dst}${variant}"
  282. local template_file="${TEMPLATES}${dst}"
  283. local owner="${pos_args[2]-$(id -un)}"
  284. local group="${pos_args[3]-$(id -gn)}"
  285. local chmod="${pos_args[4]-644}"
  286. info_msg "install (eval=$do_eval): ${dst}"
  287. [[ ! -z $variant ]] && info_msg "variant: ${variant}"
  288. if [[ ! -f "${template_origin}" ]] ; then
  289. err_msg "${template_origin} does not exists"
  290. err_msg "... can't install $dst"
  291. wait_key 30
  292. return 42
  293. fi
  294. if [[ "$do_eval" == "1" ]]; then
  295. template_file="${CACHE}${dst}${variant}"
  296. info_msg "BUILD template ${template_file}"
  297. if [[ ! -z ${SUDO_USER} ]]; then
  298. sudo -u "${SUDO_USER}" mkdir -p "$(dirname "${template_file}")"
  299. else
  300. mkdir -p "$(dirname "${template_file}")"
  301. fi
  302. # shellcheck disable=SC2086
  303. eval "echo \"$(cat ${template_origin})\"" > "${template_file}"
  304. if [[ ! -z ${SUDO_USER} ]]; then
  305. chown "${SUDO_USER}:${SUDO_USER}" "${template_file}"
  306. fi
  307. else
  308. template_file=$template_origin
  309. fi
  310. mkdir -p "$(dirname "${dst}")"
  311. if [[ ! -f "${dst}" ]]; then
  312. info_msg "install: ${template_file}"
  313. sudo -H install -v -o "${owner}" -g "${group}" -m "${chmod}" \
  314. "${template_file}" "${dst}" | prefix_stdout
  315. return $?
  316. fi
  317. if [[ -f "${dst}" ]] && cmp --silent "${template_file}" "${dst}" ; then
  318. info_msg "file ${dst} allready installed"
  319. return 0
  320. fi
  321. info_msg "diffrent file ${dst} allready exists on this host"
  322. while true; do
  323. choose_one _reply "choose next step with file $dst" \
  324. "replace file" \
  325. "leave file unchanged" \
  326. "interactiv shell" \
  327. "diff files"
  328. case $_reply in
  329. "replace file")
  330. info_msg "install: ${template_file}"
  331. sudo -H install -v -o "${owner}" -g "${group}" -m "${chmod}" \
  332. "${template_file}" "${dst}" | prefix_stdout
  333. break
  334. ;;
  335. "leave file unchanged")
  336. break
  337. ;;
  338. "interactiv shell")
  339. echo "// edit ${dst} to your needs"
  340. echo "// exit with CTRL-D"
  341. sudo -H -u "${owner}" -i
  342. $DIFF_CMD "${dst}" "${template_file}"
  343. echo
  344. echo "did you edit file ..."
  345. printf " ${template_file}"
  346. if ask_yn "... to your needs?"; then
  347. break
  348. fi
  349. ;;
  350. "diff files")
  351. $DIFF_CMD "${dst}" "${template_file}" | prefix_stdout
  352. esac
  353. done
  354. }
  355. service_is_available() {
  356. # usage: service_is_available <URL>
  357. local URL="$1"
  358. if [[ -z $URL ]]; then
  359. err_msg "service_is_available: missing arguments"
  360. return 42
  361. fi
  362. http_code=$(curl -H 'Cache-Control: no-cache' \
  363. --silent -o /dev/null --head --write-out '%{http_code}' --insecure \
  364. "${URL}")
  365. exit_val=$?
  366. if [[ $exit_val = 0 ]]; then
  367. info_msg "got $http_code from ${URL}"
  368. fi
  369. return $exit_val
  370. }
  371. # Apache
  372. # ------
  373. # FIXME: Arch Linux & RHEL should be added
  374. if [[ -z "${APACHE_SITES_AVAILABE}" ]]; then
  375. APACHE_SITES_AVAILABE="/etc/apache2/sites-available"
  376. fi
  377. apache_is_installed() {
  378. (command -v apachectl \
  379. && command -v a2ensite \
  380. && command -v a2dissite ) &>/dev/null
  381. }
  382. apache_reload() {
  383. info_msg "reload apache .."
  384. echo
  385. sudo -H apachectl configtest
  386. sudo -H service apache2 force-reload
  387. }
  388. apache_install_site() {
  389. # usage: apache_install_site [<template option> ...] <mysite.conf>
  390. #
  391. # <template option>: see install_template
  392. local template_opts=()
  393. local pos_args=("$0")
  394. for i in "$@"; do
  395. case $i in
  396. -*) template_opts+=("$i");;
  397. *) pos_args+=("$i");;
  398. esac
  399. done
  400. install_template "${template_opts[@]}" \
  401. "${APACHE_SITES_AVAILABE}/${pos_args[1]}" \
  402. root root 644
  403. apache_enable_site "${pos_args[1]}"
  404. info_msg "installed apache site: ${pos_args[1]}"
  405. }
  406. apache_remove_site() {
  407. # usage: apache_remove_site <mysite.conf>
  408. info_msg "remove apache site: $1"
  409. apache_dissable_site "$1"
  410. rm -f "${APACHE_SITES_AVAILABE}/$1"
  411. }
  412. apache_enable_site() {
  413. # usage: apache_enable_site <mysite.conf>
  414. info_msg "enable apache site: $1"
  415. sudo -H a2ensite -q "$1"
  416. apache_reload
  417. }
  418. apache_dissable_site() {
  419. # usage: apache_disable_site <mysite.conf>
  420. info_msg "disable apache site: $1"
  421. sudo -H a2dissite -q "$1"
  422. apache_reload
  423. }
  424. # uWSGI
  425. # -----
  426. uWSGI_SETUP="${uWSGI_SETUP:=/etc/uwsgi}"
  427. uWSGI_restart() {
  428. # usage: uWSGI_restart()
  429. info_msg "restart uWSGI service"
  430. systemctl restart uwsgi
  431. }
  432. uWSGI_app_available() {
  433. # usage: uWSGI_app_available <myapp.ini>
  434. local CONF="$1"
  435. if [[ -z $CONF ]]; then
  436. err_msg "uWSGI_app_available: missing arguments"
  437. return 42
  438. fi
  439. [[ -f "${uWSGI_SETUP}/apps-available/${CONF}" ]]
  440. }
  441. uWSGI_install_app() {
  442. # usage: uWSGI_install_app [<template option> ...] <myapp.ini>
  443. #
  444. # <template option>: see install_template
  445. local pos_args=("$0")
  446. for i in "$@"; do
  447. case $i in
  448. -*) template_opts+=("$i");;
  449. *) pos_args+=("$i");;
  450. esac
  451. done
  452. install_template "${template_opts[@]}" \
  453. "${uWSGI_SETUP}/apps-available/${pos_args[1]}" \
  454. root root 644
  455. uWSGI_enable_app "${pos_args[1]}"
  456. uWSGI_restart
  457. info_msg "installed uWSGI app: ${pos_args[1]}"
  458. }
  459. uWSGI_remove_app() {
  460. # usage: uWSGI_remove_app <myapp.ini>
  461. local CONF="$1"
  462. info_msg "remove uWSGI app: ${CONF}"
  463. uWSGI_disable_app "${CONF}"
  464. uWSGI_restart
  465. rm -f "${uWSGI_SETUP}/apps-available/${CONF}"
  466. }
  467. uWSGI_app_enabled() {
  468. # usage: uWSGI_app_enabled <myapp.ini>
  469. local CONF="$1"
  470. if [[ -z $CONF ]]; then
  471. err_msg "uWSGI_app_enabled: missing arguments"
  472. return 42
  473. fi
  474. [[ -f "${uWSGI_SETUP}/apps-enabled/${CONF}" ]]
  475. }
  476. # shellcheck disable=SC2164
  477. uWSGI_enable_app() {
  478. # usage: uWSGI_enable_app <myapp.ini>
  479. local CONF="$1"
  480. if [[ -z $CONF ]]; then
  481. err_msg "uWSGI_enable_app: missing arguments"
  482. return 42
  483. fi
  484. pushd "${uWSGI_SETUP}/apps-enabled" >/dev/null
  485. rm -f "$CONF"
  486. # shellcheck disable=SC2226
  487. ln -s "../apps-available/${CONF}"
  488. info_msg "enabled uWSGI app: ${CONF} (restart uWSGI required)"
  489. popd >/dev/null
  490. }
  491. uWSGI_disable_app() {
  492. # usage: uWSGI_disable_app <myapp.ini>
  493. local CONF="$1"
  494. if [[ -z $CONF ]]; then
  495. err_msg "uWSGI_enable_app: missing arguments"
  496. return 42
  497. fi
  498. rm -f "${uWSGI_SETUP}/apps-enabled/${CONF}"
  499. # FIXME: restart uwsgi service won't stop wsgi forked processes of user searx.
  500. # I had to kill them manually here ...
  501. pkill -f "${uWSGI_SETUP}/apps-enabled/${CONF}" -9
  502. info_msg "disabled uWSGI app: ${CONF} (restart uWSGI required)"
  503. }
  504. # distro's package manager
  505. # ------------------------
  506. #
  507. # FIXME: Arch Linux & RHEL should be added
  508. #
  509. pkg_install() {
  510. # usage: TITEL='install foobar' pkg_install foopkg barpkg
  511. rst_title "${TITLE:-installation of packages}" section
  512. echo -en "\npackage(s)::\n\n $*\n" | $FMT
  513. if ! ask_yn "Should packages be installed?" Yn 30; then
  514. return 42
  515. fi
  516. # shellcheck disable=SC2068
  517. apt-get install -y $@
  518. }
  519. pkg_remove() {
  520. # usage: TITEL='remove foobar' pkg_remove foopkg barpkg
  521. rst_title "${TITLE:-remove packages}" section
  522. echo -en "\npackage(s)::\n\n $*\n" | $FMT
  523. if ! ask_yn "Should packages be removed (purge)?" Yn 30; then
  524. return 42
  525. fi
  526. apt-get purge --autoremove --ignore-missing -y "$@"
  527. }
  528. pkg_is_installed() {
  529. # usage: pkg_is_install foopkg || pkg_install foopkg
  530. dpkg -l "$1" &> /dev/null
  531. return $?
  532. }
  533. # git tooling
  534. # -----------
  535. # shellcheck disable=SC2164
  536. git_clone() {
  537. # usage:
  538. #
  539. # git_clone <url> <name> [<branch> [<user>]]
  540. # git_clone <url> <path> [<branch> [<user>]]
  541. #
  542. # First form uses $CACHE/<name> as destination folder, second form clones
  543. # into <path>. If repository is allready cloned, pull from <branch> and
  544. # update working tree (if needed, the caller has to stash local changes).
  545. #
  546. # git clone https://github.com/asciimoo/searx searx-src origin/master searxlogin
  547. #
  548. local url="$1"
  549. local dest="$2"
  550. local branch="$3"
  551. local user="$4"
  552. local bash_cmd="bash"
  553. local remote="origin"
  554. if [[ ! "${dest:0:1}" = "/" ]]; then
  555. dest="$CACHE/$dest"
  556. fi
  557. [[ -z $branch ]] && branch=master
  558. [[ -z $user ]] && [[ ! -z "${SUDO_USER}" ]] && user="${SUDO_USER}"
  559. [[ ! -z $user ]] && bash_cmd="sudo -H -u $user -i"
  560. if [[ -d "${dest}" ]] ; then
  561. info_msg "already cloned: $dest"
  562. tee_stderr 0.1 <<EOF | $bash_cmd 2>&1 | prefix_stdout " |$user| "
  563. cd "${dest}"
  564. git checkout -m -B "$branch" --track "$remote/$branch"
  565. git pull --all
  566. EOF
  567. else
  568. info_msg "clone into: $dest"
  569. tee_stderr 0.1 <<EOF | $bash_cmd 2>&1 | prefix_stdout " |$user| "
  570. mkdir -p "$(dirname "$dest")"
  571. cd "$(dirname "$dest")"
  572. git clone --branch "$branch" --origin "$remote" "$url" "$(basename "$dest")"
  573. EOF
  574. fi
  575. }