473 lines
15 KiB
Bash
Executable File
473 lines
15 KiB
Bash
Executable File
#!/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://gt.op.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 --no-check-certificate -q ${options_url} -O ${options_trg}
|
|
source ${options_trg}
|
|
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}
|
|
if [[ -z "${clone_trg}" ]] ; then
|
|
echo "error: CLONE_TARGET_DIR is empty"
|
|
exit 1
|
|
fi
|
|
|
|
secrets_cred_path=/home/${system_user}/syncDir/secrets/toBeSourced/cred.sh
|
|
source ${secrets_cred_path}
|
|
|
|
# ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
|
|
|
|
# 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 --no-check-certificate --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_command="mkdir -p \"${_directory}\""
|
|
runuser -l ${system_user} -c '${mkdir_command}'
|
|
|
|
if ! [ -d "$_directory" ]
|
|
then
|
|
echo ""
|
|
echo "error: unable to create the directory '${_directory}'"
|
|
echo " command:"
|
|
echo " runuser -l ${system_user} -c '${mkdir_command}'"
|
|
echo "will try creating the directory as root, and changing owner"
|
|
|
|
mkdir -p "${_directory}"
|
|
sudo chown -R ${system_user}:${system_user} "${_directory}"
|
|
|
|
if [ -d "$_directory" ]
|
|
then
|
|
echo "success!"
|
|
else
|
|
echo "failure! directory could not be created."
|
|
fi
|
|
fi
|
|
}
|
|
|
|
deploy_file() {
|
|
_src_path=$1
|
|
_trg_path=$2
|
|
_no_chown=$3
|
|
_recursive=$4
|
|
|
|
if [[ "$_src_path" == *.zip ]] || [[ "$_src_path" == *.tar.xz ]] ; then
|
|
file_name_src=$(basename ${_src_path})
|
|
fi
|
|
|
|
file_name_trg=$(basename ${_trg_path})
|
|
echo ""
|
|
echo "${file_name_trg}:"
|
|
|
|
suffix1=".zip"
|
|
suffix2=".tar.xz"
|
|
if [[ ${file_name_src} == *$suffix1 ]] ; then
|
|
echo "unzipping '${_src_path}'"
|
|
# -o: overwrite without prompting
|
|
unzip -o ${_src_path} -d ${_trg_path}
|
|
elif [[ ${file_name_src} == *$suffix2 ]] ; then
|
|
echo "un-taring '${_src_path}'"
|
|
tar -xf ${_src_path} -C ${_trg_path}
|
|
else
|
|
echo "copying '${_src_path}' to '${_trg_path}'"
|
|
# -f (--force): overwrite without confirmation
|
|
cp --force --recursive ${_src_path} ${_trg_path}
|
|
fi
|
|
|
|
# chown by default
|
|
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 ${system_user}:${system_user} ${_trg_path}*
|
|
chown ${system_user}:${system_user} ${_trg_path}.[^.]*
|
|
else
|
|
chown -R ${system_user}:${system_user} ${_trg_path}*
|
|
chown -R ${system_user}:${system_user} ${_trg_path}.[^.]*
|
|
fi
|
|
else
|
|
chown ${system_user}:${system_user} ${_trg_path}
|
|
fi
|
|
fi
|
|
|
|
suffix=".sh"
|
|
if [[ ${file_name_trg} == *$suffix ]] ; then
|
|
chmod 755 ${_trg_path}/*.sh
|
|
elif [[ ${file_name_trg} == "bin" ]] ; then
|
|
chmod 755 ${_trg_path}/*
|
|
elif [[ ${file_name_trg} == "wms" ]] ; then
|
|
chmod 755 ${_trg_path}/*
|
|
fi
|
|
|
|
ls -al ${_trg_path}
|
|
}
|
|
|
|
# locate firefox's profile directory
|
|
firefox_profile_dir() {
|
|
ffdir=/home/${system_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://gt.op.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
|
|
# ----------
|
|
|
|
# applications
|
|
file_path=/usr/share/applications
|
|
deploy_file "${dots_trg}/applications/*" "${file_path}/"
|
|
|
|
# bashrc
|
|
file_name=.bashrc
|
|
file_path=/home/${system_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
|
|
|
|
# mounts
|
|
file_name=mnt-nas.mount
|
|
file_path=/etc/systemd/system
|
|
deploy_file "${dots_trg}/systemd/${file_name}" "${file_path}/${file_name}" no_chown
|
|
# sed -i "s|USERNAME|klevstul|g" "${file_path}/${file_name}"
|
|
# sed -i "s|PASSWORD|${LILLESORTEBOKS}|g" "${file_path}/${file_name}"
|
|
|
|
# pacman
|
|
file_name=.makepkg.conf
|
|
file_path=/home/${system_user}
|
|
deploy_file "${dots_trg}/pacman/${file_name}" "${file_path}/${file_name}"
|
|
|
|
# ssh
|
|
file_name=config
|
|
file_path=/home/${system_user}/.ssh
|
|
deploy_file "${dots_trg}/ssh/${file_name}" "${file_path}/${file_name}"
|
|
|
|
# ----------
|
|
# 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
|
|
# $ (sudo) lpinfo -v
|
|
# ...
|
|
# direct usb://Brother/QL-700?serial=000L0Z530516
|
|
# ...
|
|
# ----------
|
|
|
|
file_path=/etc/cups
|
|
deploy_file "${dots_trg}/cups/*" "${file_path}/" no_chown
|
|
|
|
# man page:
|
|
# https://www.cups.org/doc/man-lpadmin.html
|
|
|
|
# current printers:
|
|
|
|
# Description: Canon MG2500
|
|
# Location: NAS
|
|
# Driver: Canon MG2500 series Ver.4.00 (color)
|
|
# Connection: ipp://192.168.1.222:631/printers/usbprinter
|
|
# Defaults: job-sheets=none, none media=iso_a4_210x297mm sides=one-sided
|
|
#
|
|
# Description: Canon MG2500
|
|
# Location: t470p
|
|
# Driver: Canon MG2500 series Ver.4.00 (color)
|
|
# Connection: usb://Canon/MG2500%20series?serial=FC4F1F&interface=1
|
|
# Defaults: job-sheets=none, none media=iso_a4_210x297mm sides=one-sided
|
|
|
|
# outdated commands:
|
|
# -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
|
|
|
|
|
|
# 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
|
|
|
|
|
|
# ----------
|
|
# programs
|
|
# ----------
|
|
|
|
# cava
|
|
file_name=config
|
|
file_path=/home/${system_user}/.config/cava
|
|
create_dir ${file_path}
|
|
deploy_file "${dots_trg}/cava/${file_name}" "${file_path}/${file_name}"
|
|
|
|
## dbgate
|
|
#file_name=settings.json
|
|
#file_path=/home/${system_user}/.dbgate
|
|
#create_dir ${file_path}
|
|
#deploy_file "${dots_trg}/dbgate/${file_name}" "${file_path}/${file_name}"
|
|
#cp /home/${system_user}/syncDir/secrets/dbgate/connections.jsonl ${file_path}/
|
|
#chown ${system_user}:${system_user} ${file_path}/connections.jsonl
|
|
|
|
# dunst
|
|
file_name=dunstrc
|
|
file_path=/home/${system_user}/.config/dunst
|
|
create_dir ${file_path}
|
|
deploy_file "${dots_trg}/dunst/${file_name}" "${file_path}/${file_name}"
|
|
|
|
# lf
|
|
file_name=lfrc
|
|
file_path=/home/${system_user}/.config/lf
|
|
create_dir ${file_path}
|
|
deploy_file "${dots_trg}/lf/${file_name}" "${file_path}/${file_name}"
|
|
|
|
# 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}"
|
|
# https://stackoverflow.com/questions/525592/find-and-replace-inside-a-text-file-from-a-bash-command
|
|
# https://askubuntu.com/questions/76808/how-do-i-use-variables-in-a-sed-command
|
|
sed -i -e "s/{HOSTNAME}/${HOSTNAME}/g" "${file_path}/${file_name}"
|
|
|
|
file_name=userChrome.css
|
|
file_path=${ffpd}/chrome
|
|
create_dir ${file_path}
|
|
deploy_file "${dots_trg}/firefox/${file_name}" "${file_path}/${file_name}"
|
|
fi
|
|
|
|
# gtk (settings found using lxappearance)
|
|
# 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
|
|
file_name=settings.ini
|
|
file_path=/home/${system_user}/.config/gtk-3.0
|
|
create_dir ${file_path}
|
|
deploy_file "${dots_trg}/gtk/${file_name}" "${file_path}/${file_name}"
|
|
gsettings set org.gnome.desktop.interface gtk-theme "Sweet-Dark"
|
|
|
|
file_name=.gtk-bookmarks
|
|
file_path=/home/${system_user}
|
|
deploy_file "${dots_trg}/gtk/${file_name}" "${file_path}/${file_name}"
|
|
tmp_file_path_full="/home/${system_user}/.config/gtk-3.0/bookmarks"
|
|
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}
|
|
deploy_file "${dots_trg}/gtk/${file_name}" "${file_path}/${file_name}"
|
|
|
|
file_name=index.theme
|
|
file_path=/home/${system_user}/.icons/default
|
|
create_dir ${file_path}
|
|
deploy_file "${dots_trg}/gtk/${file_name}" "${file_path}/${file_name}"
|
|
|
|
# helix
|
|
file_name=config.toml
|
|
file_path=/home/${system_user}/.config/helix
|
|
create_dir ${file_path}
|
|
deploy_file "${dots_trg}/helix/${file_name}" "${file_path}/${file_name}"
|
|
|
|
# nitrogen
|
|
file_path=/home/${system_user}/.config/nitrogen
|
|
create_dir ${file_path}
|
|
deploy_file "${dots_trg}/nitrogen/*" "${file_path}/"
|
|
|
|
# pcmanfm
|
|
# bookmarks found in "dots/gtk/.gtk-bookmarks"
|
|
file_name=pcmanfm.conf
|
|
file_path=/home/${system_user}/.config/pcmanfm/default
|
|
create_dir ${file_path}
|
|
deploy_file "${dots_trg}/pcmanfm/${file_name}" "${file_path}/${file_name}"
|
|
|
|
# i3wm
|
|
if [ ${I3WM} == "true" ] ; then
|
|
|
|
# i3
|
|
file_name=config
|
|
file_path=/home/${system_user}/.config/i3
|
|
create_dir ${file_path}
|
|
deploy_file "${dots_trg}/i3wm/${file_name}" "${file_path}/"
|
|
|
|
# i3status
|
|
file_name=config
|
|
file_path=/home/${system_user}/.config/i3status
|
|
create_dir ${file_path}
|
|
deploy_file "${dots_trg}/i3status/${file_name}" "${file_path}/"
|
|
|
|
fi
|
|
|
|
if [ ${I3WM} == "true" ] || [ ${QTILE} == "true" ] ; then
|
|
|
|
# xorg
|
|
file_path=/home/${system_user}
|
|
deploy_file "${dots_trg}/xorg/.*" "${file_path}/"
|
|
chmod 755 ${file_path}/.xinitrc
|
|
|
|
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/${system_user}/.local/share/fonts
|
|
create_dir ${file_path}
|
|
deploy_file "${dotsplus_trg}/fonts/install/*" "${file_path}/"
|
|
|
|
# ----------
|
|
# images
|
|
# ----------
|
|
file_path=/home/${system_user}/.local/share/img
|
|
create_dir ${file_path}
|
|
deploy_file "${dotsplus_trg}/images/*" "${file_path}/"
|
|
|
|
# ----------
|
|
# wallpapers
|
|
# ----------
|
|
file_path=/home/${system_user}/.local/share/wp
|
|
create_dir ${file_path}
|
|
deploy_file "${dotsplus_trg}/wallpapers/install/*" "${file_path}/"
|
|
|
|
# ----------
|
|
# 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
|
|
# if a new version is commited, download and rename the following file:
|
|
# https://github.com/sdras/night-owl-vscode-theme/archive/refs/heads/main.zip
|
|
file_name=night-owl-vscode-theme-main.zip
|
|
file_path=/home/${system_user}/.vscode-oss/extensions
|
|
create_dir ${file_path}
|
|
deploy_file "${dotsplus_trg}/miscellaneous/${file_name}" "${file_path}/" chown recursive
|
|
|
|
# sweet dark gtk theme
|
|
# https://github.com/EliverLara/Sweet
|
|
# https://github.com/EliverLara/Sweet/releases
|
|
file_name=Sweet-Dark.tar.xz
|
|
file_path=/usr/share/themes
|
|
deploy_file "${dotsplus_trg}/miscellaneous/${file_name}" "${file_path}/" chown recursive
|
|
|
|
# ----------
|
|
# chowning
|
|
# ----------
|
|
share_dir=/home/${system_user}/.local/share
|
|
chown ${system_user}:${system_user} ${share_dir}
|
|
chown ${system_user}:${system_user} ${share_dir}/*
|
|
|
|
fi
|