Files
lnx-arch/scripts/99_deploy.sh

412 lines
12 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
wget -q ${options_url} -O ${options_trg}
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
secrets_cred_path=/home/${system_user}/syncDir/secrets/toBeSources/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-04-30 20:29:46 -05:00
wget --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
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-05-15 17:00:57 -05:00
suffix=".zip"
2024-05-15 17:10:45 -05:00
if [[ ${file_name_src} == *$suffix ]] ; then
2024-05-15 17:16:11 -05:00
# -o: overwrite without prompting
unzip -o ${_src_path} -d ${_trg_path}
2024-05-15 17:00:57 -05:00
else
# -f (--force): overwrite without confirmation
cp --force --recursive ${_src_path} ${_trg_path}
fi
2024-04-30 21:14:23 -05:00
2024-05-03 12:54:11 -05:00
# only chown if _no_chown variable is empty
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-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
2024-05-21 07:11:24 -05:00
trash-put ${file_path}/${file_name}
2024-05-21 07:07:56 -05:00
deploy_file "${dots_trg}/systemd/${file_name}" "${file_path}/${file_name}" no_chown
2024-05-21 07:26:24 -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:07:56 -05:00
#mount_target=/mnt/nas
#mkdir -p ${mount_target}
2024-05-21 07:00:18 -05:00
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
# $ lpinfo -v
# ...
# direct usb://Brother/QL-700?serial=000L0Z530516
# ...
# ----------
#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-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-20 21:14:06 -05:00
# lf
file_name=lfrc
file_path=/home/${system_user}/.config/lf
2024-05-20 21:16:01 -05:00
mkdir -p ${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-05-04 17:20:50 -05:00
mkdir -p ${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-05-15 13:01:55 -05:00
mkdir -p ${file_path}
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-05-16 05:43:21 -05:00
2024-05-19 21:05:48 -05:00
# nitrogen
file_path=/home/${system_user}/.config/nitrogen
2024-05-21 07:20:42 -05:00
mkdir -p ${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-05-15 06:54:28 -05:00
mkdir -p ${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-05-14 08:58:52 -05:00
mkdir -p ${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-05-11 20:47:34 -05:00
mkdir -p ${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-05-20 14:21:32 -05:00
mkdir -p ${file_path}
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-05-19 17:16:52 -05:00
# lemurs (display/login manager)
2024-05-19 22:07:06 -05:00
file_name_src=.xinitrc
file_name_trg=i3
file_path_src=/home/${system_user}
2024-05-20 06:22:05 -05:00
file_path_trg=/etc/lemurs/wms
2024-05-20 06:22:52 -05:00
if [ -f ${file_path_trg}/${file_name_trg} ] ; then
2024-05-19 21:56:27 -05:00
echo ""
2024-05-19 22:07:06 -05:00
echo "softlink already exists: ${file_path}/${file_name_trg}"
2024-05-20 06:23:51 -05:00
ls -al ${file_path_trg}
2024-05-19 21:56:27 -05:00
else
echo ""
2024-05-20 06:22:05 -05:00
echo "creating soft link: ${file_path_src}/${file_name_src}${file_path_trg}/${file_name_trg}"
ln -s ${file_path_src}/${file_name_src} ${file_path_trg}/${file_name_trg}
chown -h ${system_user}:${system_user} ${file_path_trg}/${file_name_trg}
2024-05-20 06:22:05 -05:00
ls -al ${file_path_trg}
2024-05-19 21:56:27 -05:00
fi
2024-05-19 17:10:15 -05:00
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-05-04 13:59:42 -05:00
mkdir -p ${file_path}
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-05-19 17:35:37 -05:00
mkdir -p ${file_path}
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-05-11 21:18:27 -05:00
mkdir -p ${file_path}
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-05-15 07:37:55 -05:00
mkdir -p ${file_path}
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
file_name=Sweet-Dark.zip
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-04-30 07:40:24 -05:00
fi