-
Notifications
You must be signed in to change notification settings - Fork 1
/
helper.sh
executable file
·69 lines (60 loc) · 1.22 KB
/
helper.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
### remove_or_backup, install, install_template, install_template_as_root are originally written by @tijsverkoyen
# grab the current dir
CURRENTDIR=$(pwd)
USER=$(whoami)
# check if the file is a symlink, if so it will be removed, if not a backup will be created
function remove_or_backup {
if [ -h $1 ]
then
rm $1
else
if [ -f $1 ]
then
mv $1 $1.old
fi
fi
}
# install the symlink if the source file exists
function install {
if [ -f $1 ]
then
remove_or_backup $2
ln -s $CURRENTDIR/$1 $2
fi
}
# install the symlink if the source file exists, and replace some vars inside the template
function install_template {
if [ -f $1 ]
then
cp $1 ${1%.template}
sed -i '' "s/{{USER}}/$USER/" $CURRENTDIR/${1%.template}
remove_or_backup $2
ln -s $CURRENTDIR/${1%.template} $2
fi
}
function install_template_as_root {
if [ -f $1 ]
then
cp $1 ${1%.template}
sed -i '' "s/{{USER}}/$USER/" $CURRENTDIR/${1%.template}
if [ -h $2 ]
then
sudo rm $2
else
if [ -f $2 ]
then
sudo mv $2 $2.old
fi
fi
sudo ln -s $CURRENTDIR/${1%.template} $2
fi
}
function lowercase()
{
if [ -n "$1" ]; then
echo "$1" | tr "[:upper:]" "[:lower:]"
else
cat - | tr "[:upper:]" "[:lower:]"
fi
}