-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·122 lines (103 loc) · 4.14 KB
/
install.sh
File metadata and controls
executable file
·122 lines (103 loc) · 4.14 KB
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
#! /bin/sh
# Copyright (C) 2013-2017 Matthew Langbehn
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
################################################################################
# #
# Simple Install Script #
# #
################################################################################
#---------------------------- System Commands --------------------------------#
# Define tools for this script
ID=/usr/bin/id;
ECHO=/bin/echo;
MKDIR=/bin/mkdir;
CP=/bin/cp;
MV=/bin/mv;
SED=/bin/sed;
CRONTAB=/usr/bin/crontab;
COMMANDS="bash id echo cp crontab mv rm mkdir rsync";
#------------------------- Revelvant Directories -----------------------------#
INSTALL_DIRECTORY=/usr/sbin;
CONF_DIRECTORY=/etc/backup;
#-------------------------- crontab enteries ---------------------------------#
CRONJOB_DAILY="0 0 * * * /usr/sbin/backup_daily > /dev/null";
CRONJOB_WEEKLY="0 3 * * 0 /usr/sbin/backup_weekly > /dev/null";
CRONJOB_MONTHLY="0 0 1 * * /usr/sbin/backup_monthly > /dev/null";
CRONJOB_YEARLY="0 0 1 1 * /usr/sbin/backup_yearly > /dev/null";
#---------------------------- Body of Script ---------------------------------#
# Ensure user is root
if (( `$ID -u` != 0 )); then
$ECHO "$0 must be run as root.";
exit;
fi;
# Check for requisite tools
$ECHO "Checking for tools...";
for i in $COMMANDS
do
command -v $i > /dev/null && continue || $ECHO "$i command not found."; exit;
done
$ECHO "All commands found!";
# Create the configuration directory
$ECHO "Checking for existing configuration directory...";
if [ -d $CONF_DIRECTORY ]; then
$ECHO "$CONF_DIRECTORY already exists.";
if [ -f $CONF_DIRECTORY/backup.conf ]; then
$ECHO "Previous configuration file found.";
$ECHO "Backing it up.";
$MV -i $CONF_DIRECTORY/backup.conf $CONF_DIRECTORY/backup.conf.old;
fi;
if [ -f $CONF_DIRECTORY/backup.exclude ]; then
$ECHO "Previous excludes file found.";
$ECHO "Backing it up.";
$MV -i $CONF_DIRECTORY/backup.exclude $CONF_DIRECTORY/backup.exclude.old;
fi;
else
$ECHO "None found, creating $CONF_DIRECTORY":
$MKDIR $CONF_DIRECTORY;
fi;
# Install conf files
if [ -d Conf ]; then
$ECHO "Adding conf file to $CONF_DIRECTORY";
$CP Conf/backup.conf $CONF_DIRECTORY;
else
$ECHO "Please run this script from the root of the installation package.";
exit;
fi;
# Install backup tools
if [ -d Scripts ]; then
$ECHO "Installing scripts in $INSTALL_DIRECTORY";
$CP Scripts/backup_daily $INSTALL_DIRECTORY;
$CP Scripts/backup_weekly $INSTALL_DIRECTORY;
$CP Scripts/backup_monthly $INSTALL_DIRECTORY;
$CP Scripts/backup_yearly $INSTALL_DIRECTORY;
$CP Scripts/backup_now $INSTALL_DIRECTORY;
$CP Scripts/backup_restore $INSTALL_DIRECTORY;
else
$ECHO "Please run this script from the root of the installation package.";
exit;
fi;
# Add tools to root's crontab
$ECHO "Removing any old cronjobs for ABS"
$CRONTAB -l | $SED '/backup_daily/d' | $CRONTAB -;
$CRONTAB -l | $SED '/backup_weekly/d' | $CRONTAB -;
$CRONTAB -l | $SED '/backup_monthly/d' | $CRONTAB -;
$CRONTAB -l | $SED '/backup_yearly/d' | $CRONTAB -;
$ECHO "Adding cronjobs";
($CRONTAB -l; $ECHO "$CRONJOB_DAILY") | $CRONTAB -;
($CRONTAB -l; $ECHO "$CRONJOB_WEEKLY") | $CRONTAB -;
($CRONTAB -l; $ECHO "$CRONJOB_MONTHLY") | $CRONTAB -;
($CRONTAB -l; $ECHO "$CRONJOB_YEARLY") | $CRONTAB -;
# All done :-)
$ECHO "Finished installing ABS.";