import files

This commit is contained in:
Yann Autissier
2021-02-09 17:05:00 +01:00
parent f5c4576411
commit 44a6d37ba5
425 changed files with 23195 additions and 0 deletions
+3
View File
@@ -0,0 +1,3 @@
hardstatus alwayslastline "%{= kw}[%{G}%H%{-}] \# %?%-Lw%?[%{G}%n%f %t%{-}]%?%+Lw%?%?%=%-17< [%{B}%l%{-}]"
defscrollback 1048576
shell -$SHELL
+34
View File
@@ -0,0 +1,34 @@
# this is aya's tmux configuration !
bind r source-file ~/.tmux.conf\; display-message "tmux.conf reloaded!"
bind R move-window -r
bind M-1 source ~/.tmux/sessions/aws-preprod
bind M-2 source ~/.tmux/sessions/aws-prod
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"
+3
View File
@@ -0,0 +1,3 @@
new-session -A -s aws-preprod
run-shell "ssh sshuser@ssh-bastion make list-nodes |sed '1d' |awk '$1 ~ /^enovasante.aws-eu-west-1.web.(preprod.[a-z]+-[0-9a-z]+|[a-z]+pp-[0-9a-z]+)$/' |while read host ip; do type=\${host#*web.}; type=\${type#*preprod.}; type=\${type#*preprod-}; num=\$(printf '%0d' \${ip}); num=\$(echo \${ip} | tr . '\n' | awk '{n = n*256 + $1} END{print n}'); tmux neww -t aws-preprod:\$num -n \$type '/bin/bash -cli \"force ssh -Aqt ssh-bastion ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no 'enovadmin@\$ip'\"'; done"
run-shell "ssh sshuser@ssh-bastion make list-nodes |sed '1d' |awk '$1 ~ /^1001pharmacies\.preprod\.[0-9a-z]+$/' |while read host ip; do type=\${host#*preprod.}; num=\$(printf '%0d' \${ip}); num=\$(echo \${ip} | tr . '\n' | awk '{n = n*256 + $1} END{print n}'); tmux neww -t aws-preprod:\$num -n \$type '/bin/bash -cli \"force ssh -Aqt ssh-bastion ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no 'root@\$ip'\"'; done"
+3
View File
@@ -0,0 +1,3 @@
new-session -A -s aws-prod
run-shell "ssh sshuser@ssh-bastion make list-nodes |sed '1d' |awk '$1 ~ /^1001pharmacies\.prod\.[0-9a-z]+$/' |while read host ip; do type=\${host#*prod.}; num=\$(printf '%0d' \${ip}); num=\$(echo \${ip} | tr . '\n' | awk '{n = n*256 + $1} END{print n}'); tmux neww -t aws-prod:\$num -n \$type '/bin/bash -cli \"force ssh -Aqt ssh-bastion ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no 'root@\$ip'\"'; done"
run-shell "ssh sshuser@ssh-bastion make list-nodes |sed '1d' |awk '$1 ~ /enovasante.aws-eu-west-1.web.[a-z]+[^pp]-[0-9a-z]+$/' |while read host ip; do type=\${host#*web.}; num=\$(printf '%0d' \${ip}); num=\$(echo \${ip} | tr . '\n' | awk '{n = n*256 + $1} END{print n}'); tmux neww -t aws-prod:\$num -n \$type '/bin/bash -cli \"force ssh -Aqt ssh-bastion ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no 'enovadmin@\$ip'\"'; done"
+282
View File
@@ -0,0 +1,282 @@
FROM ubuntu:18.04 as dist
LABEL maintainer 1001Pharmacies <technique+docker@1001pharmacies.com>
ARG DOCKER_BUILD_DIR
# https://github.com/theia-ide/theia-apps/blob/master/theia-full-docker/Dockerfile
ENV DEBIAN_FRONTEND noninteractive
#Common deps
RUN apt-get update && apt-get -y dist-upgrade && apt-get -y install curl xz-utils wget gpg
#Install node and yarn
#From: https://github.com/nodejs/docker-node/blob/6b8d86d6ad59e0d1e7a94cec2e909cad137a028f/8/Dockerfile
# gpg keys listed at https://github.com/nodejs/node#release-keys
RUN set -ex \
&& for key in \
4ED778F539E3634C779C87C6D7062848A1AB005C \
B9E2F5981AA6E0CD28160D9FF13993A75599653C \
94AE36675C464D64BAFA68DD7434390BDBE9B9C5 \
B9AE9905FFD7803F25714661B63B535A4C206CA9 \
77984A986EBC2AA786BC0F66B01FBB92821C587A \
71DCFD284A79C3B38668286BC97EC7A07EDE3FC1 \
FD3A5288F042B6850C66B31F09FE44734EB7990E \
8FCCA13FEF1D0C2E91008E09770F7A9A5AE15600 \
C4F0DFFF4E8C1A8236409D08E73BC641CC11F4C8 \
DD8F2338BAE7501E3DD5AC78C273792F7D83545D \
A48C2BEE680E841632CD4E44F07496B3EB3C1762 \
; do \
gpg --batch --keyserver ipv4.pool.sks-keyservers.net --recv-keys "$key" || \
gpg --batch --keyserver pool.sks-keyservers.net --recv-keys "$key" || \
gpg --batch --keyserver pgp.mit.edu --recv-keys "$key" || \
gpg --batch --keyserver keyserver.pgp.com --recv-keys "$key" || \
gpg --batch --keyserver ha.pool.sks-keyservers.net --recv-keys "$key" ; \
done
ENV NODE_VERSION 8.14.1
RUN ARCH= && dpkgArch="$(dpkg --print-architecture)" \
&& case "${dpkgArch##*-}" in \
amd64) ARCH='x64';; \
ppc64el) ARCH='ppc64le';; \
s390x) ARCH='s390x';; \
arm64) ARCH='arm64';; \
armhf) ARCH='armv7l';; \
i386) ARCH='x86';; \
*) echo "unsupported architecture"; exit 1 ;; \
esac \
&& curl -SLO "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-$ARCH.tar.xz" \
&& curl -SLO --compressed "https://nodejs.org/dist/v$NODE_VERSION/SHASUMS256.txt.asc" \
&& gpg --batch --decrypt --output SHASUMS256.txt SHASUMS256.txt.asc \
&& grep " node-v$NODE_VERSION-linux-$ARCH.tar.xz\$" SHASUMS256.txt | sha256sum -c - \
&& tar -xJf "node-v$NODE_VERSION-linux-$ARCH.tar.xz" -C /usr/local --strip-components=1 --no-same-owner \
&& rm "node-v$NODE_VERSION-linux-$ARCH.tar.xz" SHASUMS256.txt.asc SHASUMS256.txt \
&& ln -s /usr/local/bin/node /usr/local/bin/nodejs
ENV YARN_VERSION 1.13.0
RUN set -ex \
&& for key in \
6A010C5166006599AA17F08146C2130DFD2497F5 \
; do \
gpg --batch --keyserver ipv4.pool.sks-keyservers.net --recv-keys "$key" || \
gpg --batch --keyserver pool.sks-keyservers.net --recv-keys "$key" || \
gpg --batch --keyserver pgp.mit.edu --recv-keys "$key" || \
gpg --batch --keyserver keyserver.pgp.com --recv-keys "$key" || \
gpg --batch --keyserver ha.pool.sks-keyservers.net --recv-keys "$key" ; \
done \
&& curl -fSLO --compressed "https://yarnpkg.com/downloads/$YARN_VERSION/yarn-v$YARN_VERSION.tar.gz" \
&& curl -fSLO --compressed "https://yarnpkg.com/downloads/$YARN_VERSION/yarn-v$YARN_VERSION.tar.gz.asc" \
&& gpg --batch --verify yarn-v$YARN_VERSION.tar.gz.asc yarn-v$YARN_VERSION.tar.gz \
&& mkdir -p /opt/yarn \
&& tar -xzf yarn-v$YARN_VERSION.tar.gz -C /opt/yarn --strip-components=1 \
&& ln -s /opt/yarn/bin/yarn /usr/local/bin/yarn \
&& ln -s /opt/yarn/bin/yarn /usr/local/bin/yarnpkg \
&& rm yarn-v$YARN_VERSION.tar.gz.asc yarn-v$YARN_VERSION.tar.gz
#Developer tools
## Git and sudo (sudo needed for user override)
RUN apt-get -y install git sudo
##GO
ENV GO_VERSION 1.11.4
ENV GOPATH=/usr/local/go-packages
ENV GO_ROOT=/usr/local/go
ENV PATH $PATH:/usr/local/go/bin
ENV PATH $PATH:${GOPATH}/bin
RUN curl -sS https://storage.googleapis.com/golang/go$GO_VERSION.linux-amd64.tar.gz | tar -C /usr/local -xzf - && \
go get -u -v github.com/nsf/gocode && \
go get -u -v github.com/uudashr/gopkgs/cmd/gopkgs && \
go get -u -v github.com/ramya-rao-a/go-outline && \
go get -u -v github.com/acroca/go-symbols && \
go get -u -v golang.org/x/tools/cmd/guru && \
go get -u -v golang.org/x/tools/cmd/gorename && \
go get -u -v github.com/fatih/gomodifytags && \
go get -u -v github.com/haya14busa/goplay/cmd/goplay && \
go get -u -v github.com/josharian/impl && \
go get -u -v github.com/tylerb/gotype-live && \
go get -u -v github.com/rogpeppe/godef && \
go get -u -v golang.org/x/tools/cmd/godoc && \
go get -u -v github.com/zmb3/gogetdoc && \
go get -u -v golang.org/x/tools/cmd/goimports && \
go get -u -v sourcegraph.com/sqs/goreturns && \
go get -u -v github.com/golang/lint/golint && \
go get -u -v github.com/cweill/gotests/... && \
go get -u -v github.com/alecthomas/gometalinter && \
go get -u -v honnef.co/go/tools/... && \
go get -u -v github.com/sourcegraph/go-langserver && \
go get -u -v github.com/derekparker/delve/cmd/dlv && \
go get -u -v github.com/davidrjenni/reftools/cmd/fillstruct
#Java
RUN echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | /usr/bin/debconf-set-selections && \
apt-get -y install openjdk-8-jdk
#C/C++
# public LLVM PPA, development version of LLVM
RUN wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - && \
echo "deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic main" > /etc/apt/sources.list.d/llvm.list && \
apt-get update && apt-get install -y clang-tools-9 && \
ln -s /usr/bin/clangd-9 /usr/bin/clangd
#Python 2
RUN apt-get install -y python python-pip && \
pip install python-language-server
#PHP
RUN apt-get -y install php curl php-cli php-mbstring unzip
# https://getcomposer.org/doc/faqs/how-to-install-composer-programmatically.md
# https://linuxconfig.org/how-to-install-php-composer-on-debian-linux
RUN curl -s -o composer-setup.php https://getcomposer.org/installer \
&& php composer-setup.php --install-dir=/usr/local/bin --filename=composer \
&& rm composer-setup.php
#Ruby
RUN apt-get -y install ruby ruby-dev zlib1g-dev && \
gem install solargraph
#Theia
##Needed for node-gyp, nsfw build
RUN apt-get install -y python build-essential
#Docker
RUN apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common \
&& curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - \
&& add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" \
&& apt-get update \
&& apt-get -y install docker-ce docker-ce-cli containerd.io
## Common tools
RUN apt-get -y install nano screen tig tmux vim-nox zsh
FROM dist as local
ARG DOCKER_BUILD_DIR
ARG DOCKER_GID
ARG SHELL=/bin/bash
ARG UID
ARG GID
ARG SSH_BASTION_HOSTNAME
ARG SSH_BASTION_USERNAME
ARG SSH_PUBLIC_HOST_KEYS
ARG SSH_PRIVATE_IP_RANGE
ARG USER
ENV UID=${UID}
ENV GID=${GID:-${UID}}
ENV USER=${USER:-root}
LABEL com.1001pharmacies.uid=${UID}
LABEL com.1001pharmacies.gid=${GID}
LABEL com.1001pharmacies.user=${USER}
# 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 docker \
&& adduser $USER sudo \
&& echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
#ARG version=latest
#ADD https://raw.githubusercontent.com/theia-ide/theia-apps/master/theia-full-docker/$version.package.json /home/$USER/package.json
COPY ${DOCKER_BUILD_DIR}/package.json /home/$USER/package.json
RUN chown $USER /home/$USER/package.json
RUN echo -e "\n\
Host *\n\
LogLevel quiet\n\
Compression yes\n\
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}\n\
User ${SSH_BASTION_USERNAME}\n\
" >> /etc/ssh/ssh_config
# Custom prompt
COPY ${DOCKER_BUILD_DIR}/rc*.sh /etc/profile.d/
USER $USER
WORKDIR /home/$USER
# using "NODE_OPTIONS=..." to avoid out-of-memory problem in CI
ARG GITHUB_TOKEN
RUN yarn --cache-folder ./ycache && rm -rf ./ycache \
&& NODE_OPTIONS="--max_old_space_size=4096" yarn theia build
# git config
RUN mkdir -p ~/.ssh ~/.config/git \
&& ssh-keyscan -t rsa -H ${SSH_PUBLIC_HOST_KEYS} >> ~/.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/
COPY ${DOCKER_BUILD_DIR}/.tmux /home/$USER/.tmux/
ARG GIT_AUTHOR_NAME
ARG GIT_AUTHOR_EMAIL
ENV GIT_AUTHOR_NAME=${GIT_AUTHOR_NAME:-1001Pharmacies}
ENV GIT_AUTHOR_EMAIL=${GIT_AUTHOR_EMAIL:-technique+docker@1001pharmacies.com}
ENV GIT_COMMITTER_NAME=${GIT_AUTHOR_NAME}
ENV GIT_COMMITTER_EMAIL=${GIT_AUTHOR_EMAIL}
ENV SHELL=${SHELL}
ENV WORKSPACE_DIR=/Sources
ENTRYPOINT yarn theia start $WORKSPACE_DIR --hostname=0.0.0.0
EXPOSE 3000
FROM local as debug
ARG DOCKER_BUILD_DIR
FROM local as tests
ARG DOCKER_BUILD_DIR
FROM tests as preprod
ARG DOCKER_BUILD_DIR
FROM preprod as prod
ARG DOCKER_BUILD_DIR
+50
View File
@@ -0,0 +1,50 @@
{
"private": true,
"dependencies": {
"typescript": "latest",
"@theia/callhierarchy": "latest",
"@theia/core": "latest",
"@theia/cpp": "latest",
"@theia/editor": "latest",
"@theia/editorconfig": "latest",
"@theia/extension-manager": "latest",
"@theia/file-search": "latest",
"@theia/filesystem": "latest",
"@theia/git": "latest",
"@theia/go": "latest",
"@theia/java": "latest",
"@theia/json": "latest",
"@theia/keymaps": "latest",
"@theia/languages": "latest",
"@theia/markers": "latest",
"@theia/merge-conflicts": "latest",
"@theia/messages": "latest",
"@theia/metrics": "latest",
"@theia/mini-browser": "latest",
"@theia/monaco": "latest",
"@theia/navigator": "latest",
"@theia/outline-view": "latest",
"@theia/output": "latest",
"@theia/plantuml": "latest",
"@theia/plugin": "latest",
"@theia/plugin-ext": "latest",
"@theia/plugin-ext-vscode": "latest",
"@theia/preferences": "latest",
"@theia/preview": "latest",
"@theia/process": "latest",
"@theia/python": "latest",
"@theia/rust": "latest",
"@theia/search-in-workspace": "latest",
"@theia/task": "latest",
"@theia/terminal": "latest",
"@theia/textmate-grammars": "latest",
"@theia/typescript": "latest",
"@theia/userstorage": "latest",
"@theia/variable-resolver": "latest",
"@theia/workspace": "latest",
"theia-yang-extension": "latest"
},
"devDependencies": {
"@theia/cli": "latest"
}
}
+56
View File
@@ -0,0 +1,56 @@
{
"private": true,
"dependencies": {
"typescript": "latest",
"@theia/callhierarchy": "next",
"@theia/core": "next",
"@theia/cpp": "next",
"@theia/docker": "next",
"@theia/editor": "next",
"@theia/editorconfig": "next",
"@theia/editor-preview": "next",
"@theia/extension-manager": "next",
"@theia/file-search": "next",
"@theia/filesystem": "next",
"@theia/git": "next",
"@theia/go": "next",
"@theia/getting-started": "next",
"@theia/java": "next",
"@theia/json": "next",
"@theia/keymaps": "next",
"@theia/languages": "next",
"@theia/markers": "next",
"@theia/merge-conflicts": "next",
"@theia/messages": "next",
"@theia/metrics": "next",
"@theia/mini-browser": "next",
"@theia/monaco": "next",
"@theia/navigator": "next",
"@theia/outline-view": "next",
"@theia/php": "next",
"@theia/output": "next",
"@theia/plantuml": "next",
"@theia/plugin": "next",
"@theia/plugin-ext": "next",
"@theia/plugin-ext-vscode": "next",
"@theia/preferences": "next",
"@theia/preview": "next",
"@theia/process": "next",
"@theia/python": "next",
"@theia/ruby": "next",
"@theia/rust": "next",
"@theia/search-in-workspace": "next",
"@theia/task": "next",
"@theia/terminal": "next",
"@theia/textmate-grammars": "next",
"@theia/tslint": "next",
"@theia/typescript": "next",
"@theia/userstorage": "next",
"@theia/variable-resolver": "next",
"@theia/workspace": "next",
"theia-yang-extension": "next"
},
"devDependencies": {
"@theia/cli": "next"
}
}
+57
View File
@@ -0,0 +1,57 @@
{
"private": true,
"dependencies": {
"typescript": "latest",
"@theia/callhierarchy": "next",
"@theia/core": "next",
"@theia/cpp": "next",
"@theia/docker": "next",
"@theia/editor": "next",
"@theia/editorconfig": "next",
"@theia/editor-preview": "next",
"@theia/extension-manager": "next",
"@theia/file-search": "next",
"@theia/filesystem": "next",
"@theia/git": "next",
"@theia/go": "next",
"@theia/getting-started": "next",
"@theia/java": "next",
"@theia/json": "next",
"@theia/keymaps": "next",
"@theia/languages": "next",
"@theia/markers": "next",
"@theia/merge-conflicts": "next",
"@theia/messages": "next",
"@theia/metrics": "next",
"@theia/mini-browser": "next",
"@theia/monaco": "next",
"@theia/navigator": "next",
"@theia/outline-view": "next",
"@theia/php": "next",
"@theia/output": "next",
"@theia/plantuml": "next",
"@theia/plugin": "next",
"@theia/plugin-ext": "next",
"@theia/plugin-ext-vscode": "next",
"@theia/preferences": "next",
"@theia/preview": "next",
"@theia/process": "next",
"@theia/python": "next",
"@theia/ruby": "next",
"@theia/rust": "next",
"@theia/search-in-workspace": "next",
"@theia/task": "next",
"@theia/terminal": "next",
"@theia/textmate-grammars": "next",
"@theia/tslint": "next",
"@theia/typescript": "next",
"@theia/userstorage": "next",
"@theia/variable-resolver": "next",
"@theia/workspace": "next",
"@theia/yaml": "next",
"theia-yang-extension": "next"
},
"devDependencies": {
"@theia/cli": "next"
}
}
+39
View File
@@ -0,0 +1,39 @@
# verify that default functions are loaded
type force >/dev/null 2>&1 || . /etc/profile.d/rc_functions.sh 2>/dev/null
# test current shell flags
case $- in
# if we are in an interactive shell
*i*)
# load user defined stuffs from ~/.rc.d
for user_func in "${HOME}"/.rc.d/*; do
# read files only
[ -f "${user_func}" ] && func_name=$(basename "${user_func}") || continue
func_args=$(cat "${user_func}")
# 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 user_func file
[ -n "${func_name}" ] && ${func_name} ${func_args} 2>/dev/null
done
# load user defined stuffs from RC_* env vars
IFS=$'\n'; for func_line in $(env 2>/dev/null |awk '$0 ~ /^RC_/ {print tolower(substr($0,4))}'); do
func_name="${func_line%%=*}"
func_args="${func_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
[ -n "${func_name}" ] && ${func_name} ${func_args} 2>/dev/null
done
unset IFS
;;
esac
+124
View File
@@ -0,0 +1,124 @@
# force a command to run and restart it when it exits
force () {
PS_X_FIELD=1
if [ $# -gt 0 ]; then
# awk expression to match $@
while true; do
[ $(ps wwx -o args |awk '
BEGIN {nargs=split("'"$*"'",args)}
$field == args[1] {
matched=1;
for (i=1;i<=NF-field;i++) {
if ($(i+field) == args[i+1]) {matched++}
}
if (matched == nargs) {found++}
}
END {print found+0}' field="${PS_X_FIELD}") -eq 0 ] \
&& "$@" || sleep 1;
done
fi
}
# start an ssh agent and add any private key in ~/.ssh
ssh_agent () {
command -v ssh-agent >/dev/null 2>&1 && command -v ssh-add >/dev/null 2>&1 || return
SSH_AGENT_DIR="/tmp/ssh-$(id -u)"
SSH_AGENT_SOCK="${SSH_AGENT_DIR}/agent@$(hostname |sed 's/\..*//')"
[ -z "${SSH_AUTH_SOCK}" ] \
&& { [ -d "${SSH_AGENT_DIR}" ] || { mkdir "${SSH_AGENT_DIR}" 2>/dev/null && chmod 0700 "${SSH_AGENT_DIR}"; } } \
&& [ $(ps wwx -o args |awk '$1 == "ssh-agent" && $3 == "'"${SSH_AGENT_SOCK}"'"' |wc -l) -eq 0 ] \
&& rm -f "${SSH_AGENT_SOCK}" \
&& ssh-agent -a "${SSH_AGENT_SOCK}" >/dev/null 2>&1
export SSH_AUTH_SOCK="${SSH_AUTH_SOCK:-${SSH_AGENT_SOCK}}"
(echo "${HOME}"/.ssh/id_rsa; grep -l 'PRIVATE KEY' "${HOME}"/.ssh/* |grep -vE "^${HOME}/.ssh/id_rsa$") |while read -r file; do
[ -r "${file}" ] && [ -z "$(ssh-add -l |awk '{print $3}' |grep -E "^${file}$")" ] && ssh-add "${file}"
done
unset SSH_AGENT_DIR SSH_AGENT_SOCK
}
# attach an existing screen or create a new one
attach_screen () {
command -v screen >/dev/null 2>&1 || return
if [ -z "${STY}" ]; then
# attach screen in tmux window 0
[ -n "${TMUX}" ] && [ "$(tmux list-window 2>/dev/null |awk '$NF == "(active)" {print $1}' |sed 's/:$//')" != "0" ] && return
/bin/echo -n 'Attaching screen.' && sleep 1 && /bin/echo -n '.' && sleep 1 && /bin/echo -n '.' && sleep 1 && screen -xRR -S "$(id -nu)" 2>/dev/null
fi
}
# attach an existing tmux or create a new one
attach_tmux () {
command -v tmux >/dev/null 2>&1 || return
SESSION_NAME="$(id -nu)@$(hostname |sed 's/\..*//')"
if [ -z "${TMUX}" ]; then
/bin/echo -n 'Attaching tmux.' && sleep 1 && /bin/echo -n '.' && sleep 1 && /bin/echo -n '.' && sleep 1 && tmux -L"${SESSION_NAME}" -q has-session >/dev/null 2>&1 && tmux -L"${SESSION_NAME}" attach-session -d || tmux -L"${SESSION_NAME}" new-session -s"${SESSION_NAME}"
fi
}
# echo the "number of running processes"/"total number of processes"/"number of processes in D-state"
process_count () {
ps ax -o stat 2>/dev/null |awk '$1 ~ /R/ {process_running++}; $1 ~ /D/ {process_dstate++}; END {print process_running+0"/"NR-1"/"process_dstate+0}'
}
# echo the "number of distinct logged in users"/"number of distinct users running processes"/"number of logged in users"
user_count () {
ps ax -o user,tty,comm 2>/dev/null |awk '$2 !~ /^\?/ && $3 !~ /getty$/ {logged[$1]++; tty[$2]++}; {user[$1]++}; END {for (ul in logged) {sl = sl" "ul;}; users_logged=split(sl,a," ")-1; for (uu in user) {su = su" "uu;}; users_user=split(su,a," ")-1; for (ut in tty) {st = st" "ut;}; users_tty=split(st,a," ")-1; print users_logged"/"users_user"/"users_tty}'
}
# echo the load average
load_average () {
awk '{print $1}' /proc/loadavg 2>/dev/null || uptime 2>/dev/null |awk '{print $(NF-2)}'
}
# export PS1
custom_ps1 () {
case "$0" in
*ash)
local DGRAY="\[\033[1;30m\]"
local RED="\[\033[01;31m\]"
local GREEN="\[\033[01;32m\]"
local BROWN="\[\033[0;33m\]"
local YELLOW="\[\033[01;33m\]"
local BLUE="\[\033[01;34m\]"
local CYAN="\[\033[0;36m\]"
local GRAY="\[\033[0;37m\]"
local NC="\[\033[0m\]"
;;
*)
;;
esac
local COLOR="\$([ \"\$(id -u)\" = 0 ] && echo \"${RED}\" || echo \"${BROWN}\")"
local COUNT="${DGRAY}[${BLUE}\$(user_count 2>/dev/null)${DGRAY}|${BLUE}\$(process_count 2>/dev/null)${DGRAY}|${BLUE}\$(load_average 2>/dev/null)${DGRAY}]"
local END="\$([ \"\$(id -u)\" = 0 ] && echo \"#\" || echo \"\$\")"
local HOSTNAME="\$(hostname |sed 's/\..*//')"
type __git_ps1 >/dev/null 2>&1 \
&& local GIT="\$(__git_ps1 2>/dev/null \" (%s)\")" \
|| local GIT="\$(BRANCH=\$(git rev-parse --abbrev-ref HEAD 2>/dev/null); [ -n \"\${BRANCH}\" ] && echo \" (\${BRANCH})\")"
local USER="\$(id -nu)"
local WORKDIR="\$(pwd |sed 's|^'\${HOME}'\(/.*\)*$|~\1|')"
export PS1="${COUNT}${COLOR}${USER}${DGRAY}@${CYAN}${HOSTNAME}${DGRAY}:${GRAY}${WORKDIR}${CYAN}${GIT}${DGRAY}${END}${NC} "
}
# export PROMPT_COMMAND
custom_prompt () {
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
[ -n "${STY}" ] \
&& export PROMPT_COMMAND='printf "${ESCAPE_CODE_DCS:-\033]0;}%s${ESCAPE_CODE_ST:-\007}" "${PWD##*/}"' \
|| export PROMPT_COMMAND='printf "${ESCAPE_CODE_DCS:-\033]0;}%s@%s:%s${ESCAPE_CODE_ST:-\007}" "${USER}" "${HOSTNAME%%.*}" "${PWD##*/}"'
}