forked from fsbruva/thebrig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
thebrig_install.sh
111 lines (101 loc) · 3.96 KB
/
thebrig_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
106
107
108
109
110
111
#!/bin/sh
# define our bail out shortcut function anytime there is an error - display the error message, then exit
# returning 1.
exerr () { echo -e "$*" >&2 ; exit 1; }
# Determine the current directory
# Method adapted from user apokalyptik at
# http://hintsforums.macworld.com/archive/index.php/t-73839.html
STAT=$(procstat -f $$ | grep -E "/"$(basename $0)"$")
FULL_PATH=$(echo $STAT | sed -r s/'^([^\/]+)\/'/'\/'/1 2>/dev/null)
START_FOLDER=$(dirname $FULL_PATH | sed 's|/thebrig_install.sh||')
# Store the script's current location in a file
echo $START_FOLDER > /tmp/thebriginstaller
# This first checks to see that the user has supplied an argument
if [ ! -z $1 ]; then
# The first argument will be the path that the user wants to be the root folder.
# If this directory does not exist, it is created
BRIG_ROOT=$1
# This checks if the supplied argument is a directory. If it is not
# then we will try to create it
if [ ! -d $BRIG_ROOT ]; then
echo "Attempting to create a new destination directory....."
mkdir -p $BRIG_ROOT || exerr "ERROR: Could not create directory!"
fi
mkdir -p temporary || exerr "ERROR: Could not create install directory!"
cd temporary || exerr "ERROR: Could not access install directory!"
# cd $BRIG_ROOT || exerr "ERROR: Could not access install directory!"
else
# We are here because the user did not specify an alternate location. Thus, we should use the
# current directory as the root.
BRIG_ROOT=$START_FOLDER
fi
# touch /tmp/thebrig.tmp
if [ $2 -eq 2 ]; then
# Fetch the testing branch as a zip file
echo "Retrieving the testing branch as a zip file"
fetch https://github.com/fsbruva/thebrig/archive/working.zip || exerr "ERROR: Could not write to install directory!"
mv working.zip master.zip
elif [ $2 -eq 3 ]; then
echo "Retrieving the alexey's branch as a zip file"
fetch https://github.com/fsbruva/thebrig/archive/alexey.zip || exerr "ERROR: Could not write to install directory!"
mv alexey.zip master.zip
else
# Fetch the master branch as a zip file
echo "Retrieving the most recent version of TheBrig"
fetch https://github.com/fsbruva/thebrig/archive/master.zip || exerr "ERROR: Could not write to install directory!"
fi
# Extract the files we want, stripping the leading directory, and exclude
# the git nonsense
echo "Unpacking the tarball..."
tar -xvf master.zip --exclude='.git*' --strip-components 1
rm master.zip
# Run the change_ver script to deal with different versions of TheBrig
/usr/local/bin/php-cgi -f conf/bin/change_ver.php
filever="/tmp/thebrigversion"
# The file /tmp/thebrigversion might get created by the change_ver script
# Its existence implies that we need to carry out the install procedure
if [ -f "$filever" ]
then
action=`cat ${filever}`
# echo "Thebrig "${action}
if [ `uname -p` = "amd64" ]; then
echo "Renaming 64 bit ftp binary"
mv conf/bin/ftp_amd64 conf/bin/ftp
rm conf/bin/ftp_i386
else
echo "Renaming 32 bit ftp binary"
mv conf/bin/ftp_i386 conf/bin/ftp
rm conf/bin/ftp_amd64
fi
cp -r * $BRIG_ROOT/
mkdir -p /usr/local/www/ext/thebrig
cp $BRIG_ROOT/conf/ext/thebrig/* /usr/local/www/ext/thebrig
cd /usr/local/www
# For each of the php files in the extensions folder
for file in /usr/local/www/ext/thebrig/*.php
do
# Check if the link is already there
if [ -e "${file##*/}" ]; then
rm "${file##*/}"
fi
# Create link
ln -s "$file" "${file##*/}"
done
echo $BRIG_ROOT > /tmp/thebrig.tmp
echo "Congratulations! Thebrig ${action} . Navigate to rudimentary config tab and push Save "
else
# There was not /tmp/thebrigversion, so we are already using the latest version
echo "You use fresh version"
fi
# Clean after work
cd $START_FOLDER
# Get rid of staged updates
rm -Rf temporary/*
rmdir temporary
rm /tmp/thebriginstaller
if [ -f "$file" ]
then
rm /tmp/thebrigversion
fi
currentdate=`date -j +"%Y-%m-%d %H:%M:%S"`
echo "[$currentdate]: TheBrig installer!: installer: ${action} successfully" >> $BRIG_ROOT/thebrig.log