Commit ba701c16 authored by AlmAck's avatar AlmAck
Browse files

initial version

parents
FROM scratch
MAINTAINER chakralinux <info@chakralinux.org>
ADD bootstraps/chakra-mini-bootstrap.tar.xz /
RUN echo 'Server = http://archlinux.puzzle.ch/kdemod/$repo/x86_64 ' >> /etc/pacman.d/mirrorlist
RUN pacman-key --init && pacman-key --populate archlinux
CMD ["/bin/bash"]
The MIT License (MIT)
Copyright (c) 2015 apporc
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.
Bootstrap a basic chakralinux docker container.
This container uses chakra-bootstrap.sh script to bootstrap basic chakralinux system. After that it just cleans up caches and non popular config files.
As a result, the container is very clean. However, advices needed.
References:
https://github.com/apporc/arch-bootstrap
https://raw.githubusercontent.com/yannayl/arch-bootstrap/master/arch-bootstrap.sh
#!/bin/bash
# build: Bootstrap a base Chakra Linux system.
set -e -u -o pipefail
SCRIPT=$(readlink -f "$0")
SCRIPT_PWD=$(dirname $SCRIPT)
RESULTPATH=${SCRIPT_PWD}/../
ARCH="x86_64"
REPO_URL="http://archlinux.puzzle.ch/kdemod"
DOWNLOAD_DIR="/tmp/bootstrap-packages"
ROOTFS=$(mktemp -d)
/usr/bin/mkdir -p "$ROOTFS"
# remove old archives
/usr/bin/rm -f ${RESULTPATH}/chakra-mini-bootstrap.tar.xz ${RESULTPATH}/chakra-mini-bootstrap.tar.xz.sha512sum
# bootstrap
${SCRIPT_PWD}/chakra-bootstrap.sh -a "${ARCH}" -r "${REPO_URL}" -d "${DOWNLOAD_DIR}" "${ROOTFS}"
cd "${ROOTFS}"
# clean up resolv.conf
/usr/bin/cp ${SCRIPT_PWD}/resolv.conf etc/resolv.conf
# use default mirrorlist for pacman
/usr/bin/cp ${SCRIPT_PWD}/mirrorlist etc/pacman.d/mirrorlist
# clean up package cache
/usr/bin/rm -rf var/cache/*
# create new archive
cd ${RESULTPATH}
/usr/bin/tar --create --xz --numeric-owner --xattrs --acls --directory=${ROOTFS} --file="chakra-mini-bootstrap.tar.xz" .
/usr/bin/sha512sum "chakra-mini-bootstrap.tar.xz" >| "chakra-mini-bootstrap.tar.xz.sha512sum"
# report result
echo "DOWNLOAD_DIR: $DOWNLOAD_DIR"
echo "ROOTFS: $ROOTFS"
echo "RESULTPATH: $RESULTPATH"
#!/bin/bash
#
# chakra-bootstrap Bootstrap a base Chakra Linux system using any GNU distribution.
#
# Dependencies: bash >= 4, coreutils, wget, sed, gawk, tar, gzip, chroot, xz.
# Project based on: https://github.com/tokland/arch-bootstrap
#
#
# Usage:
#
# # chakra-bootstrap destination
# # chakra-bootstrap -a x86_64 -r http://rsync.chakralinux.org/packages/ destination-64
#
# And then you can chroot to the destination directory (user: root, password: root):
#
# # chroot destination
set -e -u -o pipefail
# Packages needed by pacman (see get-pacman-dependencies.sh)
PACMAN_PACKAGES=(
acl attr bzip2 curl expat glibc gpgme libarchive nettle
libassuan libgpg-error libssh2 lzo2 openssl pacman pacman-mirrorlist xz zlib
krb5 e2fsprogs keyutils libidn gcc-libs lz4 icu
)
#
# acl attr bzip2 curl e2fsprogs expat glibc gpgme keyutils krb5 libarchive libassuan libgpg-error libssh2 lz4 lzo2 nettle openssl pacman xz zlib
# archlinux-keyring
BASIC_PACKAGES=(${PACMAN_PACKAGES[*]} filesystem)
EXTRA_PACKAGES=(coreutils bash grep gawk file tar systemd sed)
DEFAULT_REPO_URL="http://rsync.chakralinux.org/packages/"
stderr() {
echo "$@" >&2
}
debug() {
stderr "--- $@"
}
extract_href() {
sed -n '/<a / s/^.*<a [^>]*href="\([^\"]*\)".*$/\1/p'
}
fetch() {
curl -L -s "$@"
}
fetch_file() {
local FILEPATH=$1
shift
if [[ -e "$FILEPATH" ]]; then
curl -L -z "$FILEPATH" -o "$FILEPATH" "$@"
else
curl -L -o "$FILEPATH" "$@"
fi
}
uncompress() {
local FILEPATH=$1 DEST=$2
case "$FILEPATH" in
*.gz)
tar xzf "$FILEPATH" -C "$DEST";;
*.xz)
xz -dc "$FILEPATH" | tar x -C "$DEST";;
*)
debug "Error: unknown package format: $FILEPATH"
return 1;;
esac
}
###
get_default_repo() {
local ARCH=$1
echo $DEFAULT_REPO_URL
}
get_core_repo_url() {
local REPO_URL=$1 ARCH=$2
echo "${REPO_URL%/}/core/$ARCH"
}
get_template_repo_url() {
local REPO_URL=$1 ARCH=$2
echo "${REPO_URL%/}/\$repo/$ARCH"
}
configure_pacman() {
local DEST=$1 ARCH=$2
debug "configure DNS and pacman"
cp "/etc/resolv.conf" "$DEST/etc/resolv.conf"
SERVER=$(get_template_repo_url "$REPO_URL" "$ARCH")
# cleanup mirrorlist, use only the $SERVER
cat /dev/null > $DEST/etc/pacman.d/mirrorlist
#touch $DEST/etc/pacman.d/mirrorlist
echo "Server = $SERVER" >> "$DEST/etc/pacman.d/mirrorlist"
}
configure_minimal_system() {
local DEST=$1
mkdir -p "$DEST/dev"
sed -ie 's/^root:.*$/root:$1$GT9AUpJe$oXANVIjIzcnmOpY07iaGi\/:14657::::::/' $DEST/etc/shadow
touch "$DEST/etc/group"
echo "bootstrap" > "$DEST/etc/hostname"
test -e "$DEST/etc/mtab" || echo "rootfs / rootfs rw 0 0" > "$DEST/etc/mtab"
test -e "$DEST/dev/null" || mknod "$DEST/dev/null" c 1 3
test -e "$DEST/dev/random" || mknod -m 0644 "$DEST/dev/random" c 1 8
test -e "$DEST/dev/urandom" || mknod -m 0644 "$DEST/dev/urandom" c 1 9
sed -i "s/^[[:space:]]*\(CheckSpace\)/# \1/" "$DEST/etc/pacman.conf"
sed -i "s/^[[:space:]]*SigLevel[[:space:]]*=.*$/SigLevel = Never/" "$DEST/etc/pacman.conf"
#rankmirrors -n 3 -r core "$DEST/etc/pacman.d/mirrorlist" > "$DEST/etc/pacman.d/mirrorlist"
#cat $DEST/etc/pacman.d/mirrorlist
}
fetch_packages_list() {
local REPO=$1
debug "fetch packages list: $REPO/"
fetch "$REPO/" | extract_href | awk -F"/" '{print $NF}' | sort -rn ||
{ debug "Error: cannot fetch packages list: $REPO"; return 1; }
}
install_pacman_packages() {
local BASIC_PACKAGES=$1 DEST=$2 LIST=$3 DOWNLOAD_DIR=$4
debug "pacman package and dependencies: $BASIC_PACKAGES"
for PACKAGE in $BASIC_PACKAGES; do
local FILE=$(echo "$LIST" | grep -m1 "^$PACKAGE-[[:digit:]].*\(\.gz\|\.xz\)$")
test "$FILE" || { debug "Error: cannot find package: $PACKAGE"; return 1; }
local FILEPATH="$DOWNLOAD_DIR/$FILE"
debug "download package: $REPO/$FILE"
fetch_file "$FILEPATH" "$REPO/$FILE"
debug "uncompress package: $FILEPATH"
uncompress "$FILEPATH" "$DEST"
done
}
install_packages() {
local ARCH=$1 DEST=$2 PACKAGES=$3
debug "install packages: $PACKAGES"
LC_ALL=C chroot "$DEST" /usr/bin/pacman \
--noconfirm --arch $ARCH -Sy --force $PACKAGES
}
show_usage() {
stderr "Usage: $(basename "$0") [-q] [-a x86_64] [-r REPO_URL] [-d DOWNLOAD_DIR] DESTDIR"
}
main() {
# Process arguments and options
test $# -eq 0 && set -- "-h"
local ARCH=
local REPO_URL=
local DOWNLOAD_DIR=
local PRESERVE_DOWNLOAD_DIR=
while getopts "qa:r:d:h" ARG; do
case "$ARG" in
a) ARCH=$OPTARG;;
r) REPO_URL=$OPTARG;;
d) DOWNLOAD_DIR=$OPTARG
PRESERVE_DOWNLOAD_DIR=true;;
*) show_usage; return 1;;
esac
done
shift $(($OPTIND-1))
test $# -eq 1 || { show_usage; return 1; }
[[ -z "$ARCH" ]] && ARCH=$(uname -m)
[[ -z "$REPO_URL" ]] &&REPO_URL=$(get_default_repo "$ARCH")
local DEST=$1
local REPO=$(get_core_repo_url "$REPO_URL" "$ARCH")
[[ -z "$DOWNLOAD_DIR" ]] && DOWNLOAD_DIR=$(mktemp -d)
mkdir -p "$DOWNLOAD_DIR"
[[ -z "$PRESERVE_DOWNLOAD_DIR" ]] && trap "rm -rf '$DOWNLOAD_DIR'" KILL TERM EXIT
debug "destination directory: $DEST"
debug "core repository: $REPO"
debug "temporary directory: $DOWNLOAD_DIR"
# Fetch packages, install system and do a minimal configuration
mkdir -p "$DEST"
local LIST=$(fetch_packages_list $REPO)
install_pacman_packages "${BASIC_PACKAGES[*]}" "$DEST" "$LIST" "$DOWNLOAD_DIR"
configure_pacman "$DEST" "$ARCH"
configure_minimal_system "$DEST"
install_packages "$ARCH" "$DEST" "${BASIC_PACKAGES[*]} ${EXTRA_PACKAGES[*]}"
configure_pacman "$DEST" "$ARCH" # Pacman must be re-configured
[[ -z "$PRESERVE_DOWNLOAD_DIR" ]] && rm -rf "$DOWNLOAD_DIR"
debug "done"
}
main "$@"
# Chakra repository mirrorlist
# Australia
#Server = http://mirror.aarnet.edu.au/pub/chakra/$repo/x86_64
# Brazil
#Server = http://chakra.c3sl.ufpr.br/$repo/x86_64
# China
#Server = http://mirrors.ustc.edu.cn/chakra/$repo/x86_64
#Server = http://mirrors.tuna.tsinghua.edu.cn/chakra/$repo/x86_64
# Colombia
#Server = http://mirror.edatel.net.co/chakra/$repo/x86_64
# France
#Server = http://www-ftp.lip6.fr/pub/linux/distributions/chakra/$repo/x86_64
#Server = http://ftp.ciril.fr/pub/linux/chakra/$repo/x86_64
#Server = http://elgrande74.net/chakra/packages/$repo/x86_64
# Germany
#Server = http://ftp.halifax.rwth-aachen.de/chakra/$repo/x86_64
#Server = http://mirror.selfnet.de/chakra/$repo/x86_64
#Server = http://mirror.wh-stuttgart.net/chakra/$repo/x86_64
#Server = https://mirrors.cicku.me/chakra/$repo/x86_64
#Server = https://rsync.chakralinux.org/packages/$repo/x86_64
# Greece
#Server = http://ftp.cc.uoc.gr/mirrors/linux/chakra/$repo/x86_64
# Italy
#Server = http://chakra.mirror.garr.it/mirrors/chakra/$repo/x86_64
# Russia
#Server = http://mirror.yandex.ru/mirrors/chakra/$repo/x86_64
# Sweden
#Server = http://ftp.acc.umu.se/mirror/chakraos.org/packages/$repo/x86_64
# Switzerland
#Server = http://archlinux.puzzle.ch/kdemod/$repo/x86_64
# Taiwan
#Server = http://free.nchc.org.tw/chakra/packages/$repo/x86_64
#Server = http://ftp.yzu.edu.tw/Linux/chakra/$repo/x86_64
#Server = http://mirror.ossplanet.net/chakra/packages/$repo/x86_64
#Server = http://ftp.ubuntu-tw.org/mirror/chakra/packages/$repo/x86_64
# United States
#Server = http://chakra.hostingxtreme.com/$repo/x86_64
#Server = http://mirror.rit.edu/chakra/$repo/x86_64
#Server = http://mirror.dacentec.com/chakra/$repo/x86_64
#Server = http://mirror.atlanta.delimiter.com/pub/chakra/$repo/x86_64
#
# /etc/resolv.conf
#
#search <yourdomain.tld>
#nameserver <ip>
# End of file
#!/bin/bash
# build: Bootstrap a base Chakra Linux system container.
set -e -u -o pipefail
SCRIPT=$(readlink -f "$0")
PWD=$(dirname $SCRIPT)
# build bootstrap archive
${PWD}/bootstraps/scripts/build.sh
# build docker container
cd ${PWD}
docker build -t chakralinux/chakra-bootstrap .
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment