-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·105 lines (89 loc) · 2.55 KB
/
install.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/bin/bash
set -ueo pipefail
SCRIPTS=$(dirname "$(readlink -f "$0")")
_installLatest() {
# $1 package
# $2.. make actions
local app version arch target
app=$1
shift
version=$(dpkg-query -f='${Version}' --show "$app" 2>/dev/null || echo -n "0")
arch=$(dpkg --print-architecture)
target=$(echo "$SCRIPTS/apps/$app/$app"_*_"$arch.deb" | cut -d_ -f2)
if dpkg --compare-versions "$version" lt "$target"; then
# install package
MAKEFLAGS= make -C "$SCRIPTS/apps/$app/" "$@"
echo
else
echo "$app is up-to-date."
fi
}
# running as root?
[ "$(id -u)" == "0" ] && ROOT=true || ROOT=false
[ "${1:-}" == "-y" ] && YES=-y || YES=
if [ "$ROOT" = true ]; then
if [ "${1:-}" == "-u" ]; then
# update --> more silent
apt-get update > /dev/null
if aptitude -s -y install $(cut -d' ' -f1 "$SCRIPTS"/packages) | grep -q "The following NEW packages will be installed"; then
echo "Installing new packages.."
echo
aptitude install $(cut -d' ' -f1 "$SCRIPTS"/packages)
fi
else
# install
apt-get update
apt-get $YES install $(cut -d' ' -f1 "$SCRIPTS"/packages)
fi
# install/update custom packages
_installLatest bat install
_installLatest duf install
_installLatest tmux install copy-conf
# todo remove in the future; see also uninstall.sh
# remove .bash_completion symlink from previous version
if [ "$(readlink -f ~/.bash_completion)" == "$SCRIPTS/bash_completion" ]; then
echo 'Removing symlink' ~/.bash_completion "-> $SCRIPTS/bash_completion"
rm ~/.bash_completion
fi
else
echo "Warning: You are not root. Package installation skipped." >&2
fi
echo
# bashrc
if [ ! -f ~/.bashrc.local ]; then
echo 'Creating ' ~/.bashrc.local
echo 'return' > ~/.bashrc.local
cat ~/.bashrc >> ~/.bashrc.local
fi
if [ ! -f ~/.bashrc.backup ] && [ -f ~/.bashrc ]; then
echo 'Moving ' ~/.bashrc '->' ~/.bashrc.backup
mv ~/.bashrc ~/.bashrc.backup
fi
if [ ! -f ~/.bashrc ]; then
echo -n 'Creating symlink '
ln -sv "$SCRIPTS"/bashrc ~/.bashrc
fi
echo
# inputrc
if [ ! -f ~/.inputrc ]; then
echo -n 'Creating symlink '
ln -sv "$SCRIPTS"/inputrc ~/.inputrc
echo
fi
# vimrc
if [ "$ROOT" = true ]; then
if [ -f /etc/vim/vimrc ] && [ ! -f /etc/vim/vimrc.backup ]; then
echo 'Moving /etc/vim/vimrc -> /etc/vim/vimrc.backup'
mv /etc/vim/vimrc /etc/vim/vimrc.backup
fi
if [ ! -f /etc/vim/vimrc ]; then
echo -n 'Creating symlink '
ln -sv "$SCRIPTS"/vimrc /etc/vim/vimrc
fi
fi
echo 'Done.'
echo
if aptitude search ~iunattended-upgrades &> /dev/null; then
echo "Warning: 'unattended-upgrades' package is installed!"
echo
fi >&2