Files
lnx-arch/scripts/99_deploy.sh

442 lines
13 KiB
Bash
Raw Normal View History

2024-04-30 07:40:24 -05:00
#!/usr/bin/env bash
# klevstul
2024-04-30 21:34:49 -05:00
echo "<< 99_deploy.sh >>"
2024-04-30 07:40:24 -05:00
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
2024-05-11 20:00:35 -05:00
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
2024-05-31 13:05:30 -05:00
wget --no-check-certificate -q ${options_url} -O ${options_trg}
2024-05-11 20:00:35 -05:00
source ${options_trg}
2024-05-11 19:42:05 -05:00
if [ -z "${OPTIONS_LOADED}" ]; then
echo "error: unable to load options"
exit 1
fi
# load values found in options.sh file, sourced above
system_user=${SYSTEM_USER}
clone_trg=${CLONE_TARGET_DIR}
2024-05-21 07:09:24 -05:00
if [[ -z "${clone_trg}" ]] ; then
echo "error: CLONE_TARGET_DIR is empty"
exit 1
fi
2024-05-21 10:18:51 -05:00
secrets_cred_path=/home/${system_user}/syncDir/secrets/toBeSourced/cred.sh
2024-05-21 07:00:18 -05:00
source ${secrets_cred_path}
2024-05-11 19:42:05 -05:00
2024-04-30 07:40:24 -05:00
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
2024-04-30 21:01:05 -05:00
# helper functions
2024-04-30 07:40:24 -05:00
download_repo() {
2024-04-30 20:29:46 -05:00
_targz_url=$1
2024-04-30 07:40:24 -05:00
# 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.
2024-05-31 13:05:30 -05:00
wget --no-check-certificate --show-progress ${_targz_url} -O ${clone_trg}/tmp.tar.gz
2024-04-30 07:40:24 -05:00
tar -xzf ${clone_trg}/tmp.tar.gz -C ${clone_trg}
rm ${clone_trg}/tmp.tar.gz
}
2024-04-30 21:44:25 -05:00
create_dir() {
_directory=$1
2024-08-27 15:47:05 -05:00
echo "<!> _directory: '${_directory}'"
2024-08-27 15:45:38 -05:00
2024-08-25 19:25:13 -05:00
runuser -l ${system_user} -c 'mkdir -p ${_directory}'
2024-08-25 19:17:32 -05:00
2024-08-25 19:25:13 -05:00
#mkdir -p ${_directory}
#chown ${system_user}:${system_user} ${_directory}
2024-04-30 21:44:25 -05:00
}
2024-04-30 21:01:05 -05:00
deploy_file() {
_src_path=$1
_trg_path=$2
2024-05-03 12:54:11 -05:00
_no_chown=$3
2024-05-15 07:30:46 -05:00
_recursive=$4
2024-04-30 21:01:05 -05:00
2024-05-15 17:24:07 -05:00
if [[ "$_trg_path" == *.zip ]] ; then
2024-05-15 17:23:37 -05:00
file_name_src=$(basename ${_src_path})
fi
2024-05-15 17:10:45 -05:00
file_name_trg=$(basename ${_trg_path})
2024-05-04 17:11:11 -05:00
echo ""
2024-05-15 17:10:45 -05:00
echo "${file_name_trg}:"
2024-05-04 17:11:11 -05:00
2024-08-27 14:36:30 -05:00
suffix1=".zip"
suffix=".tar.xz"
if [[ ${file_name_src} == *$suffix1 ]] ; then
2024-05-15 17:16:11 -05:00
# -o: overwrite without prompting
2024-08-27 15:40:35 -05:00
echo "_src_path: ${_src_path}"
echo "_trg_path: ${_trg_path}"
2024-05-15 17:16:11 -05:00
unzip -o ${_src_path} -d ${_trg_path}
2024-08-27 14:36:30 -05:00
elif [[ ${file_name_src} == *$suffix2 ]] ; then
2024-08-27 15:44:13 -05:00
echo "<!> TARING!"
# tar -xf ${_src_path} -C ${_trg_path}
2024-05-15 17:00:57 -05:00
else
2024-08-27 15:44:13 -05:00
echo "<!> COPYING!"
2024-05-15 17:00:57 -05:00
# -f (--force): overwrite without confirmation
cp --force --recursive ${_src_path} ${_trg_path}
fi
2024-04-30 21:14:23 -05:00
2024-08-25 19:17:32 -05:00
# chown by default
2024-05-15 07:30:46 -05:00
if [[ ${_no_chown} != "no_chown" ]] ; then
2024-05-09 20:07:59 -05:00
# if the target path ends with a slash, we have a directory
2024-05-09 20:03:27 -05:00
if [[ "$_trg_path" == */ ]]
then
2024-05-09 20:40:02 -05:00
echo "(ignore potential \"chown: cannot access\" error, which will occur if there are no dot-files in the directory)"
2024-05-15 07:30:46 -05:00
if [[ ${_recursive} != "recursive" ]] ; then
# https://serverfault.com/questions/156437/how-to-chown-a-directory-recursively-including-hidden-files-or-directories
chown ${system_user}:${system_user} ${_trg_path}*
chown ${system_user}:${system_user} ${_trg_path}.[^.]*
2024-05-15 07:30:46 -05:00
else
chown -R ${system_user}:${system_user} ${_trg_path}*
chown -R ${system_user}:${system_user} ${_trg_path}.[^.]*
2024-05-15 07:30:46 -05:00
fi
2024-05-09 20:07:59 -05:00
else
chown ${system_user}:${system_user} ${_trg_path}
2024-05-09 20:03:27 -05:00
fi
2024-05-03 12:54:11 -05:00
fi
2024-04-30 21:49:15 -05:00
2024-04-30 21:52:09 -05:00
suffix=".sh"
2024-05-15 17:10:45 -05:00
if [[ ${file_name_trg} == *$suffix ]] ; then
2024-05-11 22:23:14 -05:00
chmod 755 ${_trg_path}/*.sh
2024-05-15 17:10:45 -05:00
elif [[ ${file_name_trg} == "bin" ]] ; then
2024-05-11 22:24:25 -05:00
chmod 755 ${_trg_path}/*
2024-05-19 21:49:24 -05:00
elif [[ ${file_name_trg} == "wms" ]] ; then
chmod 755 ${_trg_path}/*
2024-04-30 21:52:09 -05:00
fi
2024-04-30 21:01:05 -05:00
ls -al ${_trg_path}
}
2024-05-12 14:14:13 -05:00
# locate firefox's profile directory
2024-05-03 15:42:24 -05:00
firefox_profile_dir() {
ffdir=/home/${system_user}/.mozilla/firefox/
2024-05-03 15:50:14 -05:00
2024-05-03 15:51:45 -05:00
if ! [ -d "$ffdir" ]
2024-05-03 15:42:24 -05:00
then
2024-05-03 16:03:41 -05:00
echo "error: firefox main directory not found: '${ffdir}'"
2024-05-03 15:42:24 -05:00
else
2024-05-03 15:50:14 -05:00
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
2024-05-03 16:02:00 -05:00
echo "error: firefox profile directory not found"
2024-05-03 15:50:14 -05:00
else
ffprofiledir=${ffdir}${dir}
echo "${ffprofiledir}"
fi
2024-05-03 15:42:24 -05:00
fi
}
2024-04-30 22:02:09 -05:00
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
2024-04-30 07:40:24 -05:00
2024-05-01 11:15:00 -05:00
# dots (dot files)
2024-04-30 20:29:46 -05:00
if [ ${operation} == "dots" ] ; then
2024-05-01 11:15:00 -05:00
2024-05-04 16:20:52 -05:00
# declarations
targz_dots_url=https://git.mz.fo/fro/lnx-arch/archive/master.tar.gz
dots_trg=${clone_trg}/lnx-arch/dots
2024-04-30 07:40:24 -05:00
echo "***** ${operation} *****"
2024-05-01 11:08:34 -05:00
rm -rf ${clone_trg}/lnx-arch
2024-04-30 20:34:33 -05:00
download_repo ${targz_dots_url}
2024-04-30 07:40:24 -05:00
tree ${clone_trg}/lnx-arch
2024-05-04 13:32:09 -05:00
# ----------
# system
# ----------
2024-06-10 11:00:47 -05:00
# applications
file_path=/usr/share/applications
deploy_file "${dots_trg}/applications/*" "${file_path}/"
2024-05-03 13:52:41 -05:00
# bashrc
file_name=.bashrc
file_path=/home/${system_user}
2024-05-03 13:52:41 -05:00
deploy_file "${dots_trg}/bash/${file_name}" "${file_path}/${file_name}"
2024-05-03 12:54:11 -05:00
# bin (executable binaries, scripts)
file_path=/usr/local/bin
2024-05-03 14:02:20 -05:00
deploy_file "${dots_trg}/bin/*" "${file_path}/"
2024-05-03 12:54:11 -05:00
2024-05-03 13:01:11 -05:00
# environment
2024-05-03 13:02:07 -05:00
file_name=environment
2024-05-03 13:01:11 -05:00
file_path=/etc
2024-05-03 13:02:07 -05:00
deploy_file "${dots_trg}/environment/${file_name}" "${file_path}/${file_name}" no_chown
2024-05-21 07:00:18 -05:00
# mounts
file_name=mnt-nas.mount
2024-05-21 07:07:56 -05:00
file_path=/etc/systemd/system
deploy_file "${dots_trg}/systemd/${file_name}" "${file_path}/${file_name}" no_chown
2024-05-21 21:04:16 -05:00
# sed -i "s|USERNAME|klevstul|g" "${file_path}/${file_name}"
# sed -i "s|PASSWORD|${LILLESORTEBOKS}|g" "${file_path}/${file_name}"
2024-05-21 07:00:18 -05:00
2024-07-06 12:14:28 -05:00
# pacman
file_name=.makepkg.conf
file_path=/home/${system_user}
deploy_file "${dots_trg}/pacman/${file_name}" "${file_path}/${file_name}"
2024-05-20 21:24:05 -05:00
# ----------
# printing
#
# src:
# - https://wiki.manjaro.org/index.php?title=Printing
# - http://localhost:631/help/admin.html
#
# example (turn the printer on, to see the "usb: value"):
# $ lpinfo -m | grep 'ql700'
# brother_ql700_printer_en.ppd Brother QL-700 CUPS
2024-08-09 15:44:18 -05:00
# $ (sudo) lpinfo -v
2024-05-20 21:24:05 -05:00
# ...
# direct usb://Brother/QL-700?serial=000L0Z530516
# ...
# ----------
2024-05-24 12:57:54 -05:00
file_path=/etc/cups
deploy_file "${dots_trg}/cups/*" "${file_path}/" no_chown
2024-05-24 13:41:49 -05:00
# man page:
# https://www.cups.org/doc/man-lpadmin.html
2024-05-24 14:49:43 -05:00
# current printers:
2024-05-24 12:57:54 -05:00
2024-05-24 14:49:43 -05:00
# Description: Canon MG2500
# Location: NAS
# Driver: Canon MG2500 series Ver.4.00 (color)
2024-05-24 13:41:49 -05:00
# Connection: ipp://192.168.1.222:631/printers/usbprinter
2024-05-24 14:49:43 -05:00
# Defaults: job-sheets=none, none media=iso_a4_210x297mm sides=one-sided
2024-05-24 13:41:49 -05:00
#
# Description: Canon MG2500
2024-05-24 14:49:43 -05:00
# Location: t470p
# Driver: Canon MG2500 series Ver.4.00 (color)
2024-05-24 13:41:49 -05:00
# Connection: usb://Canon/MG2500%20series?serial=FC4F1F&interface=1
2024-05-24 14:49:43 -05:00
# Defaults: job-sheets=none, none media=iso_a4_210x297mm sides=one-sided
2024-05-24 12:57:54 -05:00
2024-05-24 13:41:49 -05:00
# outdated commands:
2024-05-24 14:49:43 -05:00
# -p is an obsolete flag
# lpadmin -p Brother_HL-L2310D_series -D "Brother HL-L2310D_series" -E -v usb://Brother/HL-L2310D%20series?serial=E78096L7N181893 -m lsb/usr/cupsfilters/brother-HLL2310D-cups-en.ppd
# lpadmin -p Brother_QL-700 -D "Brother QL-700" -E -v usb://Brother/QL-700?serial=000L0Z530516 -m brother_ql700_printer_en.ppd
2024-05-20 21:24:05 -05:00
2024-05-21 07:00:18 -05:00
# EXAMPLE OF FILE MANIPULATION (from lnxPub's `cli/2103mjr/scr/80_urxvt.sh`)
# # -----
# # update .Xresources
# # -----
# file=$HOME/.Xresources
#
# # update font setting (so it's understandable by the extension)
# /tmp/99_key_value_modifier.sh URxvt.font xft:NotoSansMono-Light:size=12 : $file
#
# # enable the "resize-font" extension
# /tmp/99_comment_add_remove.sh remove ! Rxvt.perl-ext-common $file
# /tmp/99_key_value_modifier.sh Rxvt.perl-ext-common resize-font : $file
#
# # make the terminal's background transparent
# /tmp/99_comment_add_remove.sh remove '! ' 'URxvt\*inheritPixmap' $file
# /tmp/99_comment_add_remove.sh remove '! ' 'URxvt\*transparent' $file
# /tmp/99_comment_add_remove.sh remove '! ' 'URxvt\*shading' $file
# /tmp/99_key_value_modifier.sh 'URxvt\*shading' 30 : $file
2024-05-04 13:32:09 -05:00
# ----------
# programs
# ----------
2024-05-26 07:45:23 -05:00
# dunst
file_name=dunstrc
file_path=/home/${system_user}/.config/dunst
2024-08-25 19:21:29 -05:00
create_dir ${file_path}
2024-05-26 07:45:23 -05:00
deploy_file "${dots_trg}/dunst/${file_name}" "${file_path}/${file_name}"
2024-05-20 21:14:06 -05:00
# lf
file_name=lfrc
file_path=/home/${system_user}/.config/lf
2024-08-25 19:21:29 -05:00
create_dir ${file_path}
2024-05-20 21:14:06 -05:00
deploy_file "${dots_trg}/lf/${file_name}" "${file_path}/${file_name}"
2024-05-03 15:42:24 -05:00
# firefox
file_name=policies.json
file_path=/usr/lib/firefox/distribution
2024-05-03 16:06:21 -05:00
deploy_file "${dots_trg}/firefox/${file_name}" "${file_path}/${file_name}" no_chown
2024-05-03 15:42:24 -05:00
2024-05-03 15:58:29 -05:00
ffpd=$(firefox_profile_dir)
2024-05-03 16:04:14 -05:00
if [[ ${ffpd} == error* ]] ; then
2024-05-03 16:02:00 -05:00
echo ${ffpd}
else
2024-05-04 17:08:00 -05:00
file_name=user.js
2024-05-03 16:04:58 -05:00
file_path=${ffpd}
deploy_file "${dots_trg}/firefox/${file_name}" "${file_path}/${file_name}"
file_name=userChrome.css
file_path=${ffpd}/chrome
2024-08-25 19:21:29 -05:00
create_dir ${file_path}
2024-05-03 16:04:58 -05:00
deploy_file "${dots_trg}/firefox/${file_name}" "${file_path}/${file_name}"
2024-05-03 16:02:00 -05:00
fi
2024-05-03 15:42:24 -05:00
2024-05-16 05:43:21 -05:00
# gtk (settings found using lxappearance)
2024-05-16 06:02:53 -05:00
# note that the bookmarks file were found in two different locations, so a
# symlink is created below. as well, ".gtkrc-2.0.mine" had no effect, so
# ".gtkrc-2.0" is overwritten
2024-05-15 13:01:55 -05:00
file_name=settings.ini
file_path=/home/${system_user}/.config/gtk-3.0
2024-08-25 19:21:29 -05:00
create_dir ${file_path}
2024-05-15 13:01:55 -05:00
deploy_file "${dots_trg}/gtk/${file_name}" "${file_path}/${file_name}"
2024-05-16 05:43:21 -05:00
file_name=.gtk-bookmarks
file_path=/home/${system_user}
2024-05-16 05:43:21 -05:00
deploy_file "${dots_trg}/gtk/${file_name}" "${file_path}/${file_name}"
tmp_file_path_full="/home/${system_user}/.config/gtk-3.0/bookmarks"
2024-05-16 05:43:21 -05:00
trash-put ${tmp_file_path_full}
ln -s "${file_path}/${file_name}" "${tmp_file_path_full}"
file_name=.gtkrc-2.0
file_path=/home/${system_user}
2024-05-16 05:47:21 -05:00
deploy_file "${dots_trg}/gtk/${file_name}" "${file_path}/${file_name}"
2024-06-26 10:52:22 -05:00
2024-05-21 21:46:39 -05:00
file_name=index.theme
file_path=/home/${system_user}/.icons/default
2024-08-25 19:21:29 -05:00
create_dir ${file_path}
2024-05-21 21:46:39 -05:00
deploy_file "${dots_trg}/gtk/${file_name}" "${file_path}/${file_name}"
2024-06-26 10:53:26 -05:00
# helix
file_name=config.toml
file_path=/home/${system_user}/.config/helix
deploy_file "${dots_trg}/helix/${file_name}" "${file_path}/${file_name}"
2024-05-19 21:05:48 -05:00
# nitrogen
file_path=/home/${system_user}/.config/nitrogen
2024-08-25 19:21:29 -05:00
create_dir ${file_path}
2024-05-19 21:05:48 -05:00
deploy_file "${dots_trg}/nitrogen/*" "${file_path}/"
2024-05-15 06:54:28 -05:00
# pcmanfm
2024-05-16 06:02:53 -05:00
# bookmarks found in "dots/gtk/.gtk-bookmarks"
2024-05-15 06:54:28 -05:00
file_name=pcmanfm.conf
file_path=/home/${system_user}/.config/pcmanfm/default
2024-08-25 19:21:29 -05:00
create_dir ${file_path}
2024-05-15 17:32:01 -05:00
deploy_file "${dots_trg}/pcmanfm/${file_name}" "${file_path}/${file_name}"
2024-05-15 06:54:28 -05:00
2024-05-14 08:56:48 -05:00
# vscodium
file_name=settings.json
file_path=/home/${system_user}/.config/VSCodium/User
2024-08-25 19:21:29 -05:00
create_dir ${file_path}
2024-05-14 08:56:48 -05:00
deploy_file "${dots_trg}/vscodium/${file_name}" "${file_path}/${file_name}"
2024-05-11 20:47:34 -05:00
# i3wm
2024-05-11 20:12:01 -05:00
if [ ${I3WM} == "true" ] ; then
2024-05-11 20:47:34 -05:00
# i3
file_name=config
file_path=/home/${system_user}/.config/i3
2024-08-25 19:21:29 -05:00
create_dir ${file_path}
2024-05-11 21:14:05 -05:00
deploy_file "${dots_trg}/i3wm/${file_name}" "${file_path}/"
2024-05-11 20:47:34 -05:00
2024-05-20 14:21:32 -05:00
# i3status
file_name=config
file_path=/home/${system_user}/.config/i3status
2024-08-25 19:21:29 -05:00
create_dir ${file_path}
2024-05-20 14:21:32 -05:00
deploy_file "${dots_trg}/i3status/${file_name}" "${file_path}/"
2024-05-11 20:12:01 -05:00
fi
if [ ${I3WM} == "true" ] || [ ${QTILE} == "true" ] ; then
# xorg
file_path=/home/${system_user}
2024-05-11 20:12:01 -05:00
deploy_file "${dots_trg}/xorg/.*" "${file_path}/"
2024-08-26 08:03:20 -05:00
chmod 755 ${file_path}/.xinitrc
2024-05-11 20:12:01 -05:00
fi
2024-05-09 19:41:43 -05:00
2024-04-30 20:41:12 -05:00
fi
2024-05-04 15:17:19 -05:00
# dots+ (wallpapers, fonts ++)
if [ ${operation} == "dots+" ] ; then
2024-05-01 11:15:00 -05:00
2024-05-04 16:20:52 -05:00
# declarations
targz_dotsplus_url=https://gitlab.com/pqq/dotsplus/-/archive/main/dotsplus-main.tar.gz
dotsplus_trg=${clone_trg}/dotsplus-main
2024-04-30 20:41:12 -05:00
echo "***** ${operation} *****"
2024-05-04 16:20:52 -05:00
rm -rf ${dotsplus_trg}
2024-05-04 13:59:42 -05:00
download_repo ${targz_dotsplus_url}
2024-05-04 16:20:52 -05:00
tree ${clone_trg}
2024-05-04 13:59:42 -05:00
# ----------
# fonts
# ----------
file_path=/home/${system_user}/.local/share/fonts
2024-08-27 15:44:13 -05:00
echo "<!> 1"
2024-08-25 19:21:29 -05:00
create_dir ${file_path}
2024-08-27 15:44:13 -05:00
echo "<!> 2"
2024-05-04 15:23:28 -05:00
deploy_file "${dotsplus_trg}/fonts/install/*" "${file_path}/"
2024-05-04 13:59:42 -05:00
2024-05-19 17:35:37 -05:00
# ----------
# images
# ----------
file_path=/home/${system_user}/.local/share/img
2024-08-25 19:21:29 -05:00
create_dir ${file_path}
2024-05-19 17:35:37 -05:00
deploy_file "${dotsplus_trg}/images/*" "${file_path}/"
2024-05-04 13:59:42 -05:00
# ----------
# wallpapers
# ----------
file_path=/home/${system_user}/.local/share/wp
2024-08-25 19:21:29 -05:00
create_dir ${file_path}
2024-05-11 21:18:27 -05:00
deploy_file "${dotsplus_trg}/wallpapers/install/*" "${file_path}/"
2024-04-30 21:06:41 -05:00
2024-05-15 07:37:55 -05:00
# ----------
# miscelanneous
# ----------
# vscodium theme
# https://vscodethemes.com/e/sdras.night-owl/night-owl-no-italics?language=javascript
# https://github.com/sdras/night-owl-vscode-theme/tree/main/themes
2024-05-15 17:13:52 -05:00
file_name=night-owl-vscode-theme-main.zip
file_path=/home/${system_user}/.vscode-oss/extensions
2024-08-25 19:21:29 -05:00
create_dir ${file_path}
2024-05-15 07:37:55 -05:00
deploy_file "${dotsplus_trg}/miscellaneous/${file_name}" "${file_path}/" chown recursive
2024-05-15 17:00:57 -05:00
# sweet dark gtk theme
# https://github.com/EliverLara/Sweet
# https://github.com/EliverLara/Sweet/releases
2024-08-27 14:36:30 -05:00
file_name=Sweet-Dark.tar.xz
2024-05-15 17:00:57 -05:00
file_path=/usr/share/themes
deploy_file "${dotsplus_trg}/miscellaneous/${file_name}" "${file_path}/" chown recursive
2024-05-15 07:37:55 -05:00
2024-06-06 10:46:44 -05:00
# ----------
# chowning
# ----------
share_dir=/home/${system_user}/.local/share
chown ${system_user}:${system_user} ${share_dir}
chown ${system_user}:${system_user} ${share_dir}/*
2024-04-30 07:40:24 -05:00
fi