-
Notifications
You must be signed in to change notification settings - Fork 1
/
init.php
executable file
·115 lines (87 loc) · 4.18 KB
/
init.php
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
<?php
//this is the script that sets up Eden...
//TODO This script should check for a properly setup zermelo, and user auth system before running the installation...
// so that we can avoid the stage where we get errors because _zermelo_cache/_zermelo_config are not there
// and where JWT security does not enable because we cannot save users...
//also the storage directory needs to be writeable by the webserver in a predictably manner...
$composer_locations = [
'/bin/composer',
'/usr/bin/composer',
'/usr/local/bin/composer',
];
//we assume its missing
$is_got_composer = false;
foreach($composer_locations as $is_it_here){
if(file_exists($is_it_here)){
$is_got_composer = true;
}
}
if(!$is_got_composer){
echo "Error: I could not find composer globally installed\n";
echo "Follow these instructions https://getcomposer.org/doc/00-intro.md#globally and install it to /usr/bin/composer\n";
echo "Since the default of /usr/local/bin/composer is not a ubuntu default\n";
exit();
}
$userinfo = posix_getpwuid(posix_geteuid());
if(!$userinfo['name'] == 'root'){
echo "This file needs to be run as root..\n";
exit();
}
$real_user = getenv('SUDO_USER');
echo "running as root, but from |$real_user| unix account\n";
$composer_config_dir = "/home/$real_user/.composer";
echo "Checking for $composer_config_dir\n";
if(!file_exists($composer_config_dir)){
echo "Error: The directory $composer_config_dir needs to exist and be writable to save authorizations etc... \n";
exit();
}
$cmds = [
"sudo chown $real_user:$real_user $composer_config_dir -R",
"sudo -u $real_user composer update",
"sudo -u $real_user php artisan key:generate",
// "sudo -u $real_user cp ./templates/ReadMe.template.md README.md",
"sudo -u $real_user php artisan vendor:publish --provider='CareSet\DURC\DURCServiceProvider'",
// "sudo -u $real_user php artisan vendor:publish --tag=laravel-handlebars",
"chmod g+w storage/* -R", //this will actually be run as root!! and
"chown $real_user:www-data storage/* -R", //this will
"usermod -a -G www-data $real_user",
];
//lets only overwrite the readme, if it is has not already been overwritten...
$readme_text = file_get_contents('./README.md');
if(strpos($readme_text,'sudo php init.php') !== false){
//then this current readme is the one saying "start by using init.php"
//if it says anything else... it should NOT be overwritten...
//but if we are in this block, then the readme does need to be replaced!!!
$cmds[] = "sudo -u $real_user cp ./templates/ReadMe.template.md README.md";
}else{
echo "The README looks custom, we are leaving it alone...\n";
}
if(!file_exists('.env')){
array_unshift($cmds,"sudo -u $real_user cp .env.example .env");
}else{
echo "The .env file already exists, so we are not deleting it\n";
}
foreach($cmds as $this_command){
echo "Running $this_command\n";
system($this_command);
}
echo "You need to run the zermelo installation now... since it is interactive\n ./artisan zermelo:install\n\n";
echo "Before you do that, you need to create a database user for this instance and edit .env to give database access\n";
echo "be sure to give appropriate access to the auth, _zermelo_config, and _zermelo_cache databases, as well as a new database for this server\n";
/*
// for now, we are ignoring the installation of zermelo, because it requires the database to be configured
#these commands need to run as the regular user...
#create our local .env file, it is ignored by .gitignore and is where lots of good configirations live
sudo -u $real_user php artisan install:zermelo
sudo -u $real_user php artisan install:zermelobladetabular
sudo -u $real_user php artisan install:zermelobladecard
*/
// correct the group permissions for all the files in the project so that they can interact correctly with github and be run by any user:
// change the group for everything to 'careset':
shell_exec("sudo chgrp careset * -R");
// Change group on the storage directory to be writable by apache:
shell_exec("sudo chgrp www-data storage -R");
// Grant groups r/w privileges:
shell_exec("sudo chmod g+rw * -R");
// Add the sticky bit permission, but only to directories:
shell_exec("sudo find ./ -type d | xargs chmod g+s");