scripts: docker scripts (#26)

* dogo/doll

dogo supports zsh/bash/sh; doll is introduced to launch a new docker
container; update $SUDO in command.sh

* update ci

* fix regex

* dogo: enhance, support -[0-9]*

* dogo&doll: enhanced

* zshrc: sibd and sob
This commit is contained in:
Dict Xiong 2022-11-14 01:37:48 +08:00 committed by GitHub
parent 995899f3a3
commit 6e33fc0875
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 53 additions and 5 deletions

View File

@ -89,6 +89,8 @@ alias "se"='sudo -sE'
alias "pbd"='ping baidu.com'
alias "p114"='ping 114.114.114.114'
alias "p666"='ping6 2001:da8::666'
sibd() {ssh -p 12022 root@$1${1:+.}ibd.ink}
sob() {ssh -p 24022 root@$1${1:+.}ob.ac.cn}
case $(bash "$DOTFILES/tools/common.sh" get_os_type) in
macos ) alias l='ls -lAGh -D "%y-%m-%d %H:%M"' ;;
* ) alias l='ls -lAGh --time-style="+%y-%m-%d %H:%M"' ;;

View File

@ -3,8 +3,28 @@
THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
source "$THIS_DIR/../tools/common.sh"
if [[ -z "$1" || "$1" =~ "-h|--help" ]]; then
fmt_info "usage: dogo <container>"
DOCKER_FORMAT="{{.ID}} {{.Image}} {{.Names}}"
if [[ -z "$1" || "$1" =~ ^(-h|--help)$ ]]; then
fmt_info "usage: $0 <container> or -[0-9]*"
exit
elif [[ "$1" =~ ^-[0-9]*$ ]]; then
LAST="${1:1}"
if [[ "$LAST" == "0" ]]; then
# the latest running container
CONTAINER_META=($($SUDO docker container ls -l --filter "status=running" --format "$DOCKER_FORMAT"))
else
$SUDO docker exec -it $1 zsh
# the last nth container (all status)
CONTAINER_META=($($SUDO docker container ls -n ${LAST:-1} --format "$DOCKER_FORMAT" | tail -n 1))
fi
CONTAINER=${CONTAINER_META[0]}
else
CONTAINER_META="$1"
CONTAINER="$1"
fi
if [[ -z "$CONTAINER" ]]; then
fmt_error "container not found"
else
echo "--> ${CONTAINER_META[@]}"
$SUDO docker exec -it $CONTAINER sh -c 'if [ -x "$(command -v zsh)" ]; then echo "--> zsh"; zsh; elif [ -x "$(command -v bash)" ]; then echo "--> bash"; bash; else echo "--> sh"; sh; fi'
fi

25
scripts/doll Executable file
View File

@ -0,0 +1,25 @@
#!/bin/bash
THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
source "$THIS_DIR/../tools/common.sh"
DOCKER_FORMAT="{{.ID}} {{.Repository}}:{{.Tag}}"
if [[ -z "$1" || "$1" =~ ^(-h|--help)$ ]]; then
fmt_info "usage: $0 <image> or -[0-9]*"
exit
elif [[ "$1" =~ ^-[0-9]*$ ]]; then
LAST="${1:1}"
# the last nth image
IMAGE_META=($($SUDO docker image ls --format "$DOCKER_FORMAT" | head -n ${LAST:-1} | tail -n 1))
IMAGE=${IMAGE_META[0]}
else
IMAGE_META="$1"
IMAGE="$1"
fi
if [[ -z "$IMAGE" ]]; then
fmt_error "image not found"
else
echo "--> ${IMAGE_META[@]}"
echo $SUDO docker run -itd $IMAGE sh
fi

View File

@ -4,7 +4,7 @@ THIS_DIR_COMMON_SH=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
export DOTFILES=$( cd "$THIS_DIR_COMMON_SH/.." && pwd )
SUDO=''
if (( $EUID != 0 )); then
if [[ "$EUID" != "0" && -x $(command -v sudo) ]]; then
SUDO='sudo'
fi

View File

@ -13,7 +13,7 @@ set_mirror()
pacman_S()
{
pacman -Syu
pacman -S tmux git zsh curl vim wget base-devel mingw-w64-x86_64-toolchain make cmake gcc zip unzip python3 python3-pip
pacman -S tmux git zsh curl vim wget base-devel mingw-w64-x86_64-toolchain make cmake gcc zip unzip python3 python3-pip man-pages-posix
}
router()

View File

@ -20,6 +20,7 @@ dfs log 1
z ~
test ~ -ef "$(pwd)"
dogo
doll
dfs cd
tools/common.sh get_os_type
tools/common.sh get_linux_dist