Skip to content

Instantly share code, notes, and snippets.

@maxux
Last active June 12, 2020 01:12
Show Gist options
  • Save maxux/828340c6c194d884b503f8b0394f8419 to your computer and use it in GitHub Desktop.
Save maxux/828340c6c194d884b503f8b0394f8419 to your computer and use it in GitHub Desktop.
#!/bin/bash
settings() {
rootdir="/export"
excludes="/dev /proc /sys /corex ${rootdir}"
ZFLIST_MNT="${rootdir}/flist"
ZFLIST_HUB="https://playground.hub.grid.tf"
# ZFLIST_BACKEND='{"host": "playground.hub.grid.tf", "port": 9910}'
ZFLIST_HUB_TOKEN=kiUTd9jRjgt7QB6lRh2bcpNiC2UqvTLI
}
initialize() {
mkdir -p "${rootdir}"
}
zflist() {
wget https://github.com/threefoldtech/corex/releases/download/2.1.1/zflist-2.1.1-linux-amd64 -O ${rootdir}/zflist
chmod +x ${rootdir}/zflist
}
prepare() {
# closing any potential existing db
# and creating a new one
"${rootdir}/zflist" close
"${rootdir}/zflist" init
}
packroot() {
# pack root filesystem and exclude
# local temporary directories or system directories
for entry in /*; do
if [[ " ${excludes[@]} " =~ " ${entry} " ]]; then
# skip excluded directory
continue
fi
if [ -d "${entry}" ]; then
echo "Adding directory: ${entry}"
"${rootdir}/zflist" mkdir "${entry}"
if [ -z "$(ls -A ${entry})" ]; then
# empty directory, skipping content
continue
fi
"${rootdir}/zflist" prefetch "${entry}"
"${rootdir}/zflist" putdir "${entry}" "${entry}"
else
echo "Adding file: ${entry}"
"${rootdir}/zflist" put ${entry} /
fi
done
}
commit() {
# commit flist
"${rootdir}/zflist" commit "${rootdir}/export.flist"
}
settings
initialize
zflist
prepare
packroot
commit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment