Skip to content

Instantly share code, notes, and snippets.

@lbr77
Created August 10, 2022 14:29
Show Gist options
  • Save lbr77/18c9bb2198f3007ad13dfe2f4eca0a87 to your computer and use it in GitHub Desktop.
Save lbr77/18c9bb2198f3007ad13dfe2f4eca0a87 to your computer and use it in GitHub Desktop.
Scripts for Synology DS120j or similar machines to install docker
#!/usr/bin/env bash
# Description: Install docker-aarch64 for ds120j
# System Required: Synology
# Author: lbr77
# some scrpts from github.com/P3TERX
#
# MIT License
#
# Copyright (c) 2021-2022 lbr77 <https://stevelbr.top>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
FontColor_Red="\033[31m"
FontColor_Red_Bold="\033[1;31m"
FontColor_Green="\033[32m"
FontColor_Green_Bold="\033[1;32m"
FontColor_Yellow="\033[33m"
FontColor_Yellow_Bold="\033[1;33m"
FontColor_Purple="\033[35m"
FontColor_Purple_Bold="\033[1;35m"
FontColor_Suffix="\033[0m"
log() {
local LEVEL="$1"
local MSG="$2"
case "${LEVEL}" in
INFO)
local LEVEL="[${FontColor_Green}${LEVEL}${FontColor_Suffix}]"
local MSG="${LEVEL} ${MSG}"
;;
WARN)
local LEVEL="[${FontColor_Yellow}${LEVEL}${FontColor_Suffix}]"
local MSG="${LEVEL} ${MSG}"
;;
ERROR)
local LEVEL="[${FontColor_Red}${LEVEL}${FontColor_Suffix}]"
local MSG="${LEVEL} ${MSG}"
;;
*) ;;
esac
echo -e "${MSG}"
}
# pre installation check
# system
# if [[ $(uname -m) != aarch64 ]]; then
# log ERROR "Target CPU should be aarch64!"
# exit 1
# fi
# identify
# if [[ $(id -u) != 0 ]]; then
# log ERROR "This script must be run as root."
# exit 1
# fi
#toolchains
if [[ -z $(command -v wget) ]]; then
log ERROR "wget is not installed."
exit 1
fi
if [[ -z $(command -v curl) ]]; then
log ERROR "cURL is not installed."
exit 1
fi
docker_version=20.10.17
docker_arch=aarch64
docker_channel=stable
Install_Docker() {
log INFO "Downloading version: ${docker_version},arch: ${docker_arch},channel: ${docker_channel},from docker.com."
log INFO "Using Mirror: aliyun"
wget "https://mirrors.aliyun.com/docker-ce/linux/static/${docker_channel}/${docker_arch}/docker-${docker_version}.tgz" -O docker.tgz
log INFO "Download finished."
log INFO "Begin to unzip it."
tar xzvf docker.tgz
log INFO "Unzipping finished.\n Removing temp files."
rm docker.tgz
log INFO "Install Docker"
cp docker/* /usr/bin/
mkdir -p /etc/docker
log INFO "Creating configs..."
cat <<EOF >>/etc/docker/daemon.json
{
"storage-driver": "vfs",
"iptables": false,
"bridge": "none",
"registry-mirrors": ["http://f1361db2.m.daocloud.io"],
"data-root": "/docker"
}
EOF
log INFO "Creating daemonize files"
mkdir -p /volume1/@Docker/lib
mkdir /docker
cat <<EOF >> /volume1/@Docker/start.sh
#!/bin/sh
NAME=dockerd
DAEMON=/usr/bin/$NAME
PIDFILE=/var/run/$NAME.pid
DAEMON_ARGS=" --ipv6=false "
PATH=$PATH:/opt/sbin:/opt/bin:/opt/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
mount -o bind "/volume1/@Docker/lib" /docker
iptables -P FORWARD ACCEPT
/usr/bin/dockerd $DAEMON_ARGS
EOF
chmod +x /volume1/@Docker/start.sh
cat <<EOF >> /lib/systemd/system/docker.service
[Unit]
Description=Docker Application Container Engine
After=network-online.target
[Service]
User=root
WorkingDirectory=/docker
ExecStart=/volume1/@Docker/start.sh
Restart=on-failure
RestartSec=10
[Install]
WantedBy=multi-user.target
EOF
log INFO "Downloading Files from docker compose."
mkdir -p /usr/local/lib/docker/cli-plugins
VERSION=$(curl -sL https://api.github.com/repos/docker/compose/releases | jq -r ".[0].name")
log INFO "Docker Compose Version ${VERSION}"
wget "https://get.daocloud.io/docker/compose/releases/download/${VERSION}/docker-compose-linux-${docker_arch}" -O /usr/local/lib/docker/cli-plugins/docker-compose
chmod +x /usr/local/lib/docker/cli-plugins/docker-compose
log INFO "Finished installing Docker Compose."
systemctl daemon-reload
systemctl enable docker
systemctl start docker
log INFO "Finished installing Docker"
}
Install_Docker
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment