186 lines
4.6 KiB
Bash
Executable File
186 lines
4.6 KiB
Bash
Executable File
#!/bin/sh
|
|
# glacier-mkimg - Generate a root filesystem image
|
|
#
|
|
# This file is part of Glacier.
|
|
#
|
|
# Glacier is free software: you can redistribute it
|
|
# and/or modify it under the terms of the GNU General Public License
|
|
# as published by the Free Software Foundation, either version 3
|
|
# of the License, or (at your option) any later version.
|
|
#
|
|
# Glacier is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
# See the GNU General Public License for more details.
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with Glacier. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
am_i_root() {
|
|
printf ">> Checking if user is root...\n"
|
|
if [[ $(/usr/bin/id -u) -ne 0 ]]; then
|
|
printf ">> glacier-mkimg must be run as root.\n"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
info() {
|
|
printf ">> Building root filesystem image with the following settings:\n"
|
|
printf "Image build location: /opt/everest\n"
|
|
printf "Packages to be installed:\n"
|
|
printf " - system-toolchain-bin\n"
|
|
printf " - busybox-base-bin\n"
|
|
printf " - glacier-base-bin\n"
|
|
printf " - make-base-bin\n"
|
|
}
|
|
|
|
init-env() {
|
|
mkdir -v /opt/everest
|
|
mkdir -v /opt/everest/{sources,toolchain,targetfs}
|
|
cd /opt/everest
|
|
}
|
|
|
|
get_skel() {
|
|
printf ">> Creating directory layout in /opt/everest...\n"
|
|
ROOT=/opt/everest/targetfs
|
|
|
|
mkdir -v $ROOT/{boot,dev,etc,home,mnt,opt,proc,root,srv,sys,tmp,var}
|
|
mkdir -v $ROOT/usr
|
|
mkdir -v $ROOT/usr/{bin,sbin,include,lib,lib64,libexec,local,sbin,share,src}
|
|
mkdir -v $ROOT/var/{cache,lib,local,lock,log,opt,run,spool,tmp,www}
|
|
mkdir -v $ROOT/var/cache/glacier
|
|
mkdir -v $ROOT/var/log/glacier
|
|
mkdir -v $ROOT/etc/glacier
|
|
mkdir -v $ROOT/etc/glacier/pkginfo
|
|
ln -sv $ROOT/usr/bin $ROOT/bin
|
|
ln -sv $ROOT/usr/lib $ROOT/lib
|
|
lv -sv $ROOT/usr/sbin $ROOT/sbin
|
|
ln -sv $ROOT/usr/lib64 $ROOT/lib64
|
|
printf ">> Finished.\n"
|
|
exit 0
|
|
}
|
|
|
|
prepare_for_pkg() {
|
|
printf ">> Preparing for package installation...\n"
|
|
glacier -c system-toolchain-bin
|
|
glacier -c busybox-base-bin
|
|
glacier -c glacier-base-bin
|
|
glacier -c make-base-bin
|
|
printf ">> Done.\n"
|
|
exit 0
|
|
}
|
|
|
|
install_pkg() {
|
|
printf ">> Installing packages...\n"
|
|
glacier -ci system-toolchain-bin
|
|
if [ "$?" != "0" ]; then
|
|
exit 1
|
|
fi
|
|
glacier -ci busybox-base-bin
|
|
if [ "$?" != "0" ]; then
|
|
exit 1
|
|
fi
|
|
glacier -ci glacier-base-bin
|
|
if [ "$?" != "0" ]; then
|
|
exit 1
|
|
fi
|
|
glacier -ci make-base-bin
|
|
if [ "$?" != "0" ]; then
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
warn_about_cache() {
|
|
printf ">> WARNING: The cache was used for installing packages to the target.\n"
|
|
printf ">> It is recommended to run the following command to clean the cache:\n"
|
|
printf ">> glacier -cc\n"
|
|
exit 0
|
|
}
|
|
|
|
change_ownership() {
|
|
printf ">> Ensuring file ownership is correct...\n"
|
|
chown -Rv root:root /opt/everest/targetfs
|
|
chgrp -v 13 /opt/everest/targetfs/var/log/lastlog
|
|
printf ">> Done.\n"
|
|
}
|
|
|
|
create_img() {
|
|
printf ">> Creating filesystem image...\n"
|
|
install -dv /opt/everest/build
|
|
cd /opt/everest/targetfs
|
|
tar -cvf /opt/everest/build/everestlinux-RELEASE-img.tar *
|
|
zstd /opt/everest/build/everestlinux-RELEASE-img.tar
|
|
rm /opt/everest/build/everestlinux-${EVEREST_RELEASE}-img.tar
|
|
printf ">> Done.\n"
|
|
}
|
|
|
|
finish() {
|
|
printf ">> Build has finished.\n"
|
|
printf ">> Filesystem image is located in the following directory:\n"
|
|
printf ">> /opt/everest/build\n"
|
|
}
|
|
|
|
showhelp_big() {
|
|
printf "glacier-mkimg - easily compile an Everest Linux image\n"
|
|
printf "usage - glacier-mkimg [-h] [init] [-t] [-s] [-p] [-o] [-i]\n"
|
|
printf "\n"
|
|
printf "glacier-mkimg {init} initialize the environment\n"
|
|
printf "glacier-mkimg {-s} only download filesystem skeleton\n"
|
|
printf "glacier-mkimg {-p} only install packages to /opt/everest\n"
|
|
printf "glacier-mkimg {-o} only change ownership of /opt/everest\n"
|
|
printf "glacier-mkimg {-i} only create image\n"
|
|
printf "\n"
|
|
printf "If no option is passed, glacier-mkimg will perform all tasks\n"
|
|
printf "glacier-mkimg init must be run before anything else is done\n"
|
|
printf "\n"
|
|
printf "This program is free software.\n"
|
|
printf "See the GNU GPL version 3 for details.\n"
|
|
exit 0
|
|
}
|
|
|
|
case $1 in
|
|
-h|--help)
|
|
showhelp_big
|
|
;;
|
|
init)
|
|
am_i_root "$@"
|
|
init_env "$@"
|
|
exit 0
|
|
;;
|
|
-s)
|
|
get_skel "$@"
|
|
exit 0
|
|
;;
|
|
-p)
|
|
prepare_for_pkg "$@"
|
|
install_pkg "$@"
|
|
warn_about_cache "$@"
|
|
exit 0
|
|
;;
|
|
-o)
|
|
change_ownership "$@"
|
|
exit 0
|
|
;;
|
|
-i)
|
|
create_img "$@"
|
|
exit 0
|
|
;;
|
|
-*)
|
|
printf "usage: glacier-mkimg [-h] [init] [-s] [-p] [-o] [-i]\n"
|
|
exit 1
|
|
;;
|
|
*)
|
|
get_skel "$@"
|
|
prepare_for_pkg "$@"
|
|
install_pkg "$@"
|
|
warn_about_cache "$@"
|
|
change_ownership "$@"
|
|
create_img "$@"
|
|
finish
|
|
exit 0
|
|
;;
|
|
esac
|
|
|
|
printf "usage: glacier-mkimg [-h] [init] [-s] [-p] [-o] [-i]\n"
|
|
exit 1
|