manjaro-tools/bin/buildiso.in
2014-12-18 02:03:40 +01:00

284 lines
7.1 KiB
Bash
Executable file

#!/bin/bash
#
# This program 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; version 2 of the License.
#
# This program 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.
version=@version@
BINDIR='@bindir@'
LIBDIR='@libdir@'
PKGDATADIR='@pkgdatadir@'
SYSCONFDIR='@sysconfdir@'
[[ -r ${LIBDIR}/util-msg.sh ]] && source ${LIBDIR}/util-msg.sh
[[ -r ${LIBDIR}/util.sh ]] && source ${LIBDIR}/util.sh
[[ -r ${LIBDIR}/util-iso.sh ]] && source ${LIBDIR}/util-iso.sh
display_settings(){
msg "manjaro-tools"
msg2 "version: ${version}"
if [[ -f ${USER_CONFIG}/manjaro-tools.conf ]]; then
msg2 "user_config: ${USER_CONFIG}/manjaro-tools.conf"
else
msg2 "manjaro_tools_conf: ${manjaro_tools_conf}"
fi
msg "OPTIONS:"
msg2 "arch: ${arch}"
msg2 "branch: ${branch}"
msg2 "work_dir: ${work_dir}"
msg2 "target_dir: ${target_dir}"
msg2 "cache_pkgs: ${cache_pkgs}"
msg2 "cache_lng: ${cache_lng}"
msg2 "pacman_conf: ${pacman_conf}"
msg2 "pacman_mirrors: ${mirrors_conf}"
msg "ARGS:"
msg2 "clean_first: ${clean_first}"
msg2 "auto_svc_conf: ${auto_svc_conf}"
msg2 "high_compression: ${high_compression}"
msg2 "xorg_overlays: ${xorg_overlays}"
msg2 "kde_lng_packages: ${kde_lng_packages}"
msg2 "is_cache_pkgs: ${is_cache_pkgs}"
msg2 "is_cache_lng: ${is_cache_lng}"
msg2 "images_only: ${images_only}"
msg2 "iso_only: ${iso_only}"
msg2 ""
msg "IMAGES SETTINGS:"
msg2 "manjaro_kernel: ${manjaro_kernel}"
msg2 "manjaro_version: ${manjaro_version}"
msg2 "displaymanager: ${displaymanager}"
msg2 "plymouth_theme: ${plymouth_theme}"
if ${auto_svc_conf};then
if [[ ${initsys} == "systemd" ]];then
msg2 "start_systemd: ${start_systemd[*]}"
else
msg2 "start_openrc: ${start_openrc[*]}"
fi
fi
msg "ISO SETTINGS:"
msg2 "iso_label: ${iso_label}"
msg2 "iso_version: ${iso_version}"
msg2 "manjaroiso: ${manjaroiso}"
msg2 "code_name: ${code_name}"
msg2 "img_name: ${img_name}"
msg2 "install_dir: ${install_dir}"
msg2 "compression: ${compression}"
msg2 "iso_file: ${iso_file}"
msg "LIVECD:"
msg2 "username: ${username}"
msg2 "password: ${password}"
msg2 "encrypted password: $(gen_pw)"
msg2 "addgroups: ${addgroups}"
msg2 "hostname: ${hostname}"
if ${auto_svc_conf};then
if [[ ${initsys} == "systemd" ]];then
msg2 "start_systemd_live: ${start_systemd_live[*]}"
else
msg2 "start_openrc_live: ${start_openrc_live[*]}"
fi
fi
}
iso_owner=${SUDO_USER:-$USER}
if [[ -n $SUDO_USER ]]; then
eval "USER_HOME=~$SUDO_USER"
else
USER_HOME=$HOME
fi
USER_CONFIG="$USER_HOME/.config"
load_config "${USER_CONFIG}/manjaro-tools.conf"
load_config "${SYSCONFDIR}/manjaro-tools.conf"
load_desktop_definition
displaymanager=$(cat ${PWD}/displaymanager)
initsys=$(cat ${PWD}/initsys)
clean_first=true
auto_svc_conf=true
high_compression=true
pretend=false
verbose=false
xorg_overlays=false
kde_lng_packages=false
images_only=false
iso_only=false
is_cache_pkgs=false
is_cache_lng=false
pacman_conf_arch='default'
usage() {
echo "Usage: ${0##*/} [options]"
echo ' -a <arch> Set arch'
echo " [default: ${arch}]"
echo ' -b <branch> Set branch'
echo " [default: ${branch}]"
echo ' -r <dir> Work directory'
echo " [default: ${work_dir}]"
echo ' -t <dir> Target iso directory'
echo " [default: ${target_dir}]"
echo " -i <file> Config file for pacman"
echo " [default: ${PKGDATADIR}/pacman-${pacman_conf_arch}.conf]"
echo ' -v Verbose iso compression'
echo ' -q Query settings and pretend build'
echo ' -c Disable clean work dir and target dir iso'
echo ' -z Disable high compression'
echo ' -A Disable auto configure livecd services'
echo ' -X Xorg overlays'
echo ' -K kde lng packages'
echo ' -B Build images only'
echo ' -G Generate iso only'
echo ' -P Use custom pkgs cache, useful for image rebuilds'
echo ' -L Use custom lng cache, useful for image rebuilds'
echo ' Requires pre built images'
echo ' -h This help'
echo ''
echo ''
exit 1
}
orig_argv=("$@")
opts='a:b:r:t:i:cvzqXKABGPLh'
while getopts "${opts}" arg; do
case "${arg}" in
a) arch="$OPTARG" ;;
b) branch="$OPTARG" ;;
r) work_dir="$OPTARG" ;;
t) target_dir="$OPTARG" ;;
i) pacman_conf="$OPTARG" ;;
c) clean_first=false ;;
z) high_compression=false ;;
A) auto_svc_conf=false ;;
v) verbose=true; iso_args+=(-v) ;;
X) xorg_overlays=true ;;
K) kde_lng_packages=true ;;
B) images_only=true ;;
G) iso_only=true ;;
P) is_cache_pkgs=true ;;
L) is_cache_lng=true ;;
q) pretend=true ;;
h) usage ;;
esac
done
shift $(($OPTIND - 1))
work_dir=${work_dir}/${desktop}/${arch}
if [[ "$arch" == 'x86_64' ]]; then
pacman_conf_arch='multilib'
fi
load_pacman_conf "${pacman_conf}"
load_pacman_conf "${PKGDATADIR}/pacman-${pacman_conf_arch}.conf"
mirrors_conf="${PKGDATADIR}/pacman-mirrors-${branch}.conf"
create_args+=(-v -a ${arch} -D ${install_dir} -C ${pacman_conf} -M ${mirrors_conf})
iso_args+=(-a ${arch} -D ${install_dir} -L ${iso_label} -c ${compression})
iso_file="${target_dir}/${img_name}-${desktop}-${iso_version}-${arch}.iso"
iso_profile=${PWD##*/}
${high_compression} && iso_args+=(-x)
${clean_first} && iso_args+=(-f)
check_root "$0" "${orig_argv[@]}"
get_pkglist
if [ -e Packages-Xorg ] ; then
get_pkglist_xorg
fi
if [ -e Packages-Lng ] ; then
get_pkglist_lng
fi
if [ -e "${pkgsfile}" ] ; then
get_pkglist_de
fi
if [[ -f Packages-Livecd ]]; then
get_pkglist_overlay
fi
${pretend} && display_settings && exit 1
compress_images(){
# install common
make_boot
if [ "${arch}" == "x86_64" ]; then
make_efi
make_efiboot
fi
make_isolinux
make_isomounts
make_iso
}
if ${iso_only}; then
[[ ! -d ${work_dir} ]] && die "You need to create images first eg buildiso -B"
compress_images
exit 1
fi
${clean_first} && clean_up
prepare_buildiso
make_images(){
# install basic
make_root_image
# install DE(s)
if [ -e "${pkgsfile}" ] ; then
make_de_image
fi
# install xorg-drivers
if [ -e Packages-Xorg ] ; then
make_pkgs_image
fi
# install translations
if [ -e Packages-Lng ] ; then
make_lng_image
fi
# install overlay
if [[ -f Packages-Livecd ]]; then
make_overlay_image
fi
}
if ${images_only}; then
make_images
warning "Continue with eg. buildiso -Gv ..."
exit 1
else
make_images
fi
compress_images