manjaro-tools/lib/util-iso-image.sh

342 lines
9.2 KiB
Bash
Raw Normal View History

#!/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.
2015-12-06 18:40:05 +01:00
copy_overlay(){
if [[ -e $1 ]];then
msg2 "Copying [%s] ..." "${1##*/}"
if [[ -L $1 ]];then
cp -a --no-preserve=ownership $1/* $2
else
cp -LR $1/* $2
fi
2015-12-06 05:58:56 +01:00
fi
}
2016-02-29 08:18:25 +01:00
configure_plymouth(){
if ${plymouth_boot};then
msg2 "Configuring plymouth: %s" "${plymouth_theme}"
local conf=$1/etc/plymouth/plymouthd.conf
sed -i -e "s/^.*Theme=.*/Theme=${plymouth_theme}/" "${conf}"
fi
}
2016-02-24 11:28:10 +01:00
add_svc_rc(){
if [[ -f $1/etc/init.d/$2 ]];then
msg2 "Setting %s ..." "$2"
chroot $1 rc-update add $2 default &>/dev/null
2015-02-13 15:17:00 +01:00
fi
}
2016-02-24 11:28:10 +01:00
add_svc_sd(){
if [[ -f $1/etc/systemd/system/$2.service ]] || \
[[ -f $1/usr/lib/systemd/system/$2.service ]];then
msg2 "Setting %s ..." "$2"
chroot $1 systemctl enable $2 &>/dev/null
2016-02-24 11:28:10 +01:00
fi
}
2016-02-24 11:28:10 +01:00
set_xdm(){
if [[ -f $1/etc/conf.d/xdm ]];then
local conf='DISPLAYMANAGER="'${displaymanager}'"'
sed -i -e "s|^.*DISPLAYMANAGER=.*|${conf}|" $1/etc/conf.d/xdm
fi
}
configure_mhwd_drivers(){
local path=$1${mhwd_repo}/ \
2016-02-29 08:18:25 +01:00
drv_path=$1/var/lib/mhwd/db/pci/graphic_drivers
info "Configuring mwwd db ..."
2016-02-24 11:28:10 +01:00
if [ -z "$(ls $path | grep catalyst-utils 2> /dev/null)" ]; then
2015-02-13 15:17:00 +01:00
msg2 "Disabling Catalyst driver"
2016-02-24 11:28:10 +01:00
mkdir -p $drv_path/catalyst/
touch $drv_path/catalyst/MHWDCONFIG
fi
2016-02-24 11:28:10 +01:00
if [ -z "$(ls $path | grep nvidia-utils 2> /dev/null)" ]; then
2015-02-13 15:17:00 +01:00
msg2 "Disabling Nvidia driver"
2016-02-24 11:28:10 +01:00
mkdir -p $drv_path/nvidia/
touch $drv_path/nvidia/MHWDCONFIG
2015-02-13 15:17:00 +01:00
msg2 "Disabling Nvidia Bumblebee driver"
2016-02-24 11:28:10 +01:00
mkdir -p $drv_path/hybrid-intel-nvidia-bumblebee/
touch $drv_path/hybrid-intel-nvidia-bumblebee/MHWDCONFIG
fi
2016-02-24 11:28:10 +01:00
if [ -z "$(ls $path | grep nvidia-304xx-utils 2> /dev/null)" ]; then
2015-02-13 15:17:00 +01:00
msg2 "Disabling Nvidia 304xx driver"
2016-02-24 11:28:10 +01:00
mkdir -p $drv_path/nvidia-304xx/
touch $drv_path/nvidia-304xx/MHWDCONFIG
fi
2016-02-24 11:28:10 +01:00
if [ -z "$(ls $path | grep nvidia-340xx-utils 2> /dev/null)" ]; then
2015-02-13 15:17:00 +01:00
msg2 "Disabling Nvidia 340xx driver"
2016-02-24 11:28:10 +01:00
mkdir -p $drv_path/nvidia-340xx/
touch $drv_path/nvidia-340xx/MHWDCONFIG
fi
2016-02-24 11:28:10 +01:00
if [ -z "$(ls $path | grep xf86-video-amdgpu 2> /dev/null)" ]; then
msg2 "Disabling AMD gpu driver"
2016-02-24 11:28:10 +01:00
mkdir -p $drv_path/xf86-video-amdgpu/
touch $drv_path/xf86-video-amdgpu/MHWDCONFIG
fi
}
2015-05-21 19:54:29 +02:00
configure_lsb(){
[[ -f $1/boot/grub/grub.cfg ]] && rm $1/boot/grub/grub.cfg
if [ -e $1/etc/lsb-release ] ; then
msg2 "Configuring lsb-release"
sed -i -e "s/^.*DISTRIB_RELEASE.*/DISTRIB_RELEASE=${dist_release}/" $1/etc/lsb-release
sed -i -e "s/^.*DISTRIB_CODENAME.*/DISTRIB_CODENAME=${dist_codename}/" $1/etc/lsb-release
fi
}
2016-02-24 11:28:10 +01:00
configure_mhwd(){
if [[ ${target_arch} == "x86_64" ]];then
2016-02-24 11:28:10 +01:00
if ! ${multilib};then
msg2 "Disable mhwd lib32 support"
echo 'MHWD64_IS_LIB32="false"' > $1/etc/mhwd-x86_64.conf
fi
fi
}
2016-02-29 08:18:25 +01:00
configure_logind(){
msg2 "Configuring logind ..."
local conf=$1/etc/systemd/logind.conf
sed -i 's/#\(HandleSuspendKey=\)suspend/\1ignore/' "$conf"
sed -i 's/#\(HandleLidSwitch=\)suspend/\1ignore/' "$conf"
sed -i 's/#\(HandleHibernateKey=\)hibernate/\1ignore/' "$conf"
}
2016-02-29 08:18:25 +01:00
configure_journald(){
msg2 "Configuring journald ..."
local conf=$1/etc/systemd/journald.conf
sed -i 's/#\(Storage=\)auto/\1volatile/' "$conf"
}
2016-02-24 11:28:10 +01:00
configure_services(){
2016-02-26 15:25:46 +01:00
info "Configuring [%s]" "${initsys}"
2016-02-24 11:28:10 +01:00
case ${initsys} in
'openrc')
for svc in ${enable_openrc[@]}; do
[[ $svc == "xdm" ]] && set_xdm "$1"
add_svc_rc "$1" "$svc"
2016-02-24 11:28:10 +01:00
done
for svc in ${enable_openrc_live[@]}; do
add_svc_rc "$1" "$svc"
done
2016-02-24 11:28:10 +01:00
;;
'systemd')
for svc in ${enable_systemd[@]}; do
2016-02-24 11:28:10 +01:00
add_svc_sd "$1" "$svc"
done
for svc in ${enable_systemd_live[@]}; do
2016-02-24 11:28:10 +01:00
add_svc_sd "$1" "$svc"
done
;;
esac
info "Done configuring [%s]" "${initsys}"
}
is_valid_de(){
if [[ ${default_desktop_executable} != "none" ]] && \
[[ ${default_desktop_file} != "none" ]]; then
return 0
else
return 1
fi
}
load_desktop_map(){
local _space="s| ||g" _clean=':a;N;$!ba;s/\n/ /g' _com_rm="s|#.*||g" \
file=${DATADIR}/desktop.map
local desktop_map=$(sed "$_com_rm" "$file" \
| sed "$_space" \
| sed "$_clean")
echo ${desktop_map}
}
detect_desktop_env(){
local xs=$1/usr/share/xsessions ex=$1/usr/bin key val map=( $(load_desktop_map) )
default_desktop_file="none"
default_desktop_executable="none"
for item in "${map[@]}";do
key=${item%:*}
val=${item#*:}
if [[ -f $xs/$key.desktop ]] && [[ -f $ex/$val ]];then
default_desktop_file="$key"
default_desktop_executable="$val"
fi
done
}
write_live_session_conf(){
msg2 "Configuring live session ..."
local path=$1${DATADIR}
[[ ! -d $path ]] && mkdir -p $path
local conf=$path/live.conf
echo '# live session configuration' > ${conf}
echo '' >> ${conf}
echo '# autologin' >> ${conf}
echo "autologin=${autologin}" >> ${conf}
echo '' >> ${conf}
echo '# login shell' >> ${conf}
echo "login_shell=${login_shell}" >> ${conf}
echo '' >> ${conf}
echo '# live username' >> ${conf}
echo "username=${username}" >> ${conf}
echo '' >> ${conf}
echo '# live password' >> ${conf}
echo "password=${password}" >> ${conf}
echo '' >> ${conf}
echo '# live group membership' >> ${conf}
echo "addgroups='${addgroups}'" >> ${conf}
echo '' >> ${conf}
echo '# iso name' >> ${conf}
echo "iso_name=${iso_name}" >> ${conf}
echo '' >> ${conf}
echo '# default_desktop_file' >> ${conf}
echo "default_desktop_file=${default_desktop_file}" >> ${conf}
echo '' >> ${conf}
echo '# default_desktop_executable' >> ${conf}
echo "default_desktop_executable=${default_desktop_executable}" >> ${conf}
echo '' >> ${conf}
echo '# samba workgroup' >> ${conf}
2016-08-22 12:46:55 +02:00
echo "smb_workgroup=${smb_workgroup}" >> ${conf}
}
configure_hosts(){
sed -e "s|localhost.localdomain|localhost.localdomain ${hostname}|" -i $1/etc/hosts
}
configure_system(){
2016-02-29 08:18:25 +01:00
case ${initsys} in
'systemd')
configure_journald "$1"
configure_logind "$1"
2016-02-29 08:18:25 +01:00
# Prevent some services to be started in the livecd
echo 'File created by manjaro-tools. See systemd-update-done.service(8).' \
| tee "${path}/etc/.updated" >"${path}/var/.updated"
2016-06-10 21:26:52 +02:00
msg2 "Disable systemd-gpt-auto-generator"
ln -sf /dev/null "${path}/usr/lib/systemd/system-generators/systemd-gpt-auto-generator"
echo ${hostname} > $1/etc/hostname
2016-02-29 08:18:25 +01:00
;;
'openrc')
local hn='hostname="'${hostname}'"'
sed -i -e "s|^.*hostname=.*|${hn}|" $1/etc/conf.d/hostname
2016-02-29 08:18:25 +01:00
;;
esac
}
configure_live_image(){
msg "Configuring [live-image]"
detect_desktop_env "$1"
configure_hosts "$1"
configure_plymouth "$1"
configure_lsb "$1"
configure_mhwd "$1"
configure_system "$1"
configure_services "$1"
configure_calamares "$1" "$1/etc/mkinitcpio.d/${kernel}.preset"
write_live_session_conf "$1"
2015-12-18 18:25:13 +01:00
msg "Done configuring [live-image]"
2015-05-21 19:54:29 +02:00
}
make_repo(){
repo-add $1${mhwd_repo}/mhwd.db.tar.gz $1${mhwd_repo}/*pkg*z
2015-05-21 19:54:29 +02:00
}
copy_from_cache(){
local list="${tmp_dir}"/mhwd-cache.list
chroot-run \
-r "${mountargs_ro}" \
-w "${mountargs_rw}" \
-B "${build_mirror}/${target_branch}" \
"$1" \
pacman -v -Syw $2 --noconfirm || return 1
chroot-run \
-r "${mountargs_ro}" \
-w "${mountargs_rw}" \
-B "${build_mirror}/${target_branch}" \
"$1" \
pacman -v -Sp $2 --noconfirm > "$list"
sed -ni '/.pkg.tar.xz/p' "$list"
sed -i "s/.*\///" "$list"
msg2 "Copying mhwd package cache ..."
rsync -v --files-from="$list" /var/cache/pacman/pkg "$1${mhwd_repo}"
2015-05-21 19:54:29 +02:00
}
2015-06-04 15:20:04 +02:00
chroot_create(){
[[ "${1##*/}" == "root-image" ]] && local flag="-L"
setarch "${target_arch}" \
2015-06-29 04:08:45 +02:00
mkchroot ${mkchroot_args[*]} ${flag} $@
2015-05-21 19:54:29 +02:00
}
chroot_clean(){
msg "Cleaning up ..."
for image in "$1"/*-image; do
[[ -d ${image} ]] || continue
local name=${image##*/}
if [[ $name != "mhwd-image" ]];then
msg2 "Deleting chroot [%s] ..." "$name"
lock 9 "${image}.lock" "Locking chroot '${image}'"
if [[ "$(stat -f -c %T "${image}")" == btrfs ]]; then
{ type -P btrfs && btrfs subvolume delete "${image}"; } #&> /dev/null
fi
rm -rf --one-file-system "${image}"
fi
done
exec 9>&-
rm -rf --one-file-system "$1"
}
2015-05-21 19:54:29 +02:00
clean_up_image(){
2016-03-03 22:40:30 +01:00
msg2 "Cleaning [%s]" "${1##*/}"
2015-05-21 19:54:29 +02:00
2016-03-03 22:40:30 +01:00
local path
if [[ ${1##*/} == 'mhwd-image' ]];then
path=$1/var
if [[ -d $path ]];then
find "$path" -mindepth 0 -delete &> /dev/null
fi
path=$1/etc
if [[ -d $path ]];then
find "$path" -mindepth 0 -delete &> /dev/null
fi
else
[[ -f "$1/etc/locale.gen.bak" ]] && mv "$1/etc/locale.gen.bak" "$1/etc/locale.gen"
[[ -f "$1/etc/locale.conf.bak" ]] && mv "$1/etc/locale.conf.bak" "$1/etc/locale.conf"
2016-03-03 22:40:30 +01:00
path=$1/boot
if [[ -d "$path" ]]; then
find "$path" -name 'initramfs*.img' -delete &> /dev/null
fi
2016-08-22 20:53:39 +02:00
path=$1/var/lib/pacman/sync
if [[ -d $path ]];then
find "$path" -type f -delete &> /dev/null
fi
2016-03-03 22:40:30 +01:00
path=$1/var/cache/pacman/pkg
if [[ -d $path ]]; then
find "$path" -type f -delete &> /dev/null
fi
path=$1/var/log
if [[ -d $path ]]; then
find "$path" -type f -delete &> /dev/null
fi
path=$1/var/tmp
if [[ -d $path ]];then
find "$path" -mindepth 1 -delete &> /dev/null
fi
path=$1/tmp
if [[ -d $path ]];then
find "$path" -mindepth 1 -delete &> /dev/null
fi
fi
2015-05-21 19:54:29 +02:00
# find "${work_dir}" -name *.pacnew -name *.pacsave -name *.pacorig -delete
}