dotfiles/install.sh

179 lines
4 KiB
Bash
Raw Normal View History

2018-03-01 09:24:31 +01:00
#!/bin/bash
source colors.sh
2018-03-04 10:07:06 +01:00
source install_init.sh
2018-03-01 09:24:31 +01:00
source tools/mo
echo -e "
############################################
# Welcome to Hiro98s Dotfile Installer #
# It's interactive, so sit back and enjoy. #
############################################"
DOTFILES_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
DOTFILES_TMP=$DOTFILES_DIR/.tmp #TODO remove
2018-03-04 10:49:54 +01:00
DOTDIR="dots"
2018-03-04 10:07:06 +01:00
SCHEME="light"
YES=false
2018-03-01 09:24:31 +01:00
function main {
2018-03-04 10:07:06 +01:00
# extract options and their arguments into variables.
2018-03-23 14:13:52 +01:00
while getopts ":s: :i :y :d: :c:" OPT; do
2018-03-04 10:07:06 +01:00
case $OPT in
2018-03-23 14:13:52 +01:00
c)
2018-11-01 16:15:16 +01:00
CONFIG=$OPTARG
2018-03-23 14:13:52 +01:00
;;
2018-03-04 10:07:06 +01:00
s)
SCHEME=$OPTARG
grey "\n---------> Using color scheme: $SCHEME"
;;
i)
printHeading "Installing initial dependencies!"
installInit
exit
;;
y)
YES=true
;;
2018-03-04 10:49:54 +01:00
d)
DOTDIR=$OPTARG
;;
2018-03-04 10:07:06 +01:00
\?)
2018-03-23 14:13:52 +01:00
echo "Usage $0 [-i -> Initialize] [-s -> Colorscheme] [-c -> config, default: config.sh] [-y] [-d -> dotfile dir, optional]"
2018-03-04 10:07:06 +01:00
exit
;;
esac
done
2018-11-01 16:15:16 +01:00
# load the right config
2019-02-12 13:10:26 +01:00
if [ -z "$CONFIG" ]; then
2018-11-01 16:15:16 +01:00
source $DOTFILES_DIR/config.sh
else
source $CONFIG
fi
2018-03-04 10:07:06 +01:00
2018-03-01 09:24:31 +01:00
mkdir -p $DOTFILES_TMP
2018-03-04 10:49:54 +01:00
2018-03-01 09:24:31 +01:00
printHeading "Creating Color Themes."
setColors $SCHEME
2018-03-03 11:38:33 +01:00
generateGtk
2018-03-01 09:24:31 +01:00
2018-03-04 11:05:59 +01:00
# Wallpaper
printHeading "Install Wallpaper"
ln -svf $DOTFILES_DIR/wallpaper/$SCHEME $HOME/.wallpaper
2018-03-04 10:49:54 +01:00
# Install Stuff
autolink
2019-02-12 13:10:26 +01:00
2022-03-04 15:42:50 +01:00
# if ! [ -z "$SCREEN_LAYOUT" ]; then
# printHeading "Setting up Screens"
# $($SCREEN_LAYOUT)
# fi
2018-03-01 09:24:31 +01:00
# Reload
2018-03-04 10:49:54 +01:00
printHeading "Reloading"
2018-03-04 10:07:06 +01:00
xrdb -load ${HOME}/.Xresources >/dev/null 2>&1
2019-02-12 13:10:26 +01:00
killall -s USR1 xst >/dev/null 2>&1
2018-03-04 10:07:06 +01:00
i3-msg restart >/dev/null 2>&1
gtkrc-reload >/dev/null 2>&1
2018-03-04 11:05:59 +01:00
$HOME/.scripts/wallp
2018-03-01 09:24:31 +01:00
}
## Helpers
SECTION[0]=0
function grey {
echo -e "\e[249m$1"
}
function attention {
printf "\e[36m$1\e[39m"
}
function printImportant {
echo -e "\e[93m\e[4m$1\e[0m"
}
function printHeading {
SECTION[0]=$(expr ${SECTION[0]} + 1)
SECTION[1]=0
echo
printImportant "${SECTION[0]}: $1"
}
function printSubHeading {
SECTION[1]=$(expr ${SECTION[1]} + 1)
echo
printImportant "${SECTION[0]}.${SECTION[1]}: $1"
}
# Re-Link All Function
function linkall {
DIR=$1
INSTALL_PREFIX=$2
printSubHeading "Installing $DOTFILES_DIR/$DIR"
# Create Dir-Struct
DIRS=$(find $DOTFILES_DIR/$DIR -type d | sed -n "s|^${DOTFILES_DIR}/${DIR}/||p")
# Create Base-Dir
2018-09-28 16:42:55 +02:00
grey "Creating Directory: $HOME/$INSTALL_PREFIX"
2018-03-01 09:24:31 +01:00
mkdir -p $HOME/$INSTALL_PREFIX
for d in $DIRS
do
grey "Creating Directory: $HOME/$INSTALL_PREFIX/$d"
mkdir -p $HOME/$INSTALL_PREFIX/$d
done
2018-03-04 10:49:54 +01:00
FILES=$(find $DOTFILES_DIR/$DIR ! -name '.link' ! -name '*~' ! -name '#*' -type f | sed "s~$DOTFILES_DIR/*$DIR/*~~")
2018-03-01 09:24:31 +01:00
for f in $FILES
do
CDIR=$DOTFILES_DIR/$DIR/
# Get Commands
CMD=$(sed -n '/#\$/p' $CDIR/$f | sed -e 's/#\$//g')
2018-03-04 10:07:06 +01:00
if [[ ${f: -9} == ".template" ]]; then
2018-03-01 09:24:31 +01:00
mkdir -p $DOTFILES_TMP/$DIR
cat $CDIR/$f | mo > $DOTFILES_TMP/$DIR/${f:0:-9}
2021-02-19 14:55:00 +01:00
chmod --reference=$CDIR/$f $DOTFILES_TMP/$DIR/${f:0:-9}
2018-03-01 09:24:31 +01:00
CDIR=$DOTFILES_TMP/$DIR/
f=${f:0:-9}
fi
2018-03-04 10:07:06 +01:00
if ! $YES && [ -f $HOME/$INSTALL_PREFIX/$f ]; then
2018-03-01 09:24:31 +01:00
attention "Overwrite File '$HOME/$INSTALL_PREFIX/$f' [Y/n] "
read c
case $c in
[Nn]* ) continue;;
esac
fi
if ! [ -z "${CMD// }" ]; then
grey "Running $CMD on $CDIR/$f $CDIR/$f | eval $CMD > $CDIR/$f"
cat $CDIR/$f | eval "$CMD" > $CDIR/$f.tmp
mv $CDIR/$f.tmp $CDIR/$f
fi
2021-06-18 15:18:02 +02:00
mkdir -p $(dirname $HOME/$INSTALL_PREFIX/$f)
2018-03-01 09:24:31 +01:00
ln -sfv $CDIR/$f $HOME/$INSTALL_PREFIX/$f
done
}
2018-03-04 10:49:54 +01:00
function autolink {
for DIR in $DOTFILES_DIR/$DOTDIR/*/ ; do
if [ ! -f $DIR/.link ]; then
continue
fi
source $DIR/.link
printHeading "$TASKNAME"
CLEANED_DIR=$(echo $DIR | sed "s~$DOTFILES_DIR/~~")
linkall $CLEANED_DIR $LINKTO
done
}
2018-03-01 09:24:31 +01:00
main "$@"