2017-04-19 21:30:01 +02:00
|
|
|
#!/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.
|
|
|
|
|
2017-04-19 21:30:38 +02:00
|
|
|
add_svc_rc(){
|
2017-05-10 12:06:40 +02:00
|
|
|
local mnt="$1" name="$2"
|
2017-05-09 22:21:28 +02:00
|
|
|
if [[ -f $mnt/etc/init.d/$name ]];then
|
|
|
|
msg2 "Setting %s ..." "$name"
|
|
|
|
chroot $mnt rc-update add $name default &>/dev/null
|
2017-04-19 21:30:38 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
add_svc_sd(){
|
2017-05-10 12:06:40 +02:00
|
|
|
local mnt="$1" name="$2"
|
2017-05-09 22:21:28 +02:00
|
|
|
if [[ -f $mnt/etc/systemd/system/$name.service ]] || \
|
|
|
|
[[ -f $mnt/usr/lib/systemd/system/$name.service ]];then
|
|
|
|
msg2 "Setting %s ..." "$name"
|
|
|
|
chroot $mnt systemctl enable $name &>/dev/null
|
2017-04-19 21:30:38 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
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(){
|
2017-06-07 23:45:34 +02:00
|
|
|
local path=$1$2/ \
|
2017-04-19 21:30:38 +02:00
|
|
|
drv_path=$1/var/lib/mhwd/db/pci/graphic_drivers
|
|
|
|
info "Configuring mwwd db ..."
|
|
|
|
if [ -z "$(ls $path | grep catalyst-utils 2> /dev/null)" ]; then
|
|
|
|
msg2 "Disabling Catalyst driver"
|
|
|
|
mkdir -p $drv_path/catalyst/
|
|
|
|
touch $drv_path/catalyst/MHWDCONFIG
|
|
|
|
fi
|
|
|
|
if [ -z "$(ls $path | grep nvidia-utils 2> /dev/null)" ]; then
|
|
|
|
msg2 "Disabling Nvidia driver"
|
|
|
|
mkdir -p $drv_path/nvidia/
|
|
|
|
touch $drv_path/nvidia/MHWDCONFIG
|
|
|
|
msg2 "Disabling Nvidia Bumblebee driver"
|
|
|
|
mkdir -p $drv_path/hybrid-intel-nvidia-bumblebee/
|
|
|
|
touch $drv_path/hybrid-intel-nvidia-bumblebee/MHWDCONFIG
|
|
|
|
fi
|
|
|
|
if [ -z "$(ls $path | grep nvidia-304xx-utils 2> /dev/null)" ]; then
|
|
|
|
msg2 "Disabling Nvidia 304xx driver"
|
|
|
|
mkdir -p $drv_path/nvidia-304xx/
|
|
|
|
touch $drv_path/nvidia-304xx/MHWDCONFIG
|
|
|
|
fi
|
|
|
|
if [ -z "$(ls $path | grep nvidia-340xx-utils 2> /dev/null)" ]; then
|
|
|
|
msg2 "Disabling Nvidia 340xx driver"
|
|
|
|
mkdir -p $drv_path/nvidia-340xx/
|
|
|
|
touch $drv_path/nvidia-340xx/MHWDCONFIG
|
|
|
|
fi
|
|
|
|
if [ -z "$(ls $path | grep xf86-video-amdgpu 2> /dev/null)" ]; then
|
|
|
|
msg2 "Disabling AMD gpu driver"
|
|
|
|
mkdir -p $drv_path/xf86-video-amdgpu/
|
|
|
|
touch $drv_path/xf86-video-amdgpu/MHWDCONFIG
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2017-04-19 21:30:01 +02:00
|
|
|
configure_hosts(){
|
|
|
|
sed -e "s|localhost.localdomain|localhost.localdomain ${hostname}|" -i $1/etc/hosts
|
|
|
|
}
|
|
|
|
|
2017-04-19 21:30:38 +02:00
|
|
|
configure_lsb(){
|
2017-05-08 18:19:36 +02:00
|
|
|
local conf=$1/etc/lsb-release
|
|
|
|
if [[ -e $conf ]] ; then
|
2017-04-19 21:30:38 +02:00
|
|
|
msg2 "Configuring lsb-release"
|
2017-05-08 18:19:36 +02:00
|
|
|
sed -i -e "s/^.*DISTRIB_RELEASE.*/DISTRIB_RELEASE=${dist_release}/" $conf
|
|
|
|
sed -i -e "s/^.*DISTRIB_CODENAME.*/DISTRIB_CODENAME=${dist_codename}/" $conf
|
2017-04-19 21:30:38 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
configure_logind(){
|
|
|
|
local conf=$1/etc/$2/logind.conf
|
2017-05-08 18:19:36 +02:00
|
|
|
if [[ -e $conf ]];then
|
2017-05-10 23:11:42 +02:00
|
|
|
msg2 "Configuring logind ..."
|
2017-05-08 18:19:36 +02:00
|
|
|
sed -i 's/#\(HandleSuspendKey=\)suspend/\1ignore/' "$conf"
|
|
|
|
sed -i 's/#\(HandleLidSwitch=\)suspend/\1ignore/' "$conf"
|
|
|
|
sed -i 's/#\(HandleHibernateKey=\)hibernate/\1ignore/' "$conf"
|
|
|
|
fi
|
2017-04-19 21:30:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
configure_journald(){
|
|
|
|
local conf=$1/etc/systemd/journald.conf
|
2017-06-07 23:45:34 +02:00
|
|
|
if [[ -e $conf ]];then
|
|
|
|
msg2 "Configuring journald ..."
|
|
|
|
sed -i 's/#\(Storage=\)auto/\1volatile/' "$conf"
|
|
|
|
fi
|
2017-04-19 21:30:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
configure_services(){
|
2017-05-09 22:21:28 +02:00
|
|
|
local mnt="$1"
|
2017-04-19 21:30:38 +02:00
|
|
|
info "Configuring [%s]" "${initsys}"
|
|
|
|
case ${initsys} in
|
|
|
|
'openrc')
|
|
|
|
for svc in ${enable_openrc[@]}; do
|
2017-05-09 22:21:28 +02:00
|
|
|
[[ $svc == "xdm" ]] && set_xdm "$mnt"
|
|
|
|
add_svc_rc "$mnt" "$svc"
|
2017-04-19 21:30:38 +02:00
|
|
|
done
|
2017-05-22 00:00:03 +02:00
|
|
|
for svc in ${enable_live[@]}; do
|
2017-05-09 22:21:28 +02:00
|
|
|
add_svc_rc "$mnt" "$svc"
|
2017-04-19 21:30:38 +02:00
|
|
|
done
|
|
|
|
;;
|
|
|
|
'systemd')
|
|
|
|
for svc in ${enable_systemd[@]}; do
|
2017-05-09 22:21:28 +02:00
|
|
|
add_svc_sd "$mnt" "$svc"
|
2017-04-19 21:30:38 +02:00
|
|
|
done
|
2017-05-22 00:00:03 +02:00
|
|
|
for svc in ${enable_live[@]}; do
|
2017-05-09 22:21:28 +02:00
|
|
|
add_svc_sd "$mnt" "$svc"
|
2017-04-19 21:30:38 +02:00
|
|
|
done
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
info "Done configuring [%s]" "${initsys}"
|
|
|
|
}
|
|
|
|
|
|
|
|
configure_system(){
|
2017-05-09 22:21:28 +02:00
|
|
|
local mnt="$1"
|
2017-04-19 21:30:38 +02:00
|
|
|
case ${initsys} in
|
|
|
|
'systemd')
|
2017-05-09 22:21:28 +02:00
|
|
|
configure_logind "$mnt" "systemd"
|
|
|
|
configure_journald "$mnt"
|
2017-04-19 21:30:38 +02:00
|
|
|
|
|
|
|
# Prevent some services to be started in the livecd
|
|
|
|
echo 'File created by manjaro-tools. See systemd-update-done.service(8).' \
|
2017-06-08 11:15:37 +02:00
|
|
|
| tee "${mnt}/etc/.updated" >"${mnt}/var/.updated"
|
2017-04-19 21:30:38 +02:00
|
|
|
|
|
|
|
msg2 "Disable systemd-gpt-auto-generator"
|
2017-06-08 11:15:37 +02:00
|
|
|
ln -sf /dev/null "${mnt}/usr/lib/systemd/system-generators/systemd-gpt-auto-generator"
|
2017-04-19 21:30:38 +02:00
|
|
|
;;
|
|
|
|
'openrc')
|
2017-05-09 22:21:28 +02:00
|
|
|
configure_logind "$mnt" "elogind"
|
2017-04-19 21:30:38 +02:00
|
|
|
;;
|
|
|
|
esac
|
2017-05-09 22:21:28 +02:00
|
|
|
echo ${hostname} > $mnt/etc/hostname
|
2017-04-19 21:30:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
make_repo(){
|
2017-06-07 23:45:34 +02:00
|
|
|
local dest="$1" repo="$2"
|
2017-05-09 22:21:28 +02:00
|
|
|
cp ${DATADIR}/pacman-mhwd.conf $dest/opt
|
2017-06-07 23:45:34 +02:00
|
|
|
repo-add $dest$repo/mhwd.db.tar.gz $dest$repo/*pkg*z
|
2017-04-19 21:30:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
clean_iso_root(){
|
2017-05-09 22:21:28 +02:00
|
|
|
local dest="$1"
|
2017-05-10 23:11:42 +02:00
|
|
|
msg "Deleting isoroot [%s] ..." "${dest##*/}"
|
2017-05-09 22:21:28 +02:00
|
|
|
rm -rf --one-file-system "$dest"
|
2017-04-19 21:30:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
clean_up_image(){
|
2017-05-09 22:21:28 +02:00
|
|
|
local path mnt="$1"
|
|
|
|
msg2 "Cleaning [%s]" "${mnt##*/}"
|
2017-05-11 11:30:41 +02:00
|
|
|
if [[ ${mnt##*/} == 'mhwdfs' ]];then
|
2017-05-09 22:21:28 +02:00
|
|
|
path=$mnt/var
|
2017-04-19 21:30:38 +02:00
|
|
|
if [[ -d $path ]];then
|
|
|
|
find "$path" -mindepth 0 -delete &> /dev/null
|
|
|
|
fi
|
2017-05-09 22:21:28 +02:00
|
|
|
path=$mnt/etc
|
2017-04-19 21:30:38 +02:00
|
|
|
if [[ -d $path ]];then
|
|
|
|
find "$path" -mindepth 0 -delete &> /dev/null
|
|
|
|
fi
|
|
|
|
else
|
2017-06-13 17:58:26 +02:00
|
|
|
default_locale "reset" "$mnt"
|
2017-05-09 22:21:28 +02:00
|
|
|
path=$mnt/boot
|
2017-04-19 21:30:38 +02:00
|
|
|
if [[ -d "$path" ]]; then
|
|
|
|
find "$path" -name 'initramfs*.img' -delete &> /dev/null
|
|
|
|
fi
|
2017-05-09 22:21:28 +02:00
|
|
|
path=$mnt/var/lib/pacman/sync
|
2017-04-19 21:30:38 +02:00
|
|
|
if [[ -d $path ]];then
|
|
|
|
find "$path" -type f -delete &> /dev/null
|
|
|
|
fi
|
2017-05-09 22:21:28 +02:00
|
|
|
path=$mnt/var/cache/pacman/pkg
|
2017-04-19 21:30:38 +02:00
|
|
|
if [[ -d $path ]]; then
|
|
|
|
find "$path" -type f -delete &> /dev/null
|
|
|
|
fi
|
2017-05-09 22:21:28 +02:00
|
|
|
path=$mnt/var/log
|
2017-04-19 21:30:38 +02:00
|
|
|
if [[ -d $path ]]; then
|
|
|
|
find "$path" -type f -delete &> /dev/null
|
|
|
|
fi
|
2017-05-09 22:21:28 +02:00
|
|
|
path=$mnt/var/tmp
|
2017-04-19 21:30:38 +02:00
|
|
|
if [[ -d $path ]];then
|
|
|
|
find "$path" -mindepth 1 -delete &> /dev/null
|
|
|
|
fi
|
2017-05-09 22:21:28 +02:00
|
|
|
path=$mnt/tmp
|
2017-04-19 21:30:38 +02:00
|
|
|
if [[ -d $path ]];then
|
|
|
|
find "$path" -mindepth 1 -delete &> /dev/null
|
|
|
|
fi
|
2017-05-08 18:19:36 +02:00
|
|
|
|
2017-05-09 22:54:30 +02:00
|
|
|
if [[ ${mnt##*/} == 'livefs' ]];then
|
2017-05-09 22:21:28 +02:00
|
|
|
rm -rf "$mnt/etc/pacman.d/gnupg"
|
2017-04-19 21:30:38 +02:00
|
|
|
fi
|
2017-05-08 18:19:36 +02:00
|
|
|
fi
|
|
|
|
|
2017-05-09 22:21:28 +02:00
|
|
|
find "$mnt" -name *.pacnew -name *.pacsave -name *.pacorig -delete
|
|
|
|
file=$mnt/boot/grub/grub.cfg
|
2017-05-08 18:19:36 +02:00
|
|
|
if [[ -f "$file" ]]; then
|
|
|
|
rm $file
|
|
|
|
fi
|
2017-04-19 21:30:38 +02:00
|
|
|
}
|
|
|
|
|
2017-04-19 21:30:01 +02:00
|
|
|
copy_from_cache(){
|
2017-06-03 19:02:49 +02:00
|
|
|
local list="${tmp_dir}"/mhwd-cache.list
|
2017-06-08 11:15:37 +02:00
|
|
|
local mnt="$1" repo="$2"
|
2017-06-08 15:20:50 +02:00
|
|
|
shift 2
|
2017-06-08 11:15:37 +02:00
|
|
|
chroot-run "$mnt" pacman -v -Syw --noconfirm "$@" || return 1
|
|
|
|
chroot-run "$mnt" pacman -v -Sp --noconfirm "$@" > "$list"
|
2017-04-19 21:30:01 +02:00
|
|
|
sed -ni '/.pkg.tar.xz/p' "$list"
|
|
|
|
sed -i "s/.*\///" "$list"
|
|
|
|
msg2 "Copying mhwd package cache ..."
|
2017-06-07 23:45:34 +02:00
|
|
|
rsync -v --files-from="$list" /var/cache/pacman/pkg "$mnt$repo"
|
2017-04-19 21:30:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
chroot_clean(){
|
2017-04-27 15:13:22 +02:00
|
|
|
local dest="$1"
|
|
|
|
for root in "$dest"/*; do
|
2017-04-26 22:56:49 +02:00
|
|
|
[[ -d ${root} ]] || continue
|
|
|
|
local name=${root##*/}
|
2017-04-19 21:30:01 +02:00
|
|
|
if [[ $name != "mhwdfs" ]];then
|
2017-04-30 09:13:19 +02:00
|
|
|
delete_chroot "${root}" "$dest"
|
2017-04-19 21:30:01 +02:00
|
|
|
fi
|
|
|
|
done
|
2017-04-27 15:13:22 +02:00
|
|
|
rm -rf --one-file-system "$dest"
|
2017-04-19 21:30:01 +02:00
|
|
|
}
|
2017-04-19 21:30:38 +02:00
|
|
|
|