#!/usr/bin/env bash # klevstul echo "<< 99_deploy.sh >>" 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 options_url=https://git.mz.fo/fro/lnx-arch/raw/branch/master/dots/archinstall/${HOSTNAME}/options.sh options_trg=/tmp/options.sh rm -rf ${options_trg} rm -rf ${options_trg}.tmp wget -q ${options_url} -O ${options_trg} source ${options_trg} if [ -z "${OPTIONS_LOADED}" ]; then echo "error: unable to load options" exit 1 fi user=${USER} clone_trg=${CLONE_TARGET_DIR} # ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ # 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 _recursive=$4 file_name=$(basename ${_trg_path}) echo "" echo "${file_name}:" # -f (--force): overwrite without confirmation cp --force --recursive ${_src_path} ${_trg_path} # only chown if _no_chown variable is empty if [[ ${_no_chown} != "no_chown" ]] ; then # if the target path ends with a slash, we have a directory if [[ "$_trg_path" == */ ]] then echo "(ignore potential \"chown: cannot access\" error, which will occur if there are no dot-files in the directory)" if [[ ${_recursive} != "recursive" ]] ; then # https://serverfault.com/questions/156437/how-to-chown-a-directory-recursively-including-hidden-files-or-directories chown ${user}:${user} ${_trg_path}* chown ${user}:${user} ${_trg_path}.[^.]* else chown -R ${user}:${user} ${_trg_path}* chown -R ${user}:${user} ${_trg_path}.[^.]* fi else chown ${user}:${user} ${_trg_path} fi fi suffix=".sh" if [[ ${file_name} == *$suffix ]] ; then chmod 755 ${_trg_path}/*.sh elif [[ ${file_name} == "bin" ]] ; then chmod 755 ${_trg_path}/* fi ls -al ${_trg_path} } # locate firefox's profile directory firefox_profile_dir() { ffdir=/home/${user}/.mozilla/firefox/ if ! [ -d "$ffdir" ] then echo "error: firefox main directory not found: '${ffdir}'" else pattern=".default-release" old_dir=`pwd` cd ${ffdir} for _dir in *"${pattern}"*; do [ -d "${_dir}" ] && dir="${_dir}" && break done cd ${old_dir} if [ -z "$dir" ] then echo "error: firefox profile directory not found" else ffprofiledir=${ffdir}${dir} echo "${ffprofiledir}" fi fi } # ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ # dots (dot files) if [ ${operation} == "dots" ] ; then # declarations targz_dots_url=https://git.mz.fo/fro/lnx-arch/archive/master.tar.gz dots_trg=${clone_trg}/lnx-arch/dots echo "***** ${operation} *****" rm -rf ${clone_trg}/lnx-arch download_repo ${targz_dots_url} tree ${clone_trg}/lnx-arch # ---------- # system # ---------- # bashrc file_name=.bashrc file_path=/home/${user} deploy_file "${dots_trg}/bash/${file_name}" "${file_path}/${file_name}" # bin (executable binaries, scripts) file_path=/usr/local/bin deploy_file "${dots_trg}/bin/*" "${file_path}/" # environment file_name=environment file_path=/etc deploy_file "${dots_trg}/environment/${file_name}" "${file_path}/${file_name}" no_chown # ---------- # programs # ---------- # firefox file_name=policies.json file_path=/usr/lib/firefox/distribution deploy_file "${dots_trg}/firefox/${file_name}" "${file_path}/${file_name}" no_chown ffpd=$(firefox_profile_dir) if [[ ${ffpd} == error* ]] ; then echo ${ffpd} else file_name=user.js file_path=${ffpd} deploy_file "${dots_trg}/firefox/${file_name}" "${file_path}/${file_name}" file_name=userChrome.css file_path=${ffpd}/chrome mkdir -p ${file_path} deploy_file "${dots_trg}/firefox/${file_name}" "${file_path}/${file_name}" fi # pcmanfm file_name=pcmanfm.conf file_path=/home/${user}/.config/pcmanfm/default mkdir -p ${file_path} deploy_file "${dots_trg}/vscodium/${file_name}" "${file_path}/${file_name}" # vscodium file_name=settings.json file_path=/home/${user}/.config/VSCodium/User mkdir -p ${file_path} deploy_file "${dots_trg}/vscodium/${file_name}" "${file_path}/${file_name}" # https://vscodethemes.com/e/sdras.night-owl/night-owl-no-italics?language=javascript # https://github.com/sdras/night-owl-vscode-theme/tree/main/themes file_name=sdras.night-owl-2.0.1-universal file_path=/home/${user}/.vscode-oss/extensions mkdir -p ${file_path} deploy_file "${dots_trg}/vscodium/${file_name}" "${file_path}/" chown recursive # i3wm if [ ${I3WM} == "true" ] ; then # i3 file_name=config file_path=/home/${user}/.config/i3 mkdir -p ${file_path} deploy_file "${dots_trg}/i3wm/${file_name}" "${file_path}/" fi if [ ${I3WM} == "true" ] || [ ${QTILE} == "true" ] ; then # xorg file_path=/home/${user} deploy_file "${dots_trg}/xorg/.*" "${file_path}/" fi fi # dots+ (wallpapers, fonts ++) if [ ${operation} == "dots+" ] ; then # declarations targz_dotsplus_url=https://gitlab.com/pqq/dotsplus/-/archive/main/dotsplus-main.tar.gz dotsplus_trg=${clone_trg}/dotsplus-main echo "***** ${operation} *****" rm -rf ${dotsplus_trg} download_repo ${targz_dotsplus_url} tree ${clone_trg} # ---------- # fonts # ---------- file_path=/home/${user}/.local/share/fonts mkdir -p ${file_path} deploy_file "${dotsplus_trg}/fonts/install/*" "${file_path}/" # ---------- # wallpapers # ---------- file_path=/home/${user}/.local/share/wp mkdir -p ${file_path} deploy_file "${dotsplus_trg}/wallpapers/install/*" "${file_path}/" fi