Commit c89e83d2bef96fdc62cfe9d831a423b6be40a306

Authored by Alexis Gavoty
1 parent 71c4566cc6
Exists in master

Update install

Showing 1 changed file with 3 additions and 0 deletions Inline Diff

1 #!/bin/bash 1 #!/bin/bash
2 2
3 # Retrieve arguments 3 # Retrieve arguments
4 domain=$1 4 domain=$1
5 path=$2 5 path=$2
6 user=$3 6 user=$3
7 7
8 # Check user parameter 8 # Check user parameter
9 ls /home | grep $user 9 ls /home | grep $user
10 if [[ ! $? -eq 0 ]]; then 10 if [[ ! $? -eq 0 ]]; then
11 echo "Wrong user" 11 echo "Wrong user"
12 exit 1 12 exit 1
13 fi 13 fi
14 sudo yunohost app setting owncloud admin_user -v $user 14 sudo yunohost app setting owncloud admin_user -v $user
15 15
16 # Check domain/path availability 16 # Check domain/path availability
17 sudo yunohost app checkurl $domain$path -a owncloud 17 sudo yunohost app checkurl $domain$path -a owncloud
18 if [[ ! $? -eq 0 ]]; then 18 if [[ ! $? -eq 0 ]]; then
19 exit 1 19 exit 1
20 fi 20 fi
21 21
22 # Install dependencies 22 # Install dependencies
23 sudo apt-get install acl smbclient -y -qq 23 sudo apt-get install acl smbclient -y -qq
24 24
25 # Generate random password 25 # Generate random password
26 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') 26 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')
27 27
28 # Use 'owncloud' as database name and user 28 # Use 'owncloud' as database name and user
29 db_user=owncloud 29 db_user=owncloud
30 30
31 # Initialize database and store mysql password for upgrade 31 # Initialize database and store mysql password for upgrade
32 sudo yunohost app initdb $db_user -p $db_pwd 32 sudo yunohost app initdb $db_user -p $db_pwd
33 sudo yunohost app setting owncloud mysqlpwd -v $db_pwd 33 sudo yunohost app setting owncloud mysqlpwd -v $db_pwd
34 34
35 # Create owncloud user 35 # Create owncloud user
36 sudo useradd -d /var/www/owncloud owncloud 36 sudo useradd -d /var/www/owncloud owncloud
37 37
38 # Copy files to the right place 38 # Copy files to the right place
39 final_path=/var/www/owncloud 39 final_path=/var/www/owncloud
40 data_path=/home/yunohost.app/owncloud/data 40 data_path=/home/yunohost.app/owncloud/data
41 sudo mkdir -p $final_path 41 sudo mkdir -p $final_path
42 sudo mkdir -p $data_path 42 sudo mkdir -p $data_path
43 sudo cp -a ../sources/* $final_path 43 sudo cp -a ../sources/* $final_path
44 sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/owncloud.conf 44 sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/owncloud.conf
45 sudo cp ../conf/php-fpm.conf /etc/php5/fpm/pool.d/owncloud.conf 45 sudo cp ../conf/php-fpm.conf /etc/php5/fpm/pool.d/owncloud.conf
46 sudo cp ../conf/php-fpm.ini /etc/php5/fpm/conf.d/20-owncloud.ini 46 sudo cp ../conf/php-fpm.ini /etc/php5/fpm/conf.d/20-owncloud.ini
47 sudo cp ../conf/mount.json $data_path 47 sudo cp ../conf/mount.json $data_path
48 sudo chown -hR owncloud:www-data $final_path 48 sudo chown -hR owncloud:www-data $final_path
49 sudo chown -hR owncloud:www-data $data_path 49 sudo chown -hR owncloud:www-data $data_path
50 sudo chmod 755 /home/yunohost.app 50 sudo chmod 755 /home/yunohost.app
51 sudo chmod -R 775 $final_path 51 sudo chmod -R 775 $final_path
52 sudo chmod -R 770 $data_path 52 sudo chmod -R 770 $data_path
53 53
54 # Change variables in Owncloud configuration 54 # Change variables in Owncloud configuration
55 sudo sed -i "s@PATHTOCHANGE@$path@g" /etc/nginx/conf.d/$domain.d/owncloud.conf 55 sudo sed -i "s@PATHTOCHANGE@$path@g" /etc/nginx/conf.d/$domain.d/owncloud.conf
56 sudo sed -i "s@ALIASTOCHANGE@$final_path/@g" /etc/nginx/conf.d/$domain.d/owncloud.conf 56 sudo sed -i "s@ALIASTOCHANGE@$final_path/@g" /etc/nginx/conf.d/$domain.d/owncloud.conf
57 sudo sed -i "s@NAMETOCHANGE@owncloud@g" /etc/nginx/conf.d/$domain.d/owncloud.conf 57 sudo sed -i "s@NAMETOCHANGE@owncloud@g" /etc/nginx/conf.d/$domain.d/owncloud.conf
58 sudo sed -i "s@NAMETOCHANGE@owncloud@g" /etc/php5/fpm/pool.d/owncloud.conf 58 sudo sed -i "s@NAMETOCHANGE@owncloud@g" /etc/php5/fpm/pool.d/owncloud.conf
59 59
60 # Set permissions to owncloud directories and /home directories + add Home external storage 60 # Set permissions to owncloud directories and /home directories + add Home external storage
61 for i in $(ls /home) 61 for i in $(ls /home)
62 do 62 do
63 if [[ ! $i == yunohost.* ]]; 63 if [[ ! $i == yunohost.* ]];
64 then 64 then
65 sudo setfacl -m g:owncloud:rwx /home/$i 65 sudo setfacl -m g:owncloud:rwx /home/$i
66 sudo mkdir $data_path/$i 66 sudo mkdir $data_path/$i
67 fi 67 fi
68 done 68 done
69 69
70 # Reload Nginx and regenerate SSOwat conf 70 # Reload Nginx and regenerate SSOwat conf
71 sudo service php5-fpm restart 71 sudo service php5-fpm restart
72 sudo service nginx reload 72 sudo service nginx reload
73 sudo yunohost app setting owncloud skipped_uris -v "/" 73 sudo yunohost app setting owncloud skipped_uris -v "/"
74 sudo yunohost app ssowatconf 74 sudo yunohost app ssowatconf
75 75
76 # Owncloud installation via curl 76 # Owncloud installation via curl
77 echo "127.0.0.1 $domain #yunoowncloud" | sudo tee -a /etc/hosts 77 echo "127.0.0.1 $domain #yunoowncloud" | sudo tee -a /etc/hosts
78 sleep 1 78 sleep 1
79 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 79 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
80 80
81 # Enable plugins 81 # Enable plugins
82 sleep 5 82 sleep 5
83 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 83 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
84 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 84 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
85 85
86 # Check if the Mysql database is initialized & running 86 # Check if the Mysql database is initialized & running
87 mysql -u $db_user -p$db_pwd $db_user -e "select * from oc_appconfig;" > /dev/null 2>&1 87 mysql -u $db_user -p$db_pwd $db_user -e "select * from oc_appconfig;" > /dev/null 2>&1
88 result=$? 88 result=$?
89 loop_number=1 89 loop_number=1
90 while [ $result != 0 ] && [ $loop_number -lt 5 ]; 90 while [ $result != 0 ] && [ $loop_number -lt 5 ];
91 do 91 do
92 sleep 5 92 sleep 5
93 mysql -u $db_user -p$db_pwd $db_user -e "select * from oc_appconfig;" > /dev/null 2>&1 93 mysql -u $db_user -p$db_pwd $db_user -e "select * from oc_appconfig;" > /dev/null 2>&1
94 let result=$? 94 let result=$?
95 if [ $loop_number -eq 4 ]; 95 if [ $loop_number -eq 4 ];
96 then 96 then
97 print "Web installation failed" 97 print "Web installation failed"
98 exit 1 98 exit 1
99 fi 99 fi
100 let loop_number++ 100 let loop_number++
101 done 101 done
102 102
103 # Configure LDAP plugin 103 # Configure LDAP plugin
104 mysql -u $db_user -p$db_pwd $db_user < ../conf/ldap_config.sql 104 mysql -u $db_user -p$db_pwd $db_user < ../conf/ldap_config.sql
105 105
106 sudo chown -hR owncloud:owncloud $final_path
107 sudo chown -hR owncloud:owncloud $data_path
108
106 # Make an LDAP user as admin 109 # Make an LDAP user as admin
107 mysql -u $db_user -p$db_pwd $db_user -e "INSERT INTO oc_group_user VALUES ('admin','$user');" 110 mysql -u $db_user -p$db_pwd $db_user -e "INSERT INTO oc_group_user VALUES ('admin','$user');"
108 111
109 # Unprotect URIs 112 # Unprotect URIs
110 sudo yunohost app setting owncloud skipped_uris -v "/public.php,/core,/apps/files,/index.php/apps/files" 113 sudo yunohost app setting owncloud skipped_uris -v "/public.php,/core,/apps/files,/index.php/apps/files"
111 sudo yunohost app setting owncloud unprotected_uris -v "/remote.php,/cron.php,/status.php" 114 sudo yunohost app setting owncloud unprotected_uris -v "/remote.php,/cron.php,/status.php"
112 sudo yunohost app ssowatconf 115 sudo yunohost app ssowatconf
113 116
114 # Remove temporary entry in /etc/hosts 117 # Remove temporary entry in /etc/hosts
115 sudo sed -i '/yunoowncloud/d' /etc/hosts 118 sudo sed -i '/yunoowncloud/d' /etc/hosts
116 119