Files
lnx-arch/scripts/99_deploy.sh
2024-05-03 12:54:11 -05:00

130 lines
2.8 KiB
Bash

#!/usr/bin/env bash
# klevstul
echo "<< 99_deploy.sh >>"
user=poq
clone_trg=/tmp
targz_dots_url=https://git.mz.fo/fro/lnx-arch/archive/master.tar.gz
dots_trg=${clone_trg}/lnx-arch/dots
targz_wp_url=https://gitlab.com/pqq/wallpaper/-/archive/main/wallpaper-main.tar.gz
wp_trg=${clone_trg}/wallpaper-main/wp
if [ "$EUID" -ne 0 ]
then echo "error: run as 'root'"
exit
fi
this_file_name=`basename "$0"`
if [ $# -lt 1 ]; then
echo "usage: '$this_file_name {all}'"
exit 1
fi
operation=$1
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
# helper functions
download_repo() {
_targz_url=$1
# make clone target directory, if it doesn't exist
mkdir -p ${clone_trg}
# instead of doing a git clone (like `git clone ${clone_url} ${clone_trg}`),
# where i would have emptied the target dir each time, i download the
# source as a tar.gz.
wget --show-progress ${_targz_url} -O ${clone_trg}/tmp.tar.gz
tar -xzf ${clone_trg}/tmp.tar.gz -C ${clone_trg}
rm ${clone_trg}/tmp.tar.gz
}
create_dir() {
_directory=$1
mkdir -p ${_directory}
chown ${user}:${user} ${_directory}
}
deploy_file() {
_src_path=$1
_trg_path=$2
_no_chown=$3
cp -f ${_src_path} ${_trg_path}
# only chown if _no_chown variable is empty
if [ -z "${_no_chown}" ]; then
chown ${user}:${user} ${_trg_path}
fi
file_name=$(basename ${_trg_path})
suffix=".sh"
if [[ ${file_name} == *$suffix ]]; then
chmod 755 ${_trg_path}
fi
echo ""
echo "${file_name}:"
ls -al ${_trg_path}
}
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
# dots (dot files)
if [ ${operation} == "dots" ] ; then
echo "***** ${operation} *****"
rm -rf ${clone_trg}/lnx-arch
download_repo ${targz_dots_url}
tree ${clone_trg}/lnx-arch
# bin (executable binaries, scripts)
file_path=/usr/local/bin
deploy_file "${dots_trg}/bin/*" "${file_path}/${file_name}"
# environment
file_path=/etc/
deploy_file "${dots_trg}/bin/*" "${file_path}/${file_name}" no_chown
# hypridle
file_name=hypridle.conf
file_path=/home/${user}/.config/hypr
deploy_file ${dots_trg}/hypridle/${file_name} ${file_path}/${file_name}
# hyprland
file_name=hyprland.conf
file_path=/home/${user}/.config/hypr
deploy_file ${dots_trg}/hyprland/${file_name} ${file_path}/${file_name}
# hyprpaper
file_name=hyprpaper.conf
file_path=/home/${user}/.config/hypr
deploy_file ${dots_trg}/hyprpaper/${file_name} ${file_path}/${file_name}
# waybar
file_path=/home/${user}/.config/waybar
mkdir -p ${file_path}
deploy_file "${dots_trg}/waybar/*" "${file_path}/"
fi
# wallpapers
if [ ${operation} == "wp" ] ; then
echo "***** ${operation} *****"
rm -rf ${clone_trg}/wallpaper-main
download_repo ${targz_wp_url}
tree ${clone_trg}/wallpaper-main
deploy_file "${wp_trg}/*" "/home/${user}/.config/hypr/"
fi