install
4.31 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
123
124
125
#!/bin/bash
# Retrieve arguments
domain=$1
path=$2
user=$3
# Check user parameter
sudo yunohost user list --json | grep -q "\"username\": \"$user\""
if [[ ! $? -eq 0 ]]; then
echo "Wrong user"
exit 1
fi
sudo yunohost app setting owncloud admin_user -v $user
# Check domain/path availability
sudo yunohost app checkurl $domain$path -a owncloud
if [[ ! $? -eq 0 ]]; then
exit 1
fi
# Install dependencies
sudo apt-get install acl smbclient -y -qq
# Generate random password
db_pwd=$(dd if=/dev/urandom bs=1 count=200 2> /dev/null | tr -c -d 'A-Za-z0-9' | sed -n 's/\(.\{24\}\).*/\1/p')
# Use 'owncloud' as database name and user
db_user=owncloud
# Initialize database and store mysql password for upgrade
sudo yunohost app initdb $db_user -p $db_pwd
sudo yunohost app setting owncloud mysqlpwd -v $db_pwd
# Create owncloud user
sudo useradd -d /var/www/owncloud owncloud
# Copy files to the right place
final_path=/var/www/owncloud
data_path=/home/yunohost.app/owncloud/data
sudo mkdir -p $final_path
sudo mkdir -p $data_path
sudo cp -a ../sources/* $final_path
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/owncloud.conf
sudo cp ../conf/php-fpm.conf /etc/php5/fpm/pool.d/owncloud.conf
sudo cp ../conf/php-fpm.ini /etc/php5/fpm/conf.d/20-owncloud.ini
sudo cp ../conf/mount.json $data_path
sudo chown -hR owncloud:www-data $final_path
sudo chown -hR owncloud:www-data $data_path
sudo chown owncloud:www-data /home/yunohost.app/owncloud
sudo chmod 755 /home/yunohost.app
sudo find $final_path -type f | xargs sudo chmod 664
sudo find $final_path -type d | xargs sudo chmod 775
sudo chmod -R 770 $data_path
# Change variables in Owncloud configuration
sudo sed -i "s@PATHTOCHANGE@$path@g" /etc/nginx/conf.d/$domain.d/owncloud.conf
sudo sed -i "s@ALIASTOCHANGE@$final_path/@g" /etc/nginx/conf.d/$domain.d/owncloud.conf
sudo sed -i "s@NAMETOCHANGE@owncloud@g" /etc/nginx/conf.d/$domain.d/owncloud.conf
sudo sed -i "s@NAMETOCHANGE@owncloud@g" /etc/php5/fpm/pool.d/owncloud.conf
# Set permissions to owncloud directories and /home directories + add Home external storage
for i in $(ls /home)
do
sudo yunohost user list --json | grep -q "\"username\": \"$i\""
if [[ $? -eq 0 ]];
then
sudo setfacl -m g:owncloud:rwx /home/$i
sudo mkdir $data_path/$i
fi
done
# Reload Nginx and regenerate SSOwat conf
sudo service php5-fpm restart
sudo service nginx reload
sudo yunohost app setting owncloud skipped_uris -v "/"
sudo yunohost app ssowatconf
# Owncloud installation via curl
echo "127.0.0.1 $domain #yunoowncloud" | sudo tee -a /etc/hosts
sleep 1
curl -kL -X POST https://$domain$path/index.php --data "install=true&adminlogin=admin&adminpass=$db_pwd&directory=/home/yunohost.app/owncloud/data&dbtype=mysql&dbuser=$db_user&dbpass=$db_pwd&dbname=$db_user&dbhost=localhost" > /dev/null 2>&1
# Enable plugins
sleep 5
curl -kL -X POST https://$domain$path/index.php/settings/ajax/enableapp.php --data "appid=files_external" -u "admin:$db_pwd" > /dev/null 2>&1
curl -kL -X POST https://$domain$path/index.php/settings/ajax/enableapp.php --data "appid=user_ldap" -u "admin:$db_pwd" > /dev/null 2>&1
# Check if the Mysql database is initialized & running
mysql -u $db_user -p$db_pwd $db_user -e "select * from oc_appconfig;" > /dev/null 2>&1
result=$?
loop_number=1
while [ $result != 0 ] && [ $loop_number -lt 5 ];
do
sleep 5
mysql -u $db_user -p$db_pwd $db_user -e "select * from oc_appconfig;" > /dev/null 2>&1
let result=$?
if [ $loop_number -eq 4 ];
then
print "Web installation failed"
exit 1
fi
let loop_number++
done
# Configure LDAP plugin
mysql -u $db_user -p$db_pwd $db_user < ../conf/ldap_config.sql
sudo chown -hR owncloud:owncloud $final_path
sudo chown -hR owncloud:owncloud $data_path
sudo chmod 755 /home/yunohost.app
sudo find $final_path -type f | xargs sudo chmod 664
sudo find $final_path -type d | xargs sudo chmod 775
sudo chmod -R 770 $data_path
# Make an LDAP user as admin
mysql -u $db_user -p$db_pwd $db_user -e "INSERT INTO oc_group_user VALUES ('admin','$user');"
# Unprotect URIs
sudo yunohost app setting owncloud skipped_uris -v "/public.php,/core,/apps/files,/index.php/apps/files"
sudo yunohost app setting owncloud unprotected_uris -v "/remote.php,/cron.php,/status.php"
sudo yunohost app ssowatconf
# Remove temporary entry in /etc/hosts
sudo sed -i '/yunoowncloud/d' /etc/hosts