81 lines
2.4 KiB
Bash
Executable File
81 lines
2.4 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
if [ ${0:0:1} == "/" ]
|
|
then
|
|
SOURCE=$(dirname $0)/
|
|
else
|
|
SOURCE=$(dirname `pwd`/$0)/
|
|
fi
|
|
DESTINATION=~
|
|
|
|
if [ "$1" == "install" ] || [ "$1" == "link" ] || [ "$1" == "links" ]
|
|
then
|
|
REMOVE=1
|
|
BIN="ln -s"
|
|
elif [ "$1" == "update" ] || [ "$1" == "pull" ]
|
|
then
|
|
cd $SOURCE
|
|
git pull --recurse-submodules=yes `git remote | head -n 1`
|
|
exit $?
|
|
elif [ "$1" == "remove" ] || [ "$1" == "uninstall" ]
|
|
then
|
|
REMOVE=0
|
|
BIN="rm"
|
|
elif [ "$1" == "copy" ]
|
|
then
|
|
REMOVE=1
|
|
BIN="cp -r"
|
|
else
|
|
echo -e "\e[32;01mNemunaire's configuration \e[0;33m("`git branch --no-color | grep '*' | cut -d " " -f 2-`")\e[0m"
|
|
echo -e " \e[01mAuthor:\e[0m\t\t"`git log -1 --format="%aN <%aE>"`
|
|
echo -e " \e[01mOriginal source:\e[0m\thttps://git.nemunai.re/?p=conf.git"
|
|
echo
|
|
echo -e "\e[01mUsage:\e[0m"
|
|
echo -e " $0 \e[36;01minstall\e[0m"
|
|
echo -e " Create symbolic links from this directory to your home"
|
|
echo -e " $0 \e[36;01mremove\e[0m"
|
|
echo -e " Remove symbolic links from your home"
|
|
echo -e " $0 \e[36;01mupdate\e[0m"
|
|
echo -e " Pull latest commits from the server at" `git remote -v | head -n 1 | cut -f 2`
|
|
echo -e " $0 \e[36;01mcopy\e[0m"
|
|
echo -e " Copy configuration files instead of making links"
|
|
exit 0
|
|
fi
|
|
|
|
cd "$SOURCE"
|
|
git submodule init &&
|
|
git submodule update --recursive
|
|
|
|
TMPERR=`mktemp`
|
|
for f in `ls -a "$SOURCE"`
|
|
do
|
|
if [ "$f" != "." ] && [ "$f" != ".." ] && [ "$f" != ".git" ] &&
|
|
[ "$f" != ".gitmodules" ] && [ "$f" != "install.sh" ]
|
|
then
|
|
if [ "$REMOVE" -eq 0 ]; then
|
|
echo -ne "Removing $f ...\t"
|
|
if [ -L "$DESTINATION/$f" ]; then
|
|
$BIN "$DESTINATION/$f" >&2 2> "$TMPERR"
|
|
if [ $? == 0 ]; then echo -e "\e[32mdone\e[0m"; else echo -e "\e[31;01mfail\e[0m"; fi
|
|
cat "$TMPERR"
|
|
else
|
|
echo -e "Not installed"
|
|
fi
|
|
else
|
|
echo -ne "Installing $f ...\t"
|
|
if [ ${#f} -lt 9 ]; then echo -en "\t"; fi
|
|
if [ -L "$DESTINATION/$f" ]
|
|
then
|
|
echo -e "\e[36mAlready installed\e[0m"
|
|
elif [ -e "$DESTINATION/$f" ]
|
|
then
|
|
echo -e "\e[35mAlready exists\e[0m"
|
|
else
|
|
$BIN "$SOURCE/$f" "$DESTINATION/$f" >&2 2> "$TMPERR"
|
|
if [ $? == 0 ]; then echo -e "\e[32mdone\e[0m"; else echo -e "\e[31;01mfail\e[0m"; fi
|
|
cat "$TMPERR"
|
|
fi
|
|
fi
|
|
fi
|
|
done
|