~teejee2008/timeshift/trunk

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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#!/bin/bash

app_name='timeshift'
app_fullname='Timeshift'

generic_depends=(rsync libgee json-glib)
debian_depends=(rsync libgee2 libjson-glib-1.0-0)
redhat_depends=(rsync libgee json-glib)
arch_depends=(rsync libgee json-glib)

generic_recommends=()
debian_recommends=()
redhat_recommends=()
arch_recommends=()

Reset='\e[0m'
Red='\e[1;31m'
Green='\e[1;32m'
Yellow='\e[1;33m'

CHECK_COLOR_SUPPORT() {
	colors=`tput colors`
	if [ $colors -gt 1 ]; then
		COLORS_SUPPORTED=0
	else
		COLORS_SUPPORTED=1
	fi
}

MSG_INFO() {
	add_newline=''
	if [ "$2" == 0 ]; then
		add_newline='-n'
	fi
	
	if [ $COLORS_SUPPORTED -eq 0 ]; then
        echo -e ${add_newline} "[${Yellow}*${Reset}] ${Green}$1${Reset}"
    else
        echo -e ${add_newline} "[*] $1"
    fi
}

MSG_WARNING() {
	add_newline=''
	if [ "$2" == 0 ]; then
		add_newline='-n'
	fi
	
	if [ $COLORS_SUPPORTED -eq 0 ]; then
        echo -e ${add_newline} "[${Red}!${Reset}] ${Yellow}$1${Reset}"
    else
        echo -e ${add_newline} "[!] $1"
    fi
}

MSG_ERROR() {
	add_newline=''
	if [ "$2" == 0 ]; then
		add_newline='-n'
	fi
	
    if [ $COLORS_SUPPORTED -eq 0 ]; then
        echo -e ${add_newline} "[${Red}X${Reset}] ${Yellow}$1${Reset}"
    else
        echo -e ${add_newline} "[X] $1"
    fi
}

CD_PUSH() {
	cd_backup=`pwd`
}

CD_POP() {
	if [ ! -z "${cd_backup}" ]; then
		cd "${cd_backup}"
	fi
}

BACKUP_IFS(){
	IFS_backup="${IFS}"
}

SET_IFS_NEWLINE(){
	IFS=$'\n'
}

RESET_IFS() {
	if [ ! -z "${IFS_backup}" ]; then
		IFS="${IFS_backup}"
	fi
}

EXIT(){
	RESET_IFS
	CD_POP
	exit $1
}

WAIT_FOR_INPUT() {
	echo ""
	echo "Press any key to exit..."
	read dummy
}

GET_SCRIPT_PATH(){
	SCRIPTPATH="$(cd "$(dirname "$0")" && pwd)"
	SCRIPTNAME=`basename $0`
}

RUN_AS_ADMIN() {
	if [ ! `id -u` -eq 0 ]; then
		GET_SCRIPT_PATH
		if command -v sudo >/dev/null 2>&1; then
			sudo "${SCRIPTPATH}/${SCRIPTNAME}"
			EXIT $?
		elif command -v su >/dev/null 2>&1; then
			su -c "${SCRIPTPATH}/${SCRIPTNAME}"
			EXIT $?
		else
			echo ""
			MSG_ERROR "** Installer must be run as Admin (using 'sudo' or 'su') **"
			echo ""
			EXIT 1
		fi
	fi
}

CD_PUSH
CHECK_COLOR_SUPPORT
RUN_AS_ADMIN
BACKUP_IFS

SET_IFS_NEWLINE

MSG_INFO "Expanding directories..."
for f in `find ./ -type d -exec echo "{}" \;`; do
    directory=`echo "$f" | sed -r 's/^.{2}//'`
    mkdir -p -m 755 "/$directory"
    echo "/$directory"
done
echo ""

MSG_INFO "Installing files..."
for f in `find ./ -type f \( ! -iname "install.sh" \) -exec echo "{}" \;`; do
    file=`echo "$f" | sed -r 's/^.{2}//'`
    install -m 0755 "./$file" "/$file"
    echo "/$file"
done
echo ""

RESET_IFS

install_dependencies=y

if command -v apt-get >/dev/null 2>&1; then

	if [ -f /etc/debian_version ]; then
		install_dependencies=y
	else
		MSG_INFO "Found 'apt-get' package manager" 
		MSG_INFO "Install dependencies with 'apt-get'? (y/n):" "0"
		read install_dependencies
		if [ "$install_dependencies" == "" ]; then
			install_dependencies=y
		fi
	fi
	
	if [ "$install_dependencies" == "y" ]; then
		MSG_INFO "Installing Debian packages..."
		echo ""
		for i in "${debian_depends[@]}"; do
		  MSG_INFO "Installing: $i"
		  apt-get install $i
		  echo ""
		done
	fi
	
elif command -v yum >/dev/null 2>&1; then

	if [ -f /etc/redhat-release ]; then
		install_dependencies=y
	else
		MSG_INFO "Found 'yum' package manager" 
		MSG_INFO "Install dependencies with 'yum'? (y/n):" "0"
		read install_dependencies
		if [ "$install_dependencies" == "" ]; then
			install_dependencies=y
		fi
	fi
	
	if [ "$install_dependencies" == "y" ]; then
		MSG_INFO "Installing RedHat packages..."
		echo ""
		for i in "${redhat_depends[@]}"; do
		  MSG_INFO "Installing: $i"
		  yum install $i
		  echo ""
		done
	fi
	
elif command -v pacman >/dev/null 2>&1; then

	if [ -f /etc/arch-release ] || [ -f /etc/manjaro-release ]; then
		install_dependencies=y
	else
		MSG_INFO "Found 'pacman' package manager" 
		MSG_INFO "Install dependencies with 'pacman'? (y/n):" "0"
		read install_dependencies
		if [ "$install_dependencies" == "" ]; then
			install_dependencies=y
		fi
	fi

	if [ "$install_dependencies" == "y" ]; then
		MSG_INFO "Installing ArchLinux packages..."
		echo ""
		for i in "${arch_depends[@]}"; do
		  MSG_INFO "Installing: $i"
		  pacman -S $i
		  echo ""
		done
	fi
fi
echo ""

MSG_INFO "Install completed."
echo ""
echo "******************************************************************"
echo "Start ${app_fullname} using the shortcut in the Applications Menu"
echo "or by running the command: sudo ${app_name}"	
echo "If it fails to start, check and install the following packages:"
echo "Required: ${generic_depends[@]}"
echo "Optional: (none)"
echo "******************************************************************"
WAIT_FOR_INPUT
EXIT 0