Last active
January 11, 2019 12:17
-
-
Save jhsea3do/5bcc7e09b01a0b7ed1139773981a603d to your computer and use it in GitHub Desktop.
docker binary tar package setup script, support suse, centos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
FILE_DIR=${FILE_DIR:-"/tmp/docker"} | |
LOCL_DIR=${LOCL_DIR:-"/usr/local"} | |
INST_DIR=${INST_DIR:-"/home/docker"} | |
INST_GRP=${INST_GRP:-"docker"} | |
INST_GID=${INST_GID:-"2376"} | |
INST_VER=${INST_VER:-"18.09.1"} | |
INST_NET=${INST_NET:-"172.17.0.1/16"} | |
INST_SILENT=0 | |
function load_cfg { | |
mkdir -p $FILE_DIR | |
[ -f "$FILE_DIR/install.cfg" ] \ | |
&& . "$FILE_DIR/install.cfg" | |
} | |
function inst_file { | |
ver=${1:-"$INST_VER"} | |
echo "docker-${ver}.tgz" | |
} | |
function inst_file_url { | |
#site="http://download.docker.com" | |
#ctx="/linux/static/stable/x86_64" | |
site="http://javaws.com" | |
ctx="/data" | |
ver=${1:-"$INST_VER"} | |
echo "$site$ctx/$(inst_file $@)" | |
} | |
function inst_dl { | |
[ -x "/usr/bin/wget" ] && inst_dl_wget $@ && return | |
[ -x "/usr/bin/curl" ] && inst_dl_curl $@ && return | |
} | |
function inst_dl_wget { | |
wget -O "$FILE_DIR/$(inst_file $@)" \ | |
"$(inst_file_url $@)" | |
} | |
function inst_dl_curl { | |
curl -o "$FILE_DIR/$(inst_file $@)" \ | |
"$(inst_file_url $@)" | |
} | |
function inst_prepare { | |
ver=${1:-"$INST_VER"} | |
inst_log "# prepare $FILE_DIR/$(inst_file $ver)" | |
[ ! -f "$FILE_DIR/$(inst_file $ver)" ] \ | |
&& inst_dl $ver; | |
# ls -la "$FILE_DIR" | |
} | |
function inst_docker_post { | |
[ -f "/etc/default/docker" ] \ | |
&& [ ! -f "/etc/default/docker.backup" ] \ | |
&& cp "/etc/default/docker" \ | |
"/etc/default/docker.backup" | |
inst_log "# backup and create profile /etc/default/docker " | |
cat >/etc/default/docker<<EOF | |
DOCKERD=$LOCL_DIR/bin/dockerd | |
DOCKER_OPTS=" --storage-driver=vfs \ | |
--data-root $INST_DIR/var/lib/docker \ | |
--bip=$INST_NET \ | |
-H 0.0.0.0:2376 -H unix:///var/run/docker.sock \ | |
" | |
EOF | |
inst_log "# create service control file /etc/systemd/system/docker.service" | |
cat >/etc/systemd/system/docker.service<<EOF | |
[Unit] | |
Description=Docker Application Container Engine | |
Documentation=https://docs.docker.com | |
After=network-online.target | |
Wants=network-online.target | |
[Service] | |
Type=notify | |
# the default is not to use systemd for cgroups because the delegate issues still | |
# exists and systemd currently does not support the cgroup feature set required | |
# for containers run by docker | |
EnvironmentFile=-/etc/default/%p | |
ExecStart=/usr/local/bin/dockerd \$DOCKER_OPTS | |
ExecReload=/bin/kill -s HUP \$MAINPID | |
# Having non-zero Limit*s causes performance problems due to accounting overhead | |
# in the kernel. We recommend using cgroups to do container-local accounting. | |
LimitNOFILE=infinity | |
LimitNPROC=infinity | |
LimitCORE=infinity | |
# Uncomment TasksMax if your systemd version supports it. | |
# Only systemd 226 and above support this version. | |
#TasksMax=infinity | |
TimeoutStartSec=0 | |
# set delegate yes so that systemd does not reset the cgroups of docker containers | |
Delegate=yes | |
# kill only the docker process, not all processes in the cgroup | |
KillMode=process | |
# restart the docker process if it exits prematurely | |
Restart=on-failure | |
StartLimitBurst=3 | |
StartLimitInterval=60s | |
[Install] | |
WantedBy=multi-user.target | |
EOF | |
} | |
function inst_docker_pre { | |
grp_exist=$(cat /etc/group|grep "$INST_GRP"|wc -l) | |
if [ $grp_exist -lt 1 ]; then | |
inst_log "# add group $INST_GRP ($INST_GID)" | |
groupadd -g $INST_GID $INST_GRP | |
fi | |
mkdir -p "$INST_DIR/bin" | |
rm -rf "$LOCL_DIR/bin/"docker* | |
} | |
function inst_docker { | |
ver=${1:-"$INST_VER"} | |
inst_docker_pre | |
tar xzvf "$FILE_DIR/$(inst_file $ver)" \ | |
-C $INST_DIR/bin --strip 1 | |
#ln -s "$INST_DIR/bin/"docker* "$LOCL_DIR/bin/" | |
cp -rf "$INST_DIR/bin/"* "$LOCL_DIR/bin/" | |
inst_docker_post | |
} | |
function inst_log { | |
[ $INST_SILENT -eq 0 ] \ | |
&& echo $@ | |
} | |
function chck_running { | |
is_run=$(ps -ef |grep dockerd|grep -v 'grep'|wc -l) | |
echo $is_run | |
} | |
function install { | |
load_cfg | |
# printenv | |
[ $(chck_running) -gt 0 ] && inst_log "# docker is running" && exit 1 | |
inst_prepare | |
inst_docker | |
} | |
function startsvc { | |
systemctl start docker.service | |
} | |
function stopsvc { | |
systemctl stop docker.service | |
} | |
function statussvc { | |
ps -ef|grep dockerd|grep -v 'grep' | |
systemctl status docker.service | |
} | |
function killsvc { | |
PID=$(ps -ef|grep dockerd|grep -v 'grep'|awk '{print $2}') | |
[ ! -z $PID ] \ | |
&& inst_log "# Please kill dockerd process ($PID): kill -s 9 $PID " | |
} | |
function remove { | |
CL_0FF='\033[0;31m' | |
CL_FFF='\033[0m' | |
CL_GRN='\033[0;32m' | |
CL_BLU='\033[0;34m' | |
echo -e "Please check status and stop dockerd at first. | |
Then remove files in ${CL_BLU}$INST_DIR${CL_FFF}, | |
And service control file of ${CL_GRN}/etc/systemd/system/docker.service${CL_FFF}, | |
And profile of ${CL_0FF}/etc/default/docker${CL_FFF}. | |
" | |
} | |
function helpme { | |
echo "Usage: $0 [OPTION]... | |
Please use following options: | |
help - Show this help | |
install - Install docker as service | |
remove - Remove docker | |
start - Start docker service | |
stop - Stop docker service | |
kill - Kill dockerd process, if dockerd not run as service | |
status - Check docker service status | |
" | |
} | |
function main { | |
opt=${1:-"help"} | |
shift | |
[ "help" = "$opt" ] && helpme $@ | |
[ "install" = "$opt" ] && install $@ | |
[ "remove" = "$opt" ] && remove $@ | |
[ "start" = "$opt" ] && startsvc $@ | |
[ "stop" = "$opt" ] && stopsvc $@ | |
[ "kill" = "$opt" ] && killsvc $@ | |
[ "status" = "$opt" ] && statussvc $@ | |
} | |
main $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
FILE_DIR=${FILE_DIR:-"/tmp/docker"} | |
LOCL_DIR=${LOCL_DIR:-"/usr/local"} | |
INST_DIR=${INST_DIR:-"/home/docker"} | |
INST_GRP=${INST_GRP:-"docker"} | |
INST_GID=${INST_GID:-"2376"} | |
INST_VER=${INST_VER:-"18.06.0-ce"} | |
INST_NET=${INST_NET:-"172.17.0.1/16"} | |
INST_SILENT=0 | |
function load_cfg { | |
mkdir -p $FILE_DIR | |
[ -f "$FILE_DIR/install.cfg" ] \ | |
&& . "$FILE_DIR/install.cfg" | |
} | |
function inst_file { | |
ver=${1:-"$INST_VER"} | |
echo "docker-${ver}.tgz" | |
} | |
function inst_file_url { | |
site="http://download.docker.com" | |
ctx="/linux/static/stable/x86_64" | |
ver=${1:-"$INST_VER"} | |
echo "$site$ctx/$(inst_file $@)" | |
} | |
function inst_dl { | |
[ -x "/usr/bin/wget" ] && inst_dl_wget $@ && return | |
[ -x "/usr/bin/curl" ] && inst_dl_curl $@ && return | |
} | |
function inst_dl_wget { | |
wget -O "$FILE_DIR/$(inst_file $@)" \ | |
"$(inst_file_url $@)" | |
} | |
function inst_dl_curl { | |
curl -o "$FILE_DIR/$(inst_file $@)" \ | |
"$(inst_file_url $@)" | |
} | |
function inst_prepare { | |
ver=${1:-"$INST_VER"} | |
inst_log "# prepare $FILE_DIR/$(inst_file $ver)" | |
[ ! -f "$FILE_DIR/$(inst_file $ver)" ] \ | |
&& inst_dl $ver; | |
# ls -la "$FILE_DIR" | |
} | |
function inst_docker_post { | |
[ -f "/etc/default/docker" ] \ | |
&& [ ! -f "/etc/default/docker.backup" ] \ | |
&& cp "/etc/default/docker" \ | |
"/etc/default/docker.backup" | |
inst_log "# backup and create profile /etc/default/docker " | |
cat >/etc/default/docker<<EOF | |
DOCKERD=$LOCL_DIR/bin/dockerd | |
DOCKER_OPTS=" --storage-driver=vfs \ | |
--data-root $INST_DIR/var/lib/docker \ | |
--bip=$INST_NET \ | |
-H 0.0.0.0:2376 -H unix:///var/run/docker.sock \ | |
" | |
EOF | |
inst_log "# create service control file /etc/systemd/system/docker.service" | |
cat >/etc/systemd/system/docker.service<<EOF | |
[Unit] | |
Description=Docker Application Container Engine | |
Documentation=https://docs.docker.com | |
After=network-online.target | |
Wants=network-online.target | |
[Service] | |
Type=notify | |
# the default is not to use systemd for cgroups because the delegate issues still | |
# exists and systemd currently does not support the cgroup feature set required | |
# for containers run by docker | |
EnvironmentFile=-/etc/default/%p | |
ExecStart=/usr/local/bin/dockerd \$DOCKER_OPTS | |
ExecReload=/bin/kill -s HUP \$MAINPID | |
# Having non-zero Limit*s causes performance problems due to accounting overhead | |
# in the kernel. We recommend using cgroups to do container-local accounting. | |
LimitNOFILE=infinity | |
LimitNPROC=infinity | |
LimitCORE=infinity | |
# Uncomment TasksMax if your systemd version supports it. | |
# Only systemd 226 and above support this version. | |
#TasksMax=infinity | |
TimeoutStartSec=0 | |
# set delegate yes so that systemd does not reset the cgroups of docker containers | |
Delegate=yes | |
# kill only the docker process, not all processes in the cgroup | |
KillMode=process | |
# restart the docker process if it exits prematurely | |
Restart=on-failure | |
StartLimitBurst=3 | |
StartLimitInterval=60s | |
[Install] | |
WantedBy=multi-user.target | |
EOF | |
} | |
function inst_docker_pre { | |
grp_exist=$(cat /etc/group|grep "$INST_GRP"|wc -l) | |
if [ $grp_exist -lt 1 ]; then | |
inst_log "# add group $INST_GRP ($INST_GID)" | |
groupadd -g $INST_GID $INST_GRP | |
fi | |
mkdir -p "$INST_DIR/bin" | |
rm -rf "$LOCL_DIR/bin/"docker* | |
} | |
function inst_docker { | |
ver=${1:-"$INST_VER"} | |
inst_docker_pre | |
tar xzvf "$FILE_DIR/$(inst_file $ver)" \ | |
-C $INST_DIR/bin --strip 1 | |
ln -s "$INST_DIR/bin/"docker* "$LOCL_DIR/bin/" | |
inst_docker_post | |
} | |
function inst_log { | |
[ $INST_SILENT -eq 0 ] \ | |
&& echo $@ | |
} | |
function chck_running { | |
is_run=$(ps -ef |grep dockerd|grep -v 'grep'|wc -l) | |
echo $is_run | |
} | |
function install { | |
load_cfg | |
# printenv | |
[ $(chck_running) -gt 0 ] && inst_log "# docker is running" && exit 1 | |
inst_prepare | |
inst_docker | |
} | |
function startsvc { | |
systemctl start docker.service | |
} | |
function stopsvc { | |
systemctl stop docker.service | |
} | |
function statussvc { | |
ps -ef|grep dockerd|grep -v 'grep' | |
systemctl status docker.service | |
} | |
function killsvc { | |
PID=$(ps -ef|grep dockerd|grep -v 'grep'|awk '{print $2}') | |
[ ! -z $PID ] \ | |
&& inst_log "# Please kill dockerd process ($PID): kill -s 9 $PID " | |
} | |
function remove { | |
CL_0FF='\033[0;31m' | |
CL_FFF='\033[0m' | |
CL_GRN='\033[0;32m' | |
CL_BLU='\033[0;34m' | |
echo -e "Please check status and stop dockerd at first. | |
Then remove files in ${CL_BLU}$INST_DIR${CL_FFF}, | |
And service control file of ${CL_GRN}/etc/systemd/system/docker.service${CL_FFF}, | |
And profile of ${CL_0FF}/etc/default/docker${CL_FFF}. | |
" | |
} | |
function helpme { | |
echo "Usage: $0 [OPTION]... | |
Please use following options: | |
help - Show this help | |
install - Install docker as service | |
remove - Remove docker | |
start - Start docker service | |
stop - Stop docker service | |
kill - Kill dockerd process, if dockerd not run as service | |
status - Check docker service status | |
" | |
} | |
function main { | |
opt=${1:-"help"} | |
shift | |
[ "help" = "$opt" ] && helpme $@ | |
[ "install" = "$opt" ] && install $@ | |
[ "remove" = "$opt" ] && remove $@ | |
[ "start" = "$opt" ] && startsvc $@ | |
[ "stop" = "$opt" ] && stopsvc $@ | |
[ "kill" = "$opt" ] && killsvc $@ | |
[ "status" = "$opt" ] && statussvc $@ | |
} | |
main $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
SSHD_CONF=/etc/ssh/sshd_config | |
PASS_FLAG=$(cat $SSHD_CONF |grep ^PasswordAuthentication|awk '{print $2}') | |
CL_0FF='\033[0;31m' | |
CL_FFF='\033[0m' | |
CL_GRN='\033[0;32m' | |
CL_BLU='\033[0;34m' | |
echo -e "--------------------------------------------------------------------------------------- | |
${CL_FFF}Please notice current $SSHD_CONF settings : ${CL_BLU} | |
$(cat $SSHD_CONF |grep ^PasswordAuthentication)${CL_FFF} | |
" | |
[ 'yes' = "$PASS_FLAG" ] && exit 0 | |
echo -e "--------------------------------------------------------------------------------------- | |
${CL_FFF}You can run following command reset it: ${CL_FFF} | |
" | |
echo -e "${CL_0FF}# unleash password login: ${CL_GRN}" | |
echo sed -i \'s/^PasswordAuthentication\ no/PasswordAuthentication yes/g\' $SSHD_CONF | |
echo | |
echo -e "${CL_0FF}# restart opensshd service: ${CL_GRN}" | |
echo systemctl restart sshd | |
echo -e "${CL_FFF}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment