Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0f37f27563 | ||
|
|
b6b4522d31 | ||
|
|
0e09506efd |
@@ -1,5 +1,9 @@
|
|||||||
# CHANGELOG
|
# CHANGELOG
|
||||||
|
|
||||||
|
## v1.0-beta - 2026-07-29
|
||||||
|
|
||||||
|
* split make files in `myos` project and docker files in `stack` project
|
||||||
|
|
||||||
## v1.0-alpha - 2022-11-29
|
## v1.0-alpha - 2022-11-29
|
||||||
|
|
||||||
* node is host
|
* node is host
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
FROM alpine:latest as dist
|
||||||
|
LABEL maintainer aynic.os <support+docker@asycn.io>
|
||||||
|
ARG DOCKER_BUILD_DIR
|
||||||
|
|
||||||
|
ARG COMPOSE_REMOTE=https://github.com/docker/compose
|
||||||
|
ARG COMPOSE_VERSION=2.5.0
|
||||||
|
ARG DOCKER_MACHINE=x86_64
|
||||||
|
ARG DOCKER_SYSTEM=Linux
|
||||||
|
|
||||||
|
RUN apk update \
|
||||||
|
&& apk add --no-cache ca-certificates \
|
||||||
|
&& OS="$(echo ${DOCKER_SYSTEM} |awk '{print tolower($0)}')" \
|
||||||
|
&& ARCH="$(echo ${DOCKER_MACHINE} |awk '{print /armv7l/ ? "armv7" : $0}')" \
|
||||||
|
&& wget -qO /usr/bin/docker-compose ${COMPOSE_REMOTE}/releases/download/v${COMPOSE_VERSION}/docker-compose-${OS}-${ARCH} \
|
||||||
|
&& chmod +x /usr/bin/docker-compose
|
||||||
|
|
||||||
|
ENTRYPOINT ["/usr/bin/docker-compose"]
|
||||||
|
|
||||||
|
FROM dist as master
|
||||||
|
ARG DOCKER_BUILD_DIR
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
# shellcheck shell=bash source=/dev/null
|
||||||
|
# ~/.bash_profile: executed by the command interpreter for bash login shell.
|
||||||
|
|
||||||
|
# bash-completion
|
||||||
|
if ! shopt -oq posix && [ -z "${BASH_COMPLETION_VERSINFO-}" ]; then
|
||||||
|
if [ "${BASH_VERSINFO[0]}" -gt 4 ] \
|
||||||
|
|| { [ "${BASH_VERSINFO[0]}" -eq 4 ] && [ "${BASH_VERSINFO[1]}" -ge 1 ] ;}; then
|
||||||
|
shopt -q progcomp && for file in \
|
||||||
|
/{*/local,usr}/share/bash-completion/bash_completion \
|
||||||
|
/etc/bash_completion; do
|
||||||
|
[ -r "$file" ] && . "$file"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
if [ -f "${XDG_CONFIG_HOME:-$HOME/.config}/bash_completion" ]; then
|
||||||
|
. "${XDG_CONFIG_HOME:-$HOME/.config}/bash_completion"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
[ -f ~/.sh_profile ] && . ~/.sh_profile
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
hardstatus alwayslastline "%{= kw}[%{G}%H%{-}] \# %?%-Lw%?[%{G}%n%f %t%{-}]%?%+Lw%?%?%=%-17< [%{B}%l%{-}]"
|
||||||
|
defscrollback 1048576
|
||||||
|
shell -$SHELL
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
# shellcheck shell=sh source=/dev/null
|
||||||
|
# ~/.sh_profile: executed by the command interpreter for login shells.
|
||||||
|
|
||||||
|
# source ~/.*aliases and ~/.*functions files
|
||||||
|
for source in aliases functions; do
|
||||||
|
for file in "$HOME"/.*"$source"; do
|
||||||
|
[ -f "$file" ] || continue
|
||||||
|
# remove $HOME/. prefix from file
|
||||||
|
file="${file#${HOME}/.}"
|
||||||
|
# remove _$source suffix from $file
|
||||||
|
command="${file%_$source}"
|
||||||
|
# source file if command exists, ie ~/.bash_aliases
|
||||||
|
command -v "$command" >/dev/null 2>&1 && . "${HOME}/.$file"
|
||||||
|
# remove $source suffix from $file, ie ~/.aliases
|
||||||
|
command="${file%$source}"
|
||||||
|
# source file if command empty, ie ~/.aliases
|
||||||
|
[ -z "$command" ] && . "${HOME}/.$file"
|
||||||
|
done
|
||||||
|
done
|
||||||
|
|
||||||
|
# source ~/.*shrc
|
||||||
|
for file in "$HOME"/.*shrc; do
|
||||||
|
[ -f "$file" ] || continue
|
||||||
|
# remove $HOME/. prefix from file
|
||||||
|
file="${file#${HOME}/.}"
|
||||||
|
# source file if match current shell
|
||||||
|
[ "$(basename "${SHELL}")" = "${file%rc}" ] && . "${HOME}/.$file"
|
||||||
|
done
|
||||||
|
|
||||||
|
# set PATH to include user's bin
|
||||||
|
for path in /*/local/sbin /*/local/bin /*/local/*/bin "${HOME}"/.*/bin; do
|
||||||
|
[ -d "$path" ] || continue
|
||||||
|
case ":${PATH}:" in
|
||||||
|
*:"$path":*) ;;
|
||||||
|
*) export PATH="${path}:$PATH" ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
[ -f ~/.profile ] && . ~/.profile
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
export EDITOR=vim
|
||||||
|
export GIT_PS1_SHOWUPSTREAM=auto
|
||||||
|
export GIT_PS1_SHOWDIRTYSTATE=true
|
||||||
|
export GIT_PS1_HIDE_IF_PWD_IGNORED=true
|
||||||
|
export PAGER=less
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
# this is aya's tmux configuration !
|
||||||
|
bind r source-file ~/.tmux.conf\; display-message "tmux.conf reloaded!"
|
||||||
|
bind R move-window -r
|
||||||
|
bind C-n switch-client -n\; refresh-client -S
|
||||||
|
bind C-p switch-client -p\; refresh-client -S
|
||||||
|
bind Escape copy-mode
|
||||||
|
bind Y run "tmux save-buffer - |xsel -i"
|
||||||
|
bind P run "xsel -o |tmux load-buffer -; tmux paste-buffer"
|
||||||
|
bind C-c run "tmux save-buffer - | xclip -i -sel clipboard >/dev/null"
|
||||||
|
bind C-v run "tmux set-buffer \"$(xclip -o -sel clipboard)\"; tmux paste-buffer"
|
||||||
|
bind -n S-down new-window
|
||||||
|
bind -n S-left prev
|
||||||
|
bind -n S-right next
|
||||||
|
bind -n C-left swap-window -t -1
|
||||||
|
bind -n C-right swap-window -t +1
|
||||||
|
set -g aggressive-resize on
|
||||||
|
set -g status-keys vi
|
||||||
|
setw -g mode-keys vi
|
||||||
|
setw -g window-status-current-bg blue
|
||||||
|
setw -g window-status-current-fg white
|
||||||
|
setw -g monitor-activity on
|
||||||
|
set -g visual-activity on
|
||||||
|
setw -g automatic-rename on
|
||||||
|
set -g default-terminal "screen"
|
||||||
|
set -g history-limit 4242
|
||||||
|
set -g status-bg black
|
||||||
|
set -g status-fg white
|
||||||
|
set -g status-interval 60
|
||||||
|
set -g status-left-length 30
|
||||||
|
set -g status-left '<#[fg=green]#S#[default]> '
|
||||||
|
set -g status-right '#[fg=yellow] %d/%m %H:%M#[default]'
|
||||||
|
set -g update-environment "SSH_ASKPASS SSH_AUTH_SOCK SSH_AGENT_PID SSH_CONNECTION"
|
||||||
@@ -0,0 +1,179 @@
|
|||||||
|
FROM alpine:latest as dist
|
||||||
|
LABEL maintainer aynic.os <support+docker@asycn.io>
|
||||||
|
ARG DOCKER_BUILD_DIR
|
||||||
|
|
||||||
|
ARG DOCKER_MACHINE=x86_64
|
||||||
|
ARG DOCKER_SYSTEM=Linux
|
||||||
|
ARG GIT_AUTHOR_EMAIL
|
||||||
|
ARG GIT_AUTHOR_NAME
|
||||||
|
|
||||||
|
ENV GIT_AUTHOR_EMAIL=${GIT_AUTHOR_EMAIL}
|
||||||
|
ENV GIT_AUTHOR_NAME=${GIT_AUTHOR_NAME}
|
||||||
|
ENV GIT_COMMITTER_EMAIL=${GIT_AUTHOR_EMAIL}
|
||||||
|
ENV GIT_COMMITTER_NAME=${GIT_AUTHOR_NAME}
|
||||||
|
|
||||||
|
RUN apk upgrade --no-cache \
|
||||||
|
&& apk add --no-cache \
|
||||||
|
bash \
|
||||||
|
curl \
|
||||||
|
gettext \
|
||||||
|
git \
|
||||||
|
gpg \
|
||||||
|
gpg-agent \
|
||||||
|
make \
|
||||||
|
nano \
|
||||||
|
netcat-openbsd \
|
||||||
|
openssh \
|
||||||
|
screen \
|
||||||
|
socat \
|
||||||
|
tmux \
|
||||||
|
wget \
|
||||||
|
xz
|
||||||
|
|
||||||
|
RUN git clone https://github.com/ingydotnet/git-subrepo \
|
||||||
|
&& cd git-subrepo \
|
||||||
|
&& git fetch origin +refs/heads/release/0.4.0: \
|
||||||
|
&& git checkout release/0.4.0 \
|
||||||
|
&& git fetch origin pull/314/head \
|
||||||
|
&& git rebase 9cbe7ba2f61552ce97fb312c8133813f970ab4a5 \
|
||||||
|
&& sed -i 's/install -C/install/' Makefile \
|
||||||
|
&& make install \
|
||||||
|
&& cd .. \
|
||||||
|
&& rm -rf git-subrepo
|
||||||
|
|
||||||
|
ARG COMPOSE_REMOTE=https://github.com/docker/compose
|
||||||
|
ARG COMPOSE_VERSION=2.5.0
|
||||||
|
ARG IPFS_VERSION=0.24.0
|
||||||
|
|
||||||
|
RUN OS="$(echo ${DOCKER_SYSTEM} |awk '{print tolower($0)}')" \
|
||||||
|
&& ARCH="$(echo ${DOCKER_MACHINE} |awk '{print /armv7l/ ? "armv7" : $0}')" \
|
||||||
|
&& wget -qO /usr/bin/docker-compose ${COMPOSE_REMOTE}/releases/download/v${COMPOSE_VERSION}/docker-compose-${OS}-${ARCH} \
|
||||||
|
&& chmod +x /usr/bin/docker-compose \
|
||||||
|
&& OS="$(echo ${DOCKER_SYSTEM} |awk '{print tolower($0)}')" \
|
||||||
|
&& ARCH="$(echo ${DOCKER_MACHINE})" \
|
||||||
|
&& wget -qO - https://github.com/koalaman/shellcheck/releases/download/stable/shellcheck-stable.${OS}.${ARCH}.tar.xz \
|
||||||
|
|tar --strip-components 1 -C /usr/local/bin -xJf - shellcheck-stable/shellcheck \
|
||||||
|
&& ARCH="$(echo ${DOCKER_MACHINE} |awk '{print /x86_64/ ? "amd64" : /arch64/ ? "arm64" : /armv(6|7)/ ? "arm" : $0}')" \
|
||||||
|
&& wget -qO - https://github.com/ipfs/kubo/releases/download/v${IPFS_VERSION}/kubo_v${IPFS_VERSION}_${OS}-${ARCH}.tar.gz \
|
||||||
|
|tar --strip-components 1 -C /usr/local/bin -xzf - kubo/ipfs \
|
||||||
|
&& mkdir -p /usr/local/lib/shellspec \
|
||||||
|
&& wget -qO - https://github.com/shellspec/shellspec/archive/refs/heads/master.tar.gz \
|
||||||
|
|tar --strip-components 1 -C /usr/local/lib/shellspec -xzf - \
|
||||||
|
&& ln -s /usr/local/lib/shellspec/shellspec /usr/local/bin/shellspec
|
||||||
|
|
||||||
|
ADD https://raw.github.com/kvz/cronlock/master/cronlock /usr/local/bin/cronlock
|
||||||
|
RUN chmod +rx /usr/local/bin/cronlock
|
||||||
|
|
||||||
|
# Setup environment variables; export SSH_AUTH_SOCK from socket directory
|
||||||
|
ENV SOCKET_DIR /tmp/ssh-agent
|
||||||
|
ENV SSH_AUTH_SOCK ${SOCKET_DIR}/socket
|
||||||
|
ENV SSH_AUTH_PROXY_SOCK ${SOCKET_DIR}/proxy-socket
|
||||||
|
|
||||||
|
COPY ${DOCKER_BUILD_DIR}/docker-entrypoint.sh /docker-entrypoint.sh
|
||||||
|
ENTRYPOINT ["/docker-entrypoint.sh"]
|
||||||
|
|
||||||
|
CMD ["start"]
|
||||||
|
|
||||||
|
FROM dist as master
|
||||||
|
ARG DOCKER_BUILD_DIR
|
||||||
|
ARG DOCKER_GID
|
||||||
|
ARG SHELL=/bin/bash
|
||||||
|
ARG SSH_BASTION_HOSTNAME
|
||||||
|
ARG SSH_BASTION_USERNAME
|
||||||
|
ARG SSH_PRIVATE_IP_RANGE
|
||||||
|
ARG SSH_PUBLIC_HOSTS
|
||||||
|
ARG UID
|
||||||
|
ARG USER
|
||||||
|
ENV UID=${UID}
|
||||||
|
ENV GID=${UID}
|
||||||
|
ENV USER=${USER}
|
||||||
|
|
||||||
|
RUN apk add --no-cache \
|
||||||
|
docker \
|
||||||
|
mysql-client \
|
||||||
|
postgresql-client \
|
||||||
|
sudo \
|
||||||
|
vim \
|
||||||
|
zsh
|
||||||
|
|
||||||
|
# If we provide a numeric UID
|
||||||
|
RUN [ "$UID" -eq "$UID" ] 2>/dev/null \
|
||||||
|
# Remove user with $UID if it is not our $USER
|
||||||
|
&& if [ "$(getent passwd $UID |awk -F: '{print $1}')" != "$USER" ]; then \
|
||||||
|
sed -i '/^'$(getent passwd $UID |awk -F: '{print $1}')':x:'$UID':/d' /etc/passwd; \
|
||||||
|
sed -i '/^'$(getent group $GID |awk -F: '{print $1}')':x:'$GID':/d' /etc/group; \
|
||||||
|
fi \
|
||||||
|
# Force $UID if our $USER already exists
|
||||||
|
&& sed -i 's/^'$USER':x:[0-9]\+:[0-9]\+:/'$USER':x:'$UID':'$GID':/' /etc/passwd \
|
||||||
|
&& sed -i 's/^'$USER':x:[0-9]\+:/'$USER':x:'$GID':/' /etc/group \
|
||||||
|
# Create $USER if it does not exist
|
||||||
|
&& if [ "$(getent passwd $UID)" = "" ]; then \
|
||||||
|
echo "$USER:x:$UID:$GID::/home/$USER:$SHELL" >> /etc/passwd; \
|
||||||
|
echo "$USER:\!:$(($(date +%s) / 60 / 60 / 24)):0:99999:7:::" >> /etc/shadow; \
|
||||||
|
echo "$USER:x:$GID:" >> /etc/group; \
|
||||||
|
fi \
|
||||||
|
&& mkdir -p /home/$USER \
|
||||||
|
&& chown $UID:$GID /home/$USER \
|
||||||
|
|| true
|
||||||
|
|
||||||
|
# If we provide a numeric DOCKER_GID
|
||||||
|
RUN [ "$DOCKER_GID" -eq "$DOCKER_GID" ] 2>/dev/null \
|
||||||
|
&& if [ "$(getent group docker |awk -F: '{print $3}')" != "$DOCKER_GID" ]; then \
|
||||||
|
sed -i 's/^docker:x:[0-9]\+:/docker:x:'$DOCKER_GID':/' /etc/group; \
|
||||||
|
fi \
|
||||||
|
|| true
|
||||||
|
|
||||||
|
## User groups
|
||||||
|
RUN adduser $USER wheel \
|
||||||
|
# && adduser $USER docker \
|
||||||
|
&& echo '%wheel ALL=(ALL:ALL) NOPASSWD: ALL' >> /etc/sudoers
|
||||||
|
|
||||||
|
RUN echo -e "\n\
|
||||||
|
Host *\n\
|
||||||
|
LogLevel quiet\n\
|
||||||
|
Compression yes\n\
|
||||||
|
" >> /etc/ssh/ssh_config \
|
||||||
|
&& if [ -n "${SSH_PRIVATE_IP_RANGE}" ] && [ -n "${SSH_BASTION_HOSTNAME}" ]; then \
|
||||||
|
echo -e "\
|
||||||
|
Host ${SSH_PRIVATE_IP_RANGE}\n\
|
||||||
|
ProxyCommand ssh -q ssh-bastion nc -q0 %h 22\n\
|
||||||
|
HostName %h\n\
|
||||||
|
StrictHostKeyChecking no\n\
|
||||||
|
UserKnownHostsFile /dev/null\n\
|
||||||
|
Host ssh-bastion\n\
|
||||||
|
HostName ${SSH_BASTION_HOSTNAME}\
|
||||||
|
" >> /etc/ssh/ssh_config; \
|
||||||
|
if [ -n "${SSH_BASTION_USERNAME}" ]; then \
|
||||||
|
echo -e "\
|
||||||
|
User ${SSH_BASTION_USERNAME}\n\
|
||||||
|
" >> /etc/ssh/ssh_config; \
|
||||||
|
fi \
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Custom rc functions
|
||||||
|
COPY ${DOCKER_BUILD_DIR}/rc*.sh /etc/profile.d/
|
||||||
|
|
||||||
|
RUN mkdir -p $SOCKET_DIR && chown $USER $SOCKET_DIR
|
||||||
|
|
||||||
|
VOLUME ${SOCKET_DIR}
|
||||||
|
|
||||||
|
USER $USER
|
||||||
|
ENV SHELL=${SHELL}
|
||||||
|
WORKDIR /home/$USER
|
||||||
|
|
||||||
|
# git config
|
||||||
|
RUN mkdir -p ~/.ssh ~/.config/git \
|
||||||
|
&& ssh-keyscan -t rsa -H ${SSH_PUBLIC_HOSTS} >> ~/.ssh/known_hosts \
|
||||||
|
&& echo -e "\
|
||||||
|
.DS_Store\n\
|
||||||
|
.idea/\n\
|
||||||
|
.nfs*\n\
|
||||||
|
.theia/settings.json\n\
|
||||||
|
*~\n\
|
||||||
|
*.log\n\
|
||||||
|
*.swp\n\
|
||||||
|
Thumbs.db\n\
|
||||||
|
" > ~/.config/git/ignore
|
||||||
|
|
||||||
|
# dot files
|
||||||
|
COPY ${DOCKER_BUILD_DIR}/.* /home/$USER/
|
||||||
Executable
+31
@@ -0,0 +1,31 @@
|
|||||||
|
#!/usr/bin/env sh
|
||||||
|
set -euo errexit
|
||||||
|
|
||||||
|
# Print a debug message if debug mode is on ($DEBUG is not empty)
|
||||||
|
# @param message
|
||||||
|
debug_msg ()
|
||||||
|
{
|
||||||
|
if [ -n "${DEBUG:-}" -a "${DEBUG:-}" != "false" ]; then
|
||||||
|
echo "$@"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
case "${1:-start}" in
|
||||||
|
|
||||||
|
start)
|
||||||
|
debug_msg "Starting..."
|
||||||
|
|
||||||
|
# Create proxy-socket for ssh-agent (to give everyone access to the ssh-agent socket)
|
||||||
|
debug_msg "Create proxy socket..."
|
||||||
|
rm -f ${SSH_AUTH_SOCK} ${SSH_AUTH_PROXY_SOCK} > /dev/null 2>&1
|
||||||
|
socat UNIX-LISTEN:${SSH_AUTH_PROXY_SOCK},perm=0666,fork UNIX-CONNECT:${SSH_AUTH_SOCK} &
|
||||||
|
|
||||||
|
debug_msg "Launch ssh-agent..."
|
||||||
|
exec /usr/bin/ssh-agent -a ${SSH_AUTH_SOCK} -D >/dev/null
|
||||||
|
;;
|
||||||
|
|
||||||
|
*)
|
||||||
|
debug_msg "Exec: $@"
|
||||||
|
exec "$@"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
# shellcheck shell=sh
|
||||||
|
# file rc.sh: Call user defined functions
|
||||||
|
## author: Yann "aya" Autissier
|
||||||
|
## license: GPL
|
||||||
|
## version: 20260730
|
||||||
|
|
||||||
|
case $- in
|
||||||
|
# if this is an interactive shell
|
||||||
|
*i*)
|
||||||
|
# load user stuff from ~/.rc.d/* files
|
||||||
|
for file in "${HOME}"/.rc.d/*; do
|
||||||
|
# read files only
|
||||||
|
if [ -f "${file}" ]; then
|
||||||
|
func_name=$(basename "${file}")
|
||||||
|
func_args=$(cat "${file}")
|
||||||
|
# at this stage, func_name can start with numbers to allow ordering function calls with file names starting with numbers
|
||||||
|
# func_name must start with a letter, remove all other characters at the beginning of func_name until a letter is found
|
||||||
|
while [ "${func_name}" != "" ] && [ "${func_name#[a-z]}" = "${func_name}" ]; do
|
||||||
|
# remove first char of func_name
|
||||||
|
func_name="${func_name#?}"
|
||||||
|
done
|
||||||
|
# call user function with args passed from the content of the file
|
||||||
|
# an empty file means no args at all, do not pass an empty string
|
||||||
|
if command -v "${func_name}" >/dev/null 2>&1; then
|
||||||
|
if [ -n "${func_args}" ]; then
|
||||||
|
"${func_name}" "${func_args}"
|
||||||
|
else
|
||||||
|
"${func_name}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
# load user stuff from RC_* env vars
|
||||||
|
IFS="$(printf '%b_' '\n')"; IFS="${IFS%_}"; for line in $(printenv 2>/dev/null |awk '$0 ~ /^RC_[0-9A-Z_]*=/' |sort); do
|
||||||
|
func_name=$(printf '%s\n' "${line%%=*}" |awk '{print tolower(substr($0,4))}')
|
||||||
|
eval func_args=\$"${line%%=*}"
|
||||||
|
[ "${func_args}" = "false" ] && continue
|
||||||
|
[ "${func_args}" = "true" ] && unset func_args
|
||||||
|
# at this stage, func_name can start with numbers to allow ordering function calls with file names starting with numbers
|
||||||
|
# func_name must start with a letter, remove all other characters at the beginning of func_name until a letter is found
|
||||||
|
while [ "${func_name}" != "" ] && [ "${func_name#[a-z]}" = "${func_name}" ]; do
|
||||||
|
# remove first char of func_name
|
||||||
|
func_name="${func_name#?}"
|
||||||
|
done
|
||||||
|
# call user function with args passed from the value of the env var
|
||||||
|
# RC_FOO=true means no args at all, do not pass an empty string
|
||||||
|
if command -v "${func_name}" >/dev/null 2>&1; then
|
||||||
|
if [ -n "${func_args:-}" ]; then
|
||||||
|
"${func_name}" "${func_args}"
|
||||||
|
else
|
||||||
|
"${func_name}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
unset IFS
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# vim:ts=2:sw=2:sts=2:et
|
||||||
@@ -0,0 +1,368 @@
|
|||||||
|
# shellcheck shell=sh
|
||||||
|
# file rc_functions.sh: Define shell functions
|
||||||
|
## author: Yann "aya" Autissier
|
||||||
|
## license: GPL
|
||||||
|
## version: 20260730
|
||||||
|
|
||||||
|
# function force: Run a command sine die
|
||||||
|
force() {
|
||||||
|
if [ $# -gt 0 ]; then
|
||||||
|
while true; do
|
||||||
|
"$@"
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# function force8: Run a command sine die if not already running
|
||||||
|
force8() {
|
||||||
|
if [ $# -gt 0 ]; then
|
||||||
|
while true; do
|
||||||
|
# awk expression to match $@
|
||||||
|
[ "$(ps wwx -o args 2>/dev/null |awk -v field="${PS_X_FIELD:-1}" '
|
||||||
|
BEGIN { nargs=split("'"$*"'",args); }
|
||||||
|
# first field matched
|
||||||
|
$field == args[1] {
|
||||||
|
matched=1;
|
||||||
|
# match following fields
|
||||||
|
for (i=1;i<=NF-field;i++) {
|
||||||
|
if ($(i+field) == args[i+1]) { matched++; }
|
||||||
|
};
|
||||||
|
# all fields matched
|
||||||
|
if (matched == nargs) { found++; }
|
||||||
|
}
|
||||||
|
END { print found+0; }'
|
||||||
|
)" = 0 ] && "$@"
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# function lang_set; Export default LANG
|
||||||
|
lang_set() {
|
||||||
|
export $(awk -F'=' '$1 == "LANG"' /etc/default/locale 2>/dev/null) >/dev/null
|
||||||
|
}
|
||||||
|
|
||||||
|
# function load_average; Print the current load average
|
||||||
|
load_average() {
|
||||||
|
uptime 2>/dev/null |awk '{printf "%.1f\n", $(NF-2)}'
|
||||||
|
}
|
||||||
|
|
||||||
|
# function process_count: Print number of "processes"/"running processes"/"D-state"
|
||||||
|
process_count() {
|
||||||
|
ps ax -o stat 2>/dev/null |awk '
|
||||||
|
$1 ~ /R/ {process_running++};
|
||||||
|
$1 ~ /D/ {process_dstate++};
|
||||||
|
END { print NR-1"/"process_running+0"/"process_dstate+0; }'
|
||||||
|
}
|
||||||
|
|
||||||
|
# function prompt_set: Export custom PROMPT_COMMAND
|
||||||
|
prompt_set() {
|
||||||
|
# zsh: PROMPT_COMMAND is bash-only, set the terminal title from a precmd hook
|
||||||
|
if [ -n "${ZSH_VERSION:-}" ]; then
|
||||||
|
_prompt_precmd() {
|
||||||
|
local __ret=$? dcs st host
|
||||||
|
case "${TERM}" in
|
||||||
|
screen*) dcs=$'\ek'; st=$'\e\\';;
|
||||||
|
*) dcs=$'\e]0;'; st=$'\a';;
|
||||||
|
esac
|
||||||
|
host="${HOSTNAME:-${HOST}}"
|
||||||
|
if [ -n "${STY}" ]; then
|
||||||
|
printf '%s%s%s' "${dcs}" "${PWD##*/}" "${st}"
|
||||||
|
else
|
||||||
|
printf '%s%s@%s:%s%s' "${dcs}" "${USER}" "${host%%.*}" "${PWD##*/}" "${st}"
|
||||||
|
fi
|
||||||
|
return ${__ret}
|
||||||
|
}
|
||||||
|
autoload -Uz add-zsh-hook 2>/dev/null && add-zsh-hook precmd _prompt_precmd
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
case "${TERM}" in
|
||||||
|
screen*)
|
||||||
|
ESCAPE_CODE_DCS="\033k"
|
||||||
|
ESCAPE_CODE_ST="\033\\"
|
||||||
|
;;
|
||||||
|
linux*|xterm*|rxvt*)
|
||||||
|
ESCAPE_CODE_DCS="\033]0;"
|
||||||
|
ESCAPE_CODE_ST="\007"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
# in a screen
|
||||||
|
if [ -n "${STY}" ]; then
|
||||||
|
export PROMPT_COMMAND='printf\
|
||||||
|
"${ESCAPE_CODE_DCS:-\033]0;}%s${ESCAPE_CODE_ST:-\007}"\
|
||||||
|
"${PWD##*/}"'
|
||||||
|
else
|
||||||
|
export PROMPT_COMMAND='printf\
|
||||||
|
"${ESCAPE_CODE_DCS:-\033]0;}%s@%s:%s${ESCAPE_CODE_ST:-\007}"\
|
||||||
|
"${USER}"\
|
||||||
|
"${HOSTNAME%%.*}"\
|
||||||
|
"${PWD##*/}"'
|
||||||
|
fi
|
||||||
|
unset ESCAPE_CODE_DCS ESCAPE_CODE_ST
|
||||||
|
}
|
||||||
|
|
||||||
|
# function ps1_set: Export custom PS1
|
||||||
|
ps1_set() {
|
||||||
|
# zsh: bash prompt escapes (\[ \]) and "$0" shell detection do not apply;
|
||||||
|
# rebuild PROMPT from a precmd hook using zsh's %{ %} non-printing markers
|
||||||
|
if [ -n "${ZSH_VERSION:-}" ]; then
|
||||||
|
_ps1_precmd() {
|
||||||
|
local __ret=$?
|
||||||
|
local dgray=$'%{\e[1;30m%}' red=$'%{\e[01;31m%}' green=$'%{\e[01;32m%}' \
|
||||||
|
brown=$'%{\e[0;33m%}' yellow=$'%{\e[01;33m%}' blue=$'%{\e[01;34m%}' \
|
||||||
|
cyan=$'%{\e[0;36m%}' gray=$'%{\e[0;37m%}' reset=$'%{\e[0m%}'
|
||||||
|
local scol ucol hcol count user host wd git end sym uid h br
|
||||||
|
uid="$(id -u)"
|
||||||
|
# exit status: blue on success, yellow on 1, red otherwise
|
||||||
|
case "${__ret}" in
|
||||||
|
0) scol="${blue}";;
|
||||||
|
1) scol="${yellow}";;
|
||||||
|
*) scol="${red}";;
|
||||||
|
esac
|
||||||
|
count="${dgray}[${scol}${__ret}"
|
||||||
|
type process_count >/dev/null 2>&1 \
|
||||||
|
&& count="${count}${dgray}|${blue}$(process_count 2>/dev/null)"
|
||||||
|
type user_count >/dev/null 2>&1 \
|
||||||
|
&& count="${count}${dgray}|${blue}$(user_count 2>/dev/null)"
|
||||||
|
type load_average >/dev/null 2>&1 \
|
||||||
|
&& count="${count}${dgray}|${blue}$(load_average 2>/dev/null)"
|
||||||
|
count="${count}${dgray}]${reset}"
|
||||||
|
# user: red for root, brown otherwise
|
||||||
|
[ "${uid}" = 0 ] && ucol="${red}" || ucol="${brown}"
|
||||||
|
user="${ucol}$(id -nu):${uid}${reset}"
|
||||||
|
# hostname: red on prod, yellow if ENV set, green otherwise
|
||||||
|
h="$(hostname |sed 's/\..*//')"
|
||||||
|
case "${ENV}${h}" in
|
||||||
|
*[Pp][Rr][Oo][Dd]*|*[Pp][Rr][Dd]*) hcol="${red}";;
|
||||||
|
*) [ -n "${ENV}" ] && hcol="${yellow}" || hcol="${green}";;
|
||||||
|
esac
|
||||||
|
host="${hcol}${h}${reset}"
|
||||||
|
# workdir with ~ for $HOME
|
||||||
|
wd="${gray}$(pwd |sed 's|^'"${HOME}"'\(/.*\)*$|~\1|')${reset}"
|
||||||
|
# git branch
|
||||||
|
if type __git_ps1 >/dev/null 2>&1; then
|
||||||
|
git="$(__git_ps1 ' (%s)' 2>/dev/null)"
|
||||||
|
else
|
||||||
|
br="$(git rev-parse --abbrev-ref HEAD 2>/dev/null)"
|
||||||
|
[ -n "${br}" ] && git=" (${br})"
|
||||||
|
fi
|
||||||
|
git="${cyan}${git}${reset}"
|
||||||
|
# tail: # for root, $ otherwise
|
||||||
|
[ "${uid}" = 0 ] && sym='#' || sym='$'
|
||||||
|
end="${dgray}${sym}${reset}"
|
||||||
|
PROMPT="${count}${user}${dgray}@${host}${dgray}:${wd}${git}${end} "
|
||||||
|
}
|
||||||
|
autoload -Uz add-zsh-hook 2>/dev/null && add-zsh-hook precmd _ps1_precmd
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
case "$0" in
|
||||||
|
*sh)
|
||||||
|
COLOR_DGRAY="\[\033[1;30m\]"
|
||||||
|
COLOR_RED="\[\033[01;31m\]"
|
||||||
|
COLOR_GREEN="\[\033[01;32m\]"
|
||||||
|
COLOR_BROWN="\[\033[0;33m\]"
|
||||||
|
COLOR_YELLOW="\[\033[01;33m\]"
|
||||||
|
COLOR_BLUE="\[\033[01;34m\]"
|
||||||
|
COLOR_CYAN="\[\033[0;36m\]"
|
||||||
|
COLOR_GRAY="\[\033[0;37m\]"
|
||||||
|
COLOR_RESET="\[\033[0m\]"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
PS1_STATUS="\$?"
|
||||||
|
PS1_COUNT="${COLOR_DGRAY}[\`
|
||||||
|
case \"$PS1_STATUS\" in
|
||||||
|
0)
|
||||||
|
printf \"${COLOR_BLUE}${PS1_STATUS}\";;
|
||||||
|
1)
|
||||||
|
printf \"${COLOR_YELLOW}${PS1_STATUS}\";;
|
||||||
|
*)
|
||||||
|
printf \"${COLOR_RED}${PS1_STATUS}\";;
|
||||||
|
esac
|
||||||
|
type process_count >/dev/null 2>&1 && printf\
|
||||||
|
\"${COLOR_DGRAY}|${COLOR_BLUE}%s\"\
|
||||||
|
\"\$(process_count 2>/dev/null)\"
|
||||||
|
type user_count >/dev/null 2>&1 && printf\
|
||||||
|
\"${PS1_COUNT}${COLOR_DGRAY}|${COLOR_BLUE}%s\"\
|
||||||
|
\"\$(user_count 2>/dev/null)\"
|
||||||
|
type load_average >/dev/null 2>&1 && printf\
|
||||||
|
\"${PS1_COUNT}${COLOR_DGRAY}|${COLOR_BLUE}%s\"\
|
||||||
|
\"\$(load_average 2>/dev/null)\"
|
||||||
|
\`${COLOR_DGRAY}]${COLOR_RESET}"
|
||||||
|
PS1_END="${COLOR_DGRAY}\$(
|
||||||
|
if [ \"\$(id -u)\" = 0 ]; then
|
||||||
|
printf \"#\";
|
||||||
|
else
|
||||||
|
printf \"\$\";
|
||||||
|
fi
|
||||||
|
)${COLOR_RESET}"
|
||||||
|
PS1_GIT="\$(
|
||||||
|
if type __git_ps1 >/dev/null 2>&1; then
|
||||||
|
printf \"\$(__git_ps1 2>/dev/null \" (%s)\")\"
|
||||||
|
else
|
||||||
|
printf \"\$(BRANCH=\$(git rev-parse --abbrev-ref HEAD 2>/dev/null);\
|
||||||
|
[ -n \"\${BRANCH}\" ] && printf \" (\${BRANCH})\")\"
|
||||||
|
fi
|
||||||
|
)"
|
||||||
|
PS1_GIT="${COLOR_CYAN}${PS1_GIT}${COLOR_RESET}"
|
||||||
|
PS1_HOSTNAME_COLOR="\`case \"\${ENV}${HOSTNAME%%.*}\" in
|
||||||
|
*[Pp][Rr][0Oo][Dd]*|*[Pp][Rr][Dd]*)
|
||||||
|
printf \"${COLOR_RED}\";;
|
||||||
|
*)
|
||||||
|
if [ -n \"\${ENV}\" ]; then
|
||||||
|
printf \"${COLOR_YELLOW}\";
|
||||||
|
else
|
||||||
|
printf \"${COLOR_GREEN}\";
|
||||||
|
fi;;
|
||||||
|
esac\`"
|
||||||
|
PS1_HOSTNAME="${PS1_HOSTNAME_COLOR}\$(hostname |sed 's/\..*//')${COLOR_RESET}"
|
||||||
|
PS1_USER_COLOR="\$(
|
||||||
|
if [ \"\$(id -u)\" = 0 ]; then
|
||||||
|
printf \"${COLOR_RED}\";
|
||||||
|
else
|
||||||
|
printf \"${COLOR_BROWN}\";
|
||||||
|
fi
|
||||||
|
)"
|
||||||
|
PS1_USER="${PS1_USER_COLOR}\$(id -nu):\$(id -u)${COLOR_RESET}"
|
||||||
|
PS1_WORKDIR="${COLOR_GRAY}\$(
|
||||||
|
pwd |sed 's|^'\${HOME}'\(/.*\)*$|~\1|'
|
||||||
|
)${COLOR_RESET}"
|
||||||
|
PS1="${PS1_COUNT}${PS1_USER}${COLOR_DGRAY}@${PS1_HOSTNAME}"
|
||||||
|
PS1="${PS1}${COLOR_DGRAY}:${PS1_WORKDIR}${PS1_GIT}${PS1_END} "
|
||||||
|
export 'PS1'
|
||||||
|
unset PS1_COUNT PS1_END PS1_GIT PS1_HOSTNAME PS1_HOSTNAME_COLOR\
|
||||||
|
PS1_USER PS1_USER_COLOR PS1_STATUS PS1_WORKDIR
|
||||||
|
}
|
||||||
|
|
||||||
|
# function screen_attach: Attach existing screen session or Create a new one
|
||||||
|
screen_attach() {
|
||||||
|
command -v screen >/dev/null 2>&1 || return
|
||||||
|
SCREEN_SESSION="$(id -nu)@$(hostname |sed 's/\..*//')"
|
||||||
|
if [ -z "${STY}" ]; then
|
||||||
|
# attach screen in tmux window 0 only ;)
|
||||||
|
[ -n "${TMUX}" ] \
|
||||||
|
&& [ "$(tmux list-window 2>/dev/null |awk '$NF == "(active)" {print $1}'\
|
||||||
|
|sed 's/:$//')" != "0" ] \
|
||||||
|
&& return
|
||||||
|
printf 'Attaching screen.' && sleep 1\
|
||||||
|
&& printf '.' && sleep 1\
|
||||||
|
&& printf '.' && sleep 1
|
||||||
|
exec screen -xRR -S "${SCREEN_SESSION}"
|
||||||
|
fi
|
||||||
|
unset SCREEN_SESSION
|
||||||
|
}
|
||||||
|
|
||||||
|
# function screen_detach: Detach current screen session
|
||||||
|
screen_detach() {
|
||||||
|
screen -d
|
||||||
|
}
|
||||||
|
|
||||||
|
# function ssh_add: Load all private keys in ~/.ssh/ to ssh agent
|
||||||
|
ssh_add() {
|
||||||
|
command -v ssh-agent >/dev/null 2>&1 && command -v ssh-add >/dev/null 2>&1 || return
|
||||||
|
# zsh: emulate bash handling of unmatched globs (scoped to this function via localoptions)
|
||||||
|
[ -n "${ZSH_VERSION:-}" ] && setopt localoptions nonomatch
|
||||||
|
SSH_AGENT_DIR="/tmp/ssh-$(id -u)"
|
||||||
|
SSH_AGENT_SOCK="${SSH_AGENT_DIR}/agent@$(hostname |sed 's/\..*//')"
|
||||||
|
# launch a new agent
|
||||||
|
if [ -z "${SSH_AUTH_SOCK}" ]; then
|
||||||
|
[ ! -d "${SSH_AGENT_DIR}" ] \
|
||||||
|
&& mkdir -p "${SSH_AGENT_DIR}" 2>/dev/null\
|
||||||
|
&& chmod 0700 "${SSH_AGENT_DIR}"
|
||||||
|
# search for an already running agent
|
||||||
|
if ps wwx -o args |awk '$1 ~ "ssh-agent$" && $3 == "'"${SSH_AGENT_SOCK}"'"' |wc -l |grep -q 0; then
|
||||||
|
rm -f "${SSH_AGENT_SOCK}"
|
||||||
|
ssh-agent -a "${SSH_AGENT_SOCK}" >/dev/null 2>&1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
# attach to agent
|
||||||
|
export SSH_AUTH_SOCK="${SSH_AUTH_SOCK:-${SSH_AGENT_SOCK}}"
|
||||||
|
# list private keys to add
|
||||||
|
# shellcheck disable=SC2068
|
||||||
|
for dir in ${@:-${HOME}/.ssh}; do
|
||||||
|
if [ "${SSH_ADD_RECURSIVE:-}" = true ]; then
|
||||||
|
GREP_RECURSIVE_FLAG="r"
|
||||||
|
else
|
||||||
|
GREP_RECURSIVE_CHAR="*"
|
||||||
|
fi
|
||||||
|
SSH_PRIVATE_KEYS="${SSH_PRIVATE_KEYS:-} ${dir}/id_ed25519 ${dir}/id_rsa $(grep -l${GREP_RECURSIVE_FLAG:-} 'PRIVATE KEY' "${dir}/"${GREP_RECURSIVE_CHAR:-} 2>/dev/null |grep -vwE "${dir}/id_(rsa|ed25519)")"
|
||||||
|
done
|
||||||
|
# split on spaces/newlines via tr, portable across bash (IFS split) and zsh (no word split)
|
||||||
|
printf '%s' "${SSH_PRIVATE_KEYS}" |tr ' ' '\n' |while read -r file; do
|
||||||
|
[ -r "${file}" ] || continue
|
||||||
|
# fingerprint is empty when ssh-keygen cannot read the key (legacy PEM without .pub):
|
||||||
|
# in that case add it instead of matching the empty pattern against every agent line
|
||||||
|
fingerprint="$(ssh-keygen -lf "${file}" 2>/dev/null |awk '{print $2}')"
|
||||||
|
[ -n "${fingerprint}" ] && ssh-add -l 2>/dev/null |grep -qF "${fingerprint}" && continue
|
||||||
|
# add private key to agent
|
||||||
|
ssh-add "${file}"
|
||||||
|
done
|
||||||
|
unset GREP_RECURSIVE_CHAR GREP_RECURSIVE_FLAG SSH_AGENT_DIR SSH_AGENT_SOCK SSH_PRIVATE_KEYS
|
||||||
|
}
|
||||||
|
|
||||||
|
# function ssh_del: removes all private keys in ~/.ssh/ from ssh agent
|
||||||
|
ssh_del() {
|
||||||
|
command -v ssh-add >/dev/null 2>&1 || return
|
||||||
|
# zsh: emulate bash handling of unmatched globs (scoped to this function via localoptions)
|
||||||
|
[ -n "${ZSH_VERSION:-}" ] && setopt localoptions nonomatch
|
||||||
|
# attach to agent
|
||||||
|
if [ -z "${SSH_AUTH_SOCK}" ]; then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
# list private keys to del
|
||||||
|
# shellcheck disable=SC2068
|
||||||
|
for dir in ${@:-${HOME}/.ssh}; do
|
||||||
|
if [ "${SSH_DEL_RECURSIVE:-}" = true ]; then
|
||||||
|
GREP_RECURSIVE_FLAG="r"
|
||||||
|
else
|
||||||
|
GREP_RECURSIVE_CHAR="*"
|
||||||
|
fi
|
||||||
|
SSH_PRIVATE_KEYS="${SSH_PRIVATE_KEYS:-} ${dir}/id_ed25519 ${dir}/id_rsa $(grep -l${GREP_RECURSIVE_FLAG:-} 'PRIVATE KEY' "${dir}/"${GREP_RECURSIVE_CHAR:-} 2>/dev/null |grep -vwE "${dir}/id_(rsa|ed25519)")"
|
||||||
|
done
|
||||||
|
# split on spaces/newlines via tr, portable across bash (IFS split) and zsh (no word split)
|
||||||
|
printf '%s' "${SSH_PRIVATE_KEYS}" |tr ' ' '\n' |while read -r file; do
|
||||||
|
[ -r "${file}" ] || continue
|
||||||
|
# skip keys we cannot fingerprint, an empty pattern would match any agent line
|
||||||
|
fingerprint="$(ssh-keygen -lf "${file}" 2>/dev/null |awk '{print $2}')"
|
||||||
|
[ -n "${fingerprint}" ] || continue
|
||||||
|
# remove private key from agent
|
||||||
|
ssh-add -l 2>/dev/null |grep -qF "${fingerprint}" && ssh-add -d "${file}"
|
||||||
|
done
|
||||||
|
unset GREP_RECURSIVE_CHAR GREP_RECURSIVE_FLAG SSH_PRIVATE_KEYS
|
||||||
|
}
|
||||||
|
|
||||||
|
# function tmux_attach: Attach existing tmux session or Create a new one
|
||||||
|
tmux_attach() {
|
||||||
|
command -v tmux >/dev/null 2>&1 || return
|
||||||
|
TMUX_SESSION="$(id -nu)@$(hostname |sed 's/\..*//')"
|
||||||
|
# do not attach tmux in screen ;)
|
||||||
|
if [ -z "${TMUX}" -a -z "${STY}" ]; then
|
||||||
|
printf 'Attaching tmux.' && sleep 1\
|
||||||
|
&& printf '.' && sleep 1\
|
||||||
|
&& printf '.' && sleep 1
|
||||||
|
exec tmux -L"${TMUX_SESSION}" new-session -A -s"${TMUX_SESSION}"
|
||||||
|
fi
|
||||||
|
unset TMUX_SESSION
|
||||||
|
}
|
||||||
|
|
||||||
|
# function tmux_detach: Detach current tmux session
|
||||||
|
tmux_detach() {
|
||||||
|
tmux detach
|
||||||
|
}
|
||||||
|
|
||||||
|
# function user_count: Print number of "users sessions"/"users"/"logged users"
|
||||||
|
user_count() {
|
||||||
|
ps ax -o pid,user,tty,comm 2>/dev/null |awk '
|
||||||
|
$3 ~ /^(pts\/|tty[sS]?|[0-9]+,)[0-9]+$/ && $4 != "getty" { users_sessions++; logged[$2]++; };
|
||||||
|
$1 ~ /^[0-9]+$/ { count[$2]++; }
|
||||||
|
END {
|
||||||
|
for (uc in count) { c = c" "uc; }; users_count=split(c,v," ");
|
||||||
|
for (ul in logged) { l = l" "ul; }; users_logged=split(l,v," ");
|
||||||
|
print users_sessions+0"/"users_count+0"/"users_logged+0;
|
||||||
|
}'
|
||||||
|
}
|
||||||
+4
-4
@@ -121,8 +121,8 @@ logs: docker-stack-logs ## Display application dockers logs
|
|||||||
|
|
||||||
# target ps: List application dockers
|
# target ps: List application dockers
|
||||||
# on local host
|
# on local host
|
||||||
.PHONY: ps
|
.PHONY: ps status
|
||||||
ps: docker-stack-ps ## List application dockers
|
ps status: docker-stack-ps ## List application dockers
|
||||||
|
|
||||||
# target rebuild: Rebuild application docker images
|
# target rebuild: Rebuild application docker images
|
||||||
# on local host
|
# on local host
|
||||||
@@ -137,8 +137,8 @@ rebuild@%:
|
|||||||
|
|
||||||
# target recreate: Recreate application dockers
|
# target recreate: Recreate application dockers
|
||||||
# on local host
|
# on local host
|
||||||
.PHONY: recreate
|
.PHONY: recreate reload
|
||||||
recreate: docker-stack-recreate app-start ## Recreate application dockers
|
recreate reload: docker-stack-recreate app-start ## Recreate application dockers
|
||||||
|
|
||||||
# target reinstall: Fire clean, Call .env target, Call install target
|
# target reinstall: Fire clean, Call .env target, Call install target
|
||||||
# on local host
|
# on local host
|
||||||
|
|||||||
+4
-4
@@ -1,4 +1,4 @@
|
|||||||
DOCKER_DIR ?= $(wildcard $(patsubst %,%/docker,$(APP_DIR) $(SHARE_DIR)))
|
DOCKER_DIR ?= $(sort $(realpath $(wildcard $(patsubst %,%/docker,$(APP_DIR) $(SHARE_DIR) $(patsubst %,%/myos,$(SHARE_DIR))))))
|
||||||
DOCKER_DIR_NAME ?= docker
|
DOCKER_DIR_NAME ?= docker
|
||||||
DOCKER_ENV_ARGS ?= $(docker_env_args)
|
DOCKER_ENV_ARGS ?= $(docker_env_args)
|
||||||
DOCKER_EXEC_OPTIONS ?=
|
DOCKER_EXEC_OPTIONS ?=
|
||||||
@@ -38,7 +38,7 @@ MYOS_STACK_FILE ?= networks volumes
|
|||||||
RESU_DOCKER_REPOSITORY ?= $(subst -,/,$(USER_COMPOSE_PROJECT_NAME))
|
RESU_DOCKER_REPOSITORY ?= $(subst -,/,$(USER_COMPOSE_PROJECT_NAME))
|
||||||
SHARE_DIR ?= . .. ~/.local/share /usr/local/share /usr/share
|
SHARE_DIR ?= . .. ~/.local/share /usr/local/share /usr/share
|
||||||
STACK ?= $(APP)
|
STACK ?= $(APP)
|
||||||
STACK_DIR ?= $(wildcard $(patsubst %,%/$(STACK_DIR_NAME),$(APP_DIR) $(SHARE_DIR)))
|
STACK_DIR ?= $(sort $(realpath $(wildcard $(patsubst %,%/$(STACK_DIR_NAME),$(APP_DIR) $(SHARE_DIR) $(patsubst %,%/myos,$(SHARE_DIR))))))
|
||||||
STACK_DIR_NAME ?= stack
|
STACK_DIR_NAME ?= stack
|
||||||
USER_COMPOSE_PROJECT_NAME ?= $(subst .,-,$(RESU))
|
USER_COMPOSE_PROJECT_NAME ?= $(subst .,-,$(RESU))
|
||||||
USER_COMPOSE_SERVICE_NAME ?= $(USER_COMPOSE_PROJECT_NAME)
|
USER_COMPOSE_SERVICE_NAME ?= $(USER_COMPOSE_PROJECT_NAME)
|
||||||
@@ -179,7 +179,7 @@ define docker-path
|
|||||||
$(eval docker_path := $(foreach dir,$(docker_dir),$(patsubst %/Dockerfile,%,$(wildcard $(patsubst %,%/$(docker_name)/Dockerfile,$(dir))))))
|
$(eval docker_path := $(foreach dir,$(docker_dir),$(patsubst %/Dockerfile,%,$(wildcard $(patsubst %,%/$(docker_name)/Dockerfile,$(dir))))))
|
||||||
$(call debug,docker_name docker_dir docker_path)
|
$(call debug,docker_name docker_dir docker_path)
|
||||||
$(if $(docker_path),
|
$(if $(docker_path),
|
||||||
$(firstword $(docker_path))
|
$(docker_path)
|
||||||
, $(call ERROR,Unable to find a docker,$(docker_name),in dir,$(docker_dir))
|
, $(call ERROR,Unable to find a docker,$(docker_name),in dir,$(docker_dir))
|
||||||
))
|
))
|
||||||
endef
|
endef
|
||||||
@@ -240,7 +240,7 @@ define stack-path
|
|||||||
$(eval stack_dir := $(or $(2),$(STACK_DIR)))
|
$(eval stack_dir := $(or $(2),$(STACK_DIR)))
|
||||||
$(eval stack_path := $(foreach dir,$(stack_dir),$(patsubst %/,%,$(wildcard $(patsubst %,%/$(stack_name)/,$(dir))))))
|
$(eval stack_path := $(foreach dir,$(stack_dir),$(patsubst %/,%,$(wildcard $(patsubst %,%/$(stack_name)/,$(dir))))))
|
||||||
$(if $(stack_path),
|
$(if $(stack_path),
|
||||||
$(firstword $(stack_path))
|
$(stack_path)
|
||||||
, $(call ERROR,Unable to find a stack,$(stack_name),in dir,$(stack_dir))
|
, $(call ERROR,Unable to find a stack,$(stack_name),in dir,$(stack_dir))
|
||||||
))
|
))
|
||||||
endef
|
endef
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#shellcheck source=/dev/null disable=SC2046
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
# define MYOS path
|
||||||
|
MYOS="$(dirname "$(readlink "$0" || echo "$0")")"
|
||||||
|
|
||||||
|
# load system config
|
||||||
|
[ -r /etc/default/myos ] && . /etc/default/myos
|
||||||
|
|
||||||
|
# check myos requirements
|
||||||
|
[ -f "${MYOS:-.}/Makefile" ] || { echo 'Unable to find myos Makefile' >&2; exit 1; }
|
||||||
|
|
||||||
|
# call myos Makefile
|
||||||
|
IFS=$'\n'; exec env $(cat /etc/default/myos 2>/dev/null) MYOS=. WORKDIR="${PWD}" make -esC "${MYOS:-.}" "$@"
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
networks:
|
||||||
|
default:
|
||||||
|
name: ${DOCKER_NETWORK_DEFAULT:-_default}
|
||||||
|
private:
|
||||||
|
external: true
|
||||||
|
name: ${DOCKER_NETWORK_PRIVATE:-docker}
|
||||||
|
public:
|
||||||
|
external: true
|
||||||
|
name: ${DOCKER_NETWORK_PUBLIC:-localhost}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
version: '3.6'
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
backup:
|
||||||
|
driver: local
|
||||||
|
driver_opts:
|
||||||
|
device: /var/lib/backup
|
||||||
|
o: bind
|
||||||
|
type: none
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
version: '3.6'
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
dns:
|
||||||
|
driver: local
|
||||||
|
driver_opts:
|
||||||
|
device: /dns
|
||||||
|
o: bind
|
||||||
|
type: none
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
version: '3.6'
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
home:
|
||||||
|
driver: local
|
||||||
|
driver_opts:
|
||||||
|
device: /home
|
||||||
|
o: bind
|
||||||
|
type: none
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
version: '3.6'
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
log:
|
||||||
|
driver: local
|
||||||
|
driver_opts:
|
||||||
|
device: /var/log
|
||||||
|
o: bind
|
||||||
|
type: none
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
version: '3.6'
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
www:
|
||||||
|
driver: local
|
||||||
|
driver_opts:
|
||||||
|
device: /var/www
|
||||||
|
o: bind
|
||||||
|
type: none
|
||||||
Reference in New Issue
Block a user