-
Notifications
You must be signed in to change notification settings - Fork 7
/
fixv2.sh
152 lines (119 loc) · 5.55 KB
/
fixv2.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
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
#!/usr/bin/env bash
#source: https://gist.github.com/joelconty/e26a25543a4858435009e143c092e793
#Configure these two variables
MYUSER="joel"
APACHEGROUP="www-data"
#you don't need to edit anything below.
echo "Setting variables..."
SCRIPTPATH=`pwd -P`
BOOTSTRAP="${SCRIPTPATH}/bootstrap/"
BOOTSTRAPCACHE="${SCRIPTPATH}/bootstrap/cache/"
STORAGE="${SCRIPTPATH}/storage"
LOGS="${STORAGE}/logs"
FRAMEWORK="${STORAGE}/framework"
#add my user to the web server group
echo "adding ${MYUSER} to the ${APACHEGROUP} group ..."
sudo usermod -a -G ${APACHEGROUP} ${MYUSER}
#if bootstrap/cache does not exist, create it
if [ ! -d ${BOOTSTRAPCACHE} ]; then
echo "Creating ${BOOTSTRAPCACHE} directory..."
mkdir -p ${BOOTSTRAPCACHE}
fi
#if we don't have a .gitignore file in bootstrap/cache, add it
if [ ! -f ${BOOTSTRAPCACHE}/.gitignore ]; then
echo "Creating .gitignore file in ${BOOTSTRAPCACHE}/..."
echo '*' > ${BOOTSTRAPCACHE}/.gitignore
echo '!.gitignore' >> ${BOOTSTRAPCACHE}/.gitignore
fi
#if storage dir does not exist, create it.
if [ ! -d ${STORAGE} ]; then
echo "Creating ${STORAGE} directory"
mkdir -p ${STORAGE}
fi
#then, make sure we have debugbar, framework and logs inside storage
#debugbar is not installed by default, but it does not hurt to have it's directory there , ready for when you install it
for DIR in debugbar framework logs
do
if [ ! -d ${STORAGE}/${DIR} ]; then
echo "Creating ${STORAGE}/${DIR} directory..."
mkdir -p ${STORAGE}/${DIR}
else
echo "Checking for existance of ${STORAGE}/${DIR}... It exists"
fi
done
#if we don't have a .gitignore file in storage/framework, add it
if [ ! -f ${FRAMEWORK}/.gitignore ]; then
echo "Creating .gitignore file in ${FRAMEWORK}..."
echo 'compiled.php' > ${FRAMEWORK}/.gitignore
echo 'config.php' >> ${FRAMEWORK}/.gitignore
echo 'down' >> ${FRAMEWORK}/.gitignore
echo 'events.scanned.php' >> ${FRAMEWORK}/.gitignore
echo 'maintenance.php' >> ${FRAMEWORK}/.gitignore
echo 'routes.php' >> ${FRAMEWORK}/.gitignore
echo 'routes.scanned.php' >> ${FRAMEWORK}/.gitignore
echo 'schedule-*' >> ${FRAMEWORK}/.gitignore
echo 'services.json' >> ${FRAMEWORK}/.gitignore
fi
#then, make sure we have cache, sessions, testing and views inside storage/framework
for DIR in cache sessions testing views
do
if [ ! -d ${FRAMEWORK}/${DIR} ]; then
echo "Creating ${FRAMEWORK}/${DIR} directory..."
mkdir -p ${FRAMEWORK}/${DIR}
else
echo "Checking for existance of ${FRAMEWORK}/${DIR}... It exists"
fi
done
#then, make sure we have a storage/framework/cache/data directory
if [ ! -d ${FRAMEWORK}/cache/data ]; then
echo "Creating ${FRAMEWORK}/cache/data directory..."
mkdir -p ${FRAMEWORK}/cache/data
else
echo "Checking for existance of ${FRAMEWORK}/cache/data... It exists"
fi
#if we don't have a .gitignore file in storage/framework/cache/data, add it
if [ ! -f ${FRAMEWORK}/cache/data/.gitignore ]; then
echo "Creating .gitignore file in ${FRAMEWORK}/cache/data/..."
echo '*' > ${FRAMEWORK}/cache/data/.gitignore
echo '!data/' >> ${FRAMEWORK}/cache/data/.gitignore
echo '!.gitignore' >> ${FRAMEWORK}/cache/data/.gitignore
fi
#if we don't have a .gitignore file in storage/framework/sessions/, add it
if [ ! -f ${FRAMEWORK}/sessions/.gitignore ]; then
echo "Creating .gitignore file in ${FRAMEWORK}/sessions/..."
echo '*' > ${FRAMEWORK}/sessions/.gitignore
echo '!.gitignore' >> ${FRAMEWORK}/sessions/.gitignore
fi
#if we don't have a .gitignore file in storage/framework/testing/, add it
if [ ! -f ${FRAMEWORK}/testing/.gitignore ]; then
echo "Creating .gitignore file in ${FRAMEWORK}/testing/..."
echo '*' > ${FRAMEWORK}/testing/.gitignore
echo '!.gitignore' >> ${FRAMEWORK}/testing/.gitignore
fi
#if we don't have a .gitignore file in storage/framework/views/, add it
if [ ! -f ${FRAMEWORK}/views/.gitignore ]; then
echo "Creating .gitignore file in ${FRAMEWORK}/views/..."
echo '*' > ${FRAMEWORK}/views/.gitignore
echo '!.gitignore' >> ${FRAMEWORK}/views/.gitignore
fi
#make my user and the apache group own everything in the directory
echo "Fixing ownership on everything..."
sudo chown -R ${MYUSER}:${APACHEGROUP} ${SCRIPTPATH}
#change permissions on files to 644
echo "Setting permissions 0644 on all files... (excluding vendor, node_modules and .git directories)"
sudo find ${SCRIPTPATH} -type f -not -path "${SCRIPTPATH}/vendor/*" -not -path "${SCRIPTPATH}/node_modules/*" -not -path "${SCRIPTPATH}/.git/*" -exec chmod 0644 {} \;
#change permissions on directories to 755
echo "Setting permissions 0755 on all directories... (excluding vendor, node_modules and .git directories)"
sudo find ${SCRIPTPATH} -type d -not -path "${SCRIPTPATH}/vendor/*" -not -path "${SCRIPTPATH}/node_modules/*" -not -path "${SCRIPTPATH}/.git/*" -exec chmod 0755 {} \;
#change permissions on bootstrap/cache to 775
echo "Setting permissions 0775 on bootstrap/cache"
sudo chmod 0775 ${BOOTSTRAPCACHE}
#change permissions on the php files that live in bootstrap/cache to 0775
echo "Setting permissions 0775 on php files in bootstrap/cache"
sudo chmod 0775 ${BOOTSTRAPCACHE}/*.php
#if i have any bash scripts in there, make them executable
echo "Making any existing shell scripts executable"
sudo find ${SCRIPTPATH} -type f -iname "*.sh" -exec chmod +x {} \;
#finally fix permissions on storage
echo "Setting 0775 permissions on ${STORAGE}..."
chmod -R 0775 ${STORAGE}