2# -*- coding: utf-8; mode: sh indent-tabs-mode: nil -*-
3# SPDX-License-Identifier: AGPL-3.0-or-later
4# shellcheck disable=SC2059,SC1117
6# ubuntu, debian, arch, fedora ...
7DIST_ID=$(source /etc/os-release; echo "$ID");
8# shellcheck disable=SC2034
9DIST_VERS=$(source /etc/os-release; echo "$VERSION_ID");
11ADMIN_NAME="${ADMIN_NAME:-$(git config user.name)}"
12ADMIN_NAME="${ADMIN_NAME:-$USER}"
14ADMIN_EMAIL="${ADMIN_EMAIL:-$(git config user.email)}"
15ADMIN_EMAIL="${ADMIN_EMAIL:-$USER@$(hostname)}"
17if [[ -z "${REPO_ROOT}" ]]; then
18 REPO_ROOT=$(dirname "${BASH_SOURCE[0]}")
19 while [ -h "${REPO_ROOT}" ] ; do
20 REPO_ROOT=$(readlink "${REPO_ROOT}")
22 REPO_ROOT=$(cd "${REPO_ROOT}/.." && pwd -P )
25if [[ -z ${TEMPLATES} ]]; then
26 TEMPLATES="${REPO_ROOT}/utils/templates"
29if [[ -z "$CACHE" ]]; then
30 CACHE="${REPO_ROOT}/cache"
33if [[ -z ${DIFF_CMD} ]]; then
35 if command -v colordiff >/dev/null; then
36 DIFF_CMD="colordiff -u"
40DOT_CONFIG="${DOT_CONFIG:-${REPO_ROOT}/.config.sh}"
43 if [[ ! -e "${DOT_CONFIG}" ]]; then
44 err_msg "configuration does not extsts at: ${DOT_CONFIG}"
47 # shellcheck disable=SC1090
48 source "${DOT_CONFIG}"
54 if [ ! "$(id -u)" -eq 0 ]; then
55 err_msg "this command requires root (sudo) privilege!" >&2
62 # usage: required_commands [cmd1 ...]
67 if ! command -v "$1" &>/dev/null; then
68 err_msg "missing command $1"
79# shellcheck disable=SC2034
80set_terminal_colors() {
82 _creset='\e[0m' # reset all attributes
103if [ ! -p /dev/stdout ]; then
110if command -v fmt >/dev/null; then
117 # usage: rst_title <header-text> [part|chapter|section]
120 part) printf "\n${_BGreen}${1//?/=}${_creset}\n${_BCyan}${1}${_creset}\n${_BGreen}${1//?/=}${_creset}\n";;
121 chapter) printf "\n${_BCyan}${1}${_creset}\n${_BGreen}${1//?/=}${_creset}\n";;
122 section) printf "\n${_BCyan}${1}${_creset}\n${_BGreen}${1//?/-}${_creset}\n";;
124 err_msg "invalid argument '${2}' in line $(caller)"
131 # usage: RST_INDENT=1 rst_para "lorem ipsum ..."
133 if [[ -n $RST_INDENT ]] && [[ $RST_INDENT -gt 0 ]]; then
134 prefix="$(for i in $(seq 1 "$RST_INDENT"); do printf " "; done)"
135 echo -en "\n$*\n" | $FMT | prefix_stdout "$prefix"
137 echo -en "\n$*\n" | $FMT
141err_msg() { echo -e "${_BRed}ERROR:${_creset} $*" >&2; }
142warn_msg() { echo -e "${_BBlue}WARN:${_creset} $*" >&2; }
143info_msg() { echo -e "${_BYellow}INFO:${_creset} $*" >&2; }
146 if [[ $(uname -s) != 'Darwin' ]]; then
147 while read -r -n1 -t 0.1; do : ; done
152 # usage: waitKEY [<timeout in sec>]
157 [[ -z "$msg" ]] && msg="${_Green}** press any [${_BCyan}KEY${_Green}] to continue **${_creset}"
159 [[ -n $FORCE_TIMEOUT ]] && _t=$FORCE_TIMEOUT
160 [[ -n $_t ]] && _t="-t $_t"
162 # shellcheck disable=SC2086
169 # usage: ask_yn <prompt-text> [Ny|Yn] [<timeout in sec>]
171 local EXIT_YES=0 # exit status 0 --> successful
172 local EXIT_NO=1 # exit status 1 --> error code
175 [[ -n $FORCE_TIMEOUT ]] && _t=$FORCE_TIMEOUT
176 [[ -n $_t ]] && _t="-t $_t"
177 case "${FORCE_SELECTION:-${2}}" in
178 Y) return ${EXIT_YES} ;;
179 N) return ${EXIT_NO} ;;
181 local exit_val=${EXIT_YES}
182 local choice="[${_BGreen}YES${_creset}/no]"
186 local exit_val=${EXIT_NO}
187 local choice="[${_BGreen}NO${_creset}/yes]"
194 printf "$1 ${choice} "
195 # shellcheck disable=SC2086
197 if [[ -z $REPLY ]]; then
198 printf "$default\n"; break
199 elif [[ $REPLY =~ ^[Yy]$ ]]; then
203 elif [[ $REPLY =~ ^[Nn]$ ]]; then
209 err_msg "invalid choice"
218 # tee_stderr 1 <<EOF | python -i
226 if [[ -n $1 ]] ; then _t="$1"; fi
228 (while read -r line; do
229 # shellcheck disable=SC2086
237 # usage: <cmd> | prefix_stdout [prefix]
239 local prefix="${_BYellow}-->|${_creset}"
241 if [[ -n $1 ]] ; then prefix="$1"; fi
243 # shellcheck disable=SC2162
244 (while IFS= read line; do
245 echo -e "${prefix}$line"
251 # usage: append_line <line> <file>
253 # Append line if not exists, create file if not exists. E.g::
255 # append_line 'source ~/.foo' ~/bashrc
259 grep -qFs -- "$LINE" "$FILE" || echo "$LINE" >> "$FILE"
264 # usage: cache_download <url> <local-filename>
268 if [[ -n ${SUDO_USER} ]]; then
269 sudo -u "${SUDO_USER}" mkdir -p "${CACHE}"
274 if [[ -f "${CACHE}/$2" ]] ; then
275 info_msg "already cached: $1"
276 info_msg " --> ${CACHE}/$2"
279 if [[ ! -f "${CACHE}/$2" ]]; then
280 info_msg "caching: $1"
281 info_msg " --> ${CACHE}/$2"
282 if [[ -n ${SUDO_USER} ]]; then
283 sudo -u "${SUDO_USER}" wget --progress=bar -O "${CACHE}/$2" "$1" ; exit_value=$?
285 wget --progress=bar -O "${CACHE}/$2" "$1" ; exit_value=$?
287 if [[ ! $exit_value = 0 ]]; then
288 err_msg "failed to download: $1"
295 # usage: backup_file /path/to/file.foo
298 stamp=$(date +"_%Y%m%d_%H%M%S")
299 info_msg "create backup: ${1}${stamp}"
300 cp -a "${1}" "${1}${stamp}"
307 # DEFAULT_SELECT= 2 \
308 # choose_one <name> "your selection?" "Coffee" "Coffee with milk"
310 local default=${DEFAULT_SELECT-1}
312 local env_name=$1 && shift
316 [[ -n $FORCE_TIMEOUT ]] && _t=$FORCE_TIMEOUT
317 [[ -n $_t ]] && _t="-t $_t"
320 echo -e "${_BGreen}Menu::${_creset}"
321 for ((i=1; i<= $((max -1)); i++)); do
322 if [[ "$i" == "$default" ]]; then
323 echo -e " ${_BGreen}$i.${_creset}) ${list[$i]} [default]"
325 echo -e " $i.) ${list[$i]}"
330 printf "$1 [${_BGreen}$default${_creset}] "
332 if (( 10 > max )); then
333 # shellcheck disable=SC2086
336 # shellcheck disable=SC2086,SC2229
340 [[ $REPLY =~ ^-?[0-9]+$ ]] && (( REPLY > 0 )) && (( REPLY < max )) && break
343 [[ -z $REPLY ]] && REPLY=$default && break
346 err_msg "invalid choice"
348 eval "$env_name"='${list[${REPLY}]}'
357 # install_template [--no-eval] [--variant=<name>] \
358 # {file} [{owner} [{group} [{chmod}]]]
360 # E.g. the origin of variant 'raw' of /etc/updatedb.conf is::
362 # ${TEMPLATES}/etc/updatedb.conf:raw
364 # To install variant 'raw' of /etc/updatedb.conf without evaluated
365 # replacements you can use::
367 # install_template --variant=raw --no-eval \
368 # /etc/updatedb.conf root root 644
373 local pos_args=("$0")
377 --no-eval) do_eval=0; shift ;;
378 --variant=*) variant=":${i#*=}"; shift ;;
379 *) pos_args+=("$i") ;;
383 local dst="${pos_args[1]}"
384 local template_origin="${TEMPLATES}${dst}${variant}"
385 local template_file="${TEMPLATES}${dst}"
387 local owner="${pos_args[2]-$(id -un)}"
388 local group="${pos_args[3]-$(id -gn)}"
389 local chmod="${pos_args[4]-644}"
391 info_msg "install (eval=$do_eval): ${dst}"
392 [[ -n $variant ]] && info_msg "variant: ${variant}"
394 if [[ ! -f "${template_origin}" ]] ; then
395 err_msg "${template_origin} does not exists"
396 err_msg "... can't install $dst"
401 if [[ "$do_eval" == "1" ]]; then
402 template_file="${CACHE}${dst}${variant}"
403 info_msg "BUILD template ${template_file}"
404 if [[ -n ${SUDO_USER} ]]; then
405 sudo -u "${SUDO_USER}" mkdir -p "$(dirname "${template_file}")"
407 mkdir -p "$(dirname "${template_file}")"
409 # shellcheck disable=SC2086
410 eval "echo \"$(cat ${template_origin})\"" > "${template_file}"
411 if [[ -n ${SUDO_USER} ]]; then
412 chown "${SUDO_USER}:${SUDO_USER}" "${template_file}"
415 template_file=$template_origin
418 mkdir -p "$(dirname "${dst}")"
420 if [[ ! -f "${dst}" ]]; then
421 info_msg "install: ${template_file}"
422 sudo -H install -v -o "${owner}" -g "${group}" -m "${chmod}" \
423 "${template_file}" "${dst}" | prefix_stdout
427 if [[ -f "${dst}" ]] && cmp --silent "${template_file}" "${dst}" ; then
428 info_msg "file ${dst} allready installed"
432 info_msg "diffrent file ${dst} allready exists on this host"
435 choose_one _reply "choose next step with file $dst" \
437 "leave file unchanged" \
443 info_msg "install: ${template_file}"
444 sudo -H install -v -o "${owner}" -g "${group}" -m "${chmod}" \
445 "${template_file}" "${dst}" | prefix_stdout
448 "leave file unchanged")
452 echo "// edit ${dst} to your needs"
453 echo -e "// exit with [${_BCyan}CTRL-D${_creset}]"
454 sudo -H -u "${owner}" -i
455 $DIFF_CMD "${dst}" "${template_file}"
457 echo "${_BBlack}did you edit file ...${_creset}"
458 printf " ${template_file}"
459 if ask_yn "... to your needs?"; then
464 $DIFF_CMD "${dst}" "${template_file}" | prefix_stdout
470service_is_available() {
472 # usage: service_is_available <URL>
475 if [[ -z $URL ]]; then
476 err_msg "service_is_available: missing arguments"
480 http_code=$(curl -H 'Cache-Control: no-cache' \
481 --silent -o /dev/null --head --write-out '%{http_code}' --insecure \
484 if [[ $exit_val = 0 ]]; then
485 info_msg "got $http_code from ${URL}"
488 404|410|423) exit_val=$http_code;;
498 # usage: go_is_available $SERVICE_USER && echo "go is installed!"
500 sudo -i -u "${1}" which go &>/dev/null
505 # usage: install_go "${GO_PKG_URL}" "${GO_TAR}" "${SERVICE_USER}"
507 local _svcpr=" ${_Yellow}|${3}|${_creset} "
509 rst_title "Install Go in user's HOME" section
511 rst_para "download and install go binary .."
512 cache_download "${1}" "${2}"
514 tee_stderr 0.1 <<EOF | sudo -i -u "${3}" | prefix_stdout "$_svcpr"
518rm -rf \$HOME/local/go
519tar -C \$HOME/local -xzf ${CACHE}/${2}
521 sudo -i -u "${3}" <<EOF | prefix_stdout
522! which go >/dev/null && echo "ERROR - Go Installation not found in PATH!?!"
523which go >/dev/null && go version && echo "congratulations -- Go installation OK :)"
530service_account_is_available() {
532 # usage: service_account_is_available "$SERVICE_USER" && echo "OK"
534 sudo -i -u "$1" echo \$HOME &>/dev/null
537drop_service_account() {
539 # usage: drop_service_account "${SERVICE_USER}"
541 rst_title "Drop ${1} HOME" section
542 if ask_yn "Do you really want to drop ${1} home folder?"; then
543 userdel -r -f "${1}" 2>&1 | prefix_stdout
545 rst_para "Leave HOME folder $(du -sh "${1}") unchanged."
551 # usage: interactive_shell "${SERVICE_USER}"
553 echo -e "// exit with [${_BCyan}CTRL-D${_creset}]"
561SYSTEMD_UNITS="${SYSTEMD_UNITS:-/lib/systemd/system}"
563systemd_install_service() {
565 # usage: systemd_install_service "${SERVICE_NAME}" "${SERVICE_SYSTEMD_UNIT}"
567 rst_title "Install System-D Unit ${1}" section
569 install_template "${2}" root root 644
571 systemd_activate_service "${1}"
574systemd_remove_service() {
576 # usage: systemd_remove_service "${SERVICE_NAME}" "${SERVICE_SYSTEMD_UNIT}"
578 if ! ask_yn "Do you really want to deinstall systemd unit ${1}?"; then
581 systemd_deactivate_service "${1}"
582 rm "${2}" 2>&1 | prefix_stdout
585systemd_activate_service() {
587 # usage: systemd_activate_service "${SERVICE_NAME}"
589 rst_title "Activate ${1} (service)" section
591 tee_stderr <<EOF | bash 2>&1
592systemctl enable ${1}.service
593systemctl restart ${1}.service
595 tee_stderr <<EOF | bash 2>&1
596systemctl status --no-pager ${1}.service
600systemd_deactivate_service() {
602 # usage: systemd_deactivate_service "${SERVICE_NAME}"
604 rst_title "De-Activate ${1} (service)" section
606 tee_stderr <<EOF | bash 2>&1 | prefix_stdout
607systemctl stop ${1}.service
608systemctl disable ${1}.service
612systemd_restart_service() {
614 # usage: systemd_restart_service "${SERVICE_NAME}"
616 rst_title "Restart ${1} (service)" section
618 tee_stderr <<EOF | bash 2>&1
619systemctl restart ${1}.service
621 tee_stderr <<EOF | bash 2>&1
622systemctl status --no-pager ${1}.service
630# FIXME: Arch Linux & RHEL should be added
632if [[ -z "${APACHE_SITES_AVAILABE}" ]]; then
633 APACHE_SITES_AVAILABE="/etc/apache2/sites-available"
636apache_is_installed() {
637 (command -v apachectl \
638 && command -v a2ensite \
639 && command -v a2dissite ) &>/dev/null
644 info_msg "reload apache .."
646 sudo -H apachectl configtest
647 sudo -H service apache2 force-reload
650apache_install_site() {
652 # usage: apache_install_site [<template option> ...] <mysite.conf>
654 # <template option>: see install_template
656 local template_opts=()
657 local pos_args=("$0")
661 -*) template_opts+=("$i");;
662 *) pos_args+=("$i");;
666 install_template "${template_opts[@]}" \
667 "${APACHE_SITES_AVAILABE}/${pos_args[1]}" \
670 apache_enable_site "${pos_args[1]}"
671 info_msg "installed apache site: ${pos_args[1]}"
674apache_remove_site() {
676 # usage: apache_remove_site <mysite.conf>
678 info_msg "remove apache site: $1"
679 apache_dissable_site "$1"
680 rm -f "${APACHE_SITES_AVAILABE}/$1"
683apache_enable_site() {
685 # usage: apache_enable_site <mysite.conf>
687 info_msg "enable apache site: $1"
688 sudo -H a2ensite -q "$1"
692apache_dissable_site() {
694 # usage: apache_disable_site <mysite.conf>
696 info_msg "disable apache site: $1"
697 sudo -H a2dissite -q "$1"
704uWSGI_SETUP="${uWSGI_SETUP:=/etc/uwsgi}"
708# How distros manage uWSGI apps is very different. From uWSGI POV read:
709# - https://uwsgi-docs.readthedocs.io/en/latest/Management.html
711uWSGI_distro_setup() {
712 case $DIST_ID-$DIST_VERS in
714 # init.d --> /usr/share/doc/uwsgi/README.Debian.gz
715 # For uWSGI debian uses the LSB init process, this might be changed
716 # one day, see https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=833067
717 uWSGI_APPS_AVAILABLE="${uWSGI_SETUP}/apps-available"
718 uWSGI_APPS_ENABLED="${uWSGI_SETUP}/apps-enabled"
721 # systemd --> /usr/lib/systemd/system/uwsgi@.service
722 # For uWSGI archlinux uses systemd template units, see
723 # - http://0pointer.de/blog/projects/instances.html
724 # - https://uwsgi-docs.readthedocs.io/en/latest/Systemd.html#one-service-per-app-in-systemd
725 uWSGI_APPS_AVAILABLE="${uWSGI_SETUP}/apps-archlinux"
726 uWSGI_APPS_ENABLED="${uWSGI_SETUP}"
729 # systemd --> /usr/lib/systemd/system/uwsgi.service
730 # The unit file starts uWSGI in emperor mode (/etc/uwsgi.ini), see
731 # - https://uwsgi-docs.readthedocs.io/en/latest/Emperor.html
732 uWSGI_APPS_AVAILABLE="${uWSGI_SETUP}/apps-available"
733 uWSGI_APPS_ENABLED="${uWSGI_SETUP}.d"
738 info_msg "$DIST_ID-$DIST_VERS: uWSGI not yet implemented"
747 # usage: uWSGI_restart() <myapp.ini>
750 if [[ -z $CONF ]]; then
751 err_msg "uWSGI_restart: missing arguments"
755 info_msg "restart uWSGI service"
757 case $DIST_ID-$DIST_VERS in
759 # the 'service' method seems broken in that way, that it (re-)starts
760 # the whole uwsgi process.
761 service uwsgi restart "${CONF%.*}"
764 # restart systemd template instance
765 if uWSGI_app_available "${CONF}"; then
766 systemctl restart "uwsgi@${CONF%.*}"
768 info_msg "in systemd template mode: ${CONF} not installed (nothing to restart)"
772 # in emperor mode, just touch the file to restart
773 if uWSGI_app_enabled "${CONF}"; then
774 touch "${uWSGI_APPS_ENABLED}/${CONF}"
776 info_msg "in uWSGI emperor mode: ${CONF} not installed (nothing to restart)"
780 err_msg "$DIST_ID-$DIST_VERS: uWSGI not yet implemented"
786uWSGI_app_available() {
787 # usage: uWSGI_app_available <myapp.ini>
789 if [[ -z $CONF ]]; then
790 err_msg "uWSGI_app_available: missing arguments"
793 [[ -f "${uWSGI_APPS_AVAILABLE}/${CONF}" ]]
798 # usage: uWSGI_install_app [<template option> ...] <myapp.ini>
800 # <template option>: see install_template
802 local pos_args=("$0")
806 -*) template_opts+=("$i");;
807 *) pos_args+=("$i");;
810 mkdir -p "${uWSGI_APPS_AVAILABLE}"
811 install_template "${template_opts[@]}" \
812 "${uWSGI_APPS_AVAILABLE}/${pos_args[1]}" \
814 uWSGI_enable_app "${pos_args[1]}"
815 uWSGI_restart "${pos_args[1]}"
816 info_msg "uWSGI app: ${pos_args[1]} is installed"
821 # usage: uWSGI_remove_app <myapp.ini>
824 info_msg "remove uWSGI app: ${CONF}"
825 uWSGI_disable_app "${CONF}"
826 uWSGI_restart "${CONF}"
827 rm -f "${uWSGI_APPS_AVAILABLE}/${CONF}"
831 # usage: uWSGI_app_enabled <myapp.ini>
835 if [[ -z $CONF ]]; then
836 err_msg "uWSGI_app_enabled: missing arguments"
839 case $DIST_ID-$DIST_VERS in
841 [[ -f "${uWSGI_APPS_ENABLED}/${CONF}" ]]
845 systemctl -q is-enabled "uwsgi@${CONF%.*}"
849 [[ -f "${uWSGI_APPS_ENABLED}/${CONF}" ]]
854 err_msg "$DIST_ID-$DIST_VERS: uWSGI not yet implemented"
861# shellcheck disable=SC2164
864 # usage: uWSGI_enable_app <myapp.ini>
868 if [[ -z $CONF ]]; then
869 err_msg "uWSGI_enable_app: missing arguments"
873 case $DIST_ID-$DIST_VERS in
875 mkdir -p "${uWSGI_APPS_ENABLED}"
876 rm -f "${uWSGI_APPS_ENABLED}/${CONF}"
877 ln -s "${uWSGI_APPS_AVAILABLE}/${CONF}" "${uWSGI_APPS_ENABLED}/${CONF}"
878 info_msg "enabled uWSGI app: ${CONF} (restart required)"
881 mkdir -p "${uWSGI_APPS_ENABLED}"
882 rm -f "${uWSGI_APPS_ENABLED}/${CONF}"
883 ln -s "${uWSGI_APPS_AVAILABLE}/${CONF}" "${uWSGI_APPS_ENABLED}/${CONF}"
884 systemctl enable "uwsgi@${CONF%.*}"
885 info_msg "enabled uWSGI app: ${CONF} (restart required)"
888 mkdir -p "${uWSGI_APPS_ENABLED}"
889 rm -f "${uWSGI_APPS_ENABLED}/${CONF}"
890 ln -s "${uWSGI_APPS_AVAILABLE}/${CONF}" "${uWSGI_APPS_ENABLED}/${CONF}"
891 chown "${uWSGI_USER}:${uWSGI_GROUP}" "${uWSGI_APPS_ENABLED}/${CONF}"
892 info_msg "enabled uWSGI app: ${CONF}"
896 err_msg "$DIST_ID-$DIST_VERS: uWSGI not yet implemented"
903 # usage: uWSGI_disable_app <myapp.ini>
906 if [[ -z $CONF ]]; then
907 err_msg "uWSGI_disable_app: missing arguments"
911 case $DIST_ID-$DIST_VERS in
913 service uwsgi stop "${CONF%.*}"
914 rm -f "${uWSGI_APPS_ENABLED}/${CONF}"
915 info_msg "disabled uWSGI app: ${CONF} (restart uWSGI required)"
918 systemctl stop "uwsgi@${CONF%.*}"
919 systemctl disable "uwsgi@${CONF%.*}"
920 rm -f "${uWSGI_APPS_ENABLED}/${CONF}"
923 # in emperor mode, just remove the app.ini file
924 rm -f "${uWSGI_APPS_ENABLED}/${CONF}"
928 err_msg "$DIST_ID-$DIST_VERS: uWSGI not yet implemented"
933# distro's package manager
934# ------------------------
938 # usage: TITEL='install foobar' pkg_install foopkg barpkg
940 rst_title "${TITLE:-installation of packages}" section
941 echo -e "\npackage(s)::\n"
942 # shellcheck disable=SC2068
945 if ! ask_yn "Should packages be installed?" Yn 30; then
950 # shellcheck disable=SC2068
951 apt-get install -m -y $@
954 # shellcheck disable=SC2068
955 pacman -S --noconfirm $@
958 # shellcheck disable=SC2068
966 # usage: TITEL='remove foobar' pkg_remove foopkg barpkg
968 rst_title "${TITLE:-remove packages}" section
969 echo -e "\npackage(s)::\n"
970 # shellcheck disable=SC2068
973 if ! ask_yn "Should packages be removed (purge)?" Yn 30; then
978 # shellcheck disable=SC2068
979 apt-get purge --autoremove --ignore-missing -y $@
982 # shellcheck disable=SC2068
983 pacman -R --noconfirm $@
986 # shellcheck disable=SC2068
994 # usage: pkg_is_install foopkg || pkg_install foopkg
998 dpkg -l "$1" &> /dev/null
1002 pacman -Qsq "$1" &> /dev/null
1006 dnf list -q --installed "$1" &> /dev/null
1015# shellcheck disable=SC2164
1020 # git_clone <url> <name> [<branch> [<user>]]
1021 # git_clone <url> <path> [<branch> [<user>]]
1023 # First form uses $CACHE/<name> as destination folder, second form clones
1024 # into <path>. If repository is allready cloned, pull from <branch> and
1025 # update working tree (if needed, the caller has to stash local changes).
1027 # git clone https://github.com/asciimoo/searx searx-src origin/master searxlogin
1034 local bash_cmd="bash"
1035 local remote="origin"
1037 if [[ ! "${dest:0:1}" = "/" ]]; then
1041 [[ -z $branch ]] && branch=master
1042 [[ -z $user ]] && [[ -n "${SUDO_USER}" ]] && user="${SUDO_USER}"
1043 [[ -n $user ]] && bash_cmd="sudo -H -u $user -i"
1045 if [[ -d "${dest}" ]] ; then
1046 info_msg "already cloned: $dest"
1047 tee_stderr 0.1 <<EOF | $bash_cmd 2>&1 | prefix_stdout " ${_Yellow}|$user|${_creset} "
1049git checkout -m -B "$branch" --track "$remote/$branch"
1053 info_msg "clone into: $dest"
1054 tee_stderr 0.1 <<EOF | $bash_cmd 2>&1 | prefix_stdout " ${_Yellow}|$user|${_creset} "
1055mkdir -p "$(dirname "$dest")"
1056cd "$(dirname "$dest")"
1057git clone --branch "$branch" --origin "$remote" "$url" "$(basename "$dest")"
1066 # Test if shell runs in a container.
1068 # usage: in_container && echo "process running inside a LXC container"
1069 # in_container || echo "process is not running inside a LXC container"
1072 # hint: Reads init process environment, therefore root access is required!
1073 # to be safe, take a look at the environment of process 1 (/sbin/init)
1074 # grep -qa 'container=lxc' /proc/1/environ
1076 # see lxc_init_container
1080lxc_init_container() {
1082 # Create a /.lxcenv file in the root folder. Call this once after container
1083 # is inital started.
1085 # usage: lxc_create_root_dot_lxcenv <name>
1087 info_msg "create /.lxcenv in container $1"
1088 cat <<EOF | lxc exec "${1}" -- bash | prefix_stdout "[${_BBlue}${1}${_creset}] "
1095 # usage: lxc_exists <name> || echo "container <name> does not exists"
1097 lxc info "$1" &>/dev/null
1101 # usage: lxc_image_exists <alias> || echo "image <alias> does locally not exists"
1103 lxc image info "local:$1" &>/dev/null
1107lxc_delete_container() {
1109 # usage: lxc_delete_container <container-name>
1111 if lxc info "$1" &>/dev/null; then
1112 info_msg "stop & delete instance ${_BBlue}${1}${_creset}"
1113 lxc stop "$1" &>/dev/null
1114 lxc delete "$1" | prefix_stdout
1116 warn_msg "instance '$1' does not exist / can't delete :o"
1120lxc_delete_local_image() {
1122 # usage: lxc_delete_local_image <container-name>
1124 info_msg "delete image 'local:$i'"
1125 lxc image delete "local:$i"
1135 # print list of host's SCOPE global addresses and adapters e.g::
1138 # enp4s0|192.168.1.127
1139 # lxdbr0|10.246.86.1
1140 # lxdbr0|fd42:8c58:2cd:b73f::1
1142 ip -o addr show | sed -nr 's/[0-9]*:\s*([a-z0-9]*).*inet[6]?\s*([a-z0-9.:]*).*scope global.*/\1|\2/p'
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list