Blame view

scripts/install 4.08 KB
03e52840d   Kload   Init
1
2
3
4
5
  #!/bin/bash
  
  # Retrieve arguments
  domain=$1
  path=$2
035b88fde   Kload   Try local externa...
6
  user=$3
03e52840d   Kload   Init
7

035b88fde   Kload   Try local externa...
8
  # Check user parameter
d459457a6   Alexis Gavoty   [fix] typo
9
  sudo yunohost user list --json | grep -q "\"username\": \"$user\""
035b88fde   Kload   Try local externa...
10
11
  if [[ ! $? -eq 0 ]]; then
      echo "Wrong user"
bcdcd2d21   Alexis Gavoty   Update install
12
13
      exit 1
  fi
b6d6452fc   Kload   Add upgrade script
14
  sudo yunohost app setting owncloud admin_user -v $user
bcdcd2d21   Alexis Gavoty   Update install
15

03e52840d   Kload   Init
16
17
18
19
20
  # Check domain/path availability
  sudo yunohost app checkurl $domain$path -a owncloud
  if [[ ! $? -eq 0 ]]; then
      exit 1
  fi
348d91c95   Alexis Gavoty   Update install
21
  # Install dependencies
9e3ff650a   Alexis Gavoty   Update install
22
  sudo apt-get install acl smbclient -y -qq
348d91c95   Alexis Gavoty   Update install
23

03e52840d   Kload   Init
24
  # Generate random password
be1d85a81   Alexis Gavoty   Update install
25
  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')
03e52840d   Kload   Init
26
27
28
29
30
31
32
33
34
  
  # 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
71f9ee4c3   Alexis Gavoty   Update install
35
  sudo useradd -d /var/www/owncloud owncloud
03e52840d   Kload   Init
36
37
38
  
  # Copy files to the right place
  final_path=/var/www/owncloud
035b88fde   Kload   Try local externa...
39
  data_path=/home/yunohost.app/owncloud/data
03e52840d   Kload   Init
40
  sudo mkdir -p $final_path
035b88fde   Kload   Try local externa...
41
  sudo mkdir -p $data_path
03e52840d   Kload   Init
42
43
44
  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
a0a7896f8   Alexis Gavoty   Update install
45
  sudo cp ../conf/mount.json $data_path
0f328c944   Alexis Gavoty   Update install
46
47
  sudo chown -hR owncloud:www-data $final_path
  sudo chown -hR owncloud:www-data $data_path
d4f5dce5a   npze   Parent dir of /da...
48
  sudo chown owncloud:www-data /home/yunohost.app/owncloud
a87b65ea9   Alexis Gavoty   Update install
49
  sudo chmod 755 /home/yunohost.app
08c2e70be   Julien Malik   [fix] Support spa...
50
51
  sudo find $final_path -type f -print0 | xargs -0 sudo chmod 664
  sudo find $final_path -type d -print0 | xargs -0 sudo chmod 775
233e6c697   Alexis Gavoty   Update install
52
  sudo chmod -R 770 $data_path
03e52840d   Kload   Init
53
54
55
56
57
58
  
  # 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
035b88fde   Kload   Try local externa...
59
  # Set permissions to owncloud directories and /home directories + add Home external storage
03e52840d   Kload   Init
60
61
  for i in $(ls /home)
  do
d459457a6   Alexis Gavoty   [fix] typo
62
      sudo yunohost user list --json | grep -q "\"username\": \"$i\""
538aac04e   Alexis Gavoty   [fix] Properly ch...
63
      if [[ $? -eq 0 ]];
03e52840d   Kload   Init
64
      then
353bbee12   Alexis Gavoty   Update install
65
          sudo setfacl -m g:owncloud:rwx /home/$i
b6ed77c7e   Kload   woops
66
          sudo mkdir $data_path/$i
03e52840d   Kload   Init
67
68
69
70
      fi
  done
  
  # Reload Nginx and regenerate SSOwat conf
82d689175   Alexis Gavoty   Update install
71
  sudo service php5-fpm restart
03e52840d   Kload   Init
72
  sudo service nginx reload
aed02bb45   Alexis Gavoty   Update install
73
  sudo yunohost app setting owncloud unprotected_uris -v "/"
03e52840d   Kload   Init
74
75
76
77
  sudo yunohost app ssowatconf
  
  # Owncloud installation via curl
  echo "127.0.0.1 $domain #yunoowncloud" | sudo tee -a /etc/hosts
55626cb3b   Alexis Gavoty   Update install
78
  sleep 1
44bcf46d1   Alexis Gavoty   Update install
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
03e52840d   Kload   Init
80

035b88fde   Kload   Try local externa...
81
  # Enable plugins
03e52840d   Kload   Init
82
  sleep 5
44bcf46d1   Alexis Gavoty   Update install
83
84
  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
035b88fde   Kload   Try local externa...
85
86
  
  # Check if the Mysql database is initialized & running
03e52840d   Kload   Init
87
88
89
90
91
  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
035b88fde   Kload   Try local externa...
92
93
94
95
96
97
98
99
100
      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++
03e52840d   Kload   Init
101
  done
035b88fde   Kload   Try local externa...
102
  # Configure LDAP plugin
82d689175   Alexis Gavoty   Update install
103
  mysql -u $db_user -p$db_pwd $db_user < ../conf/ldap_config.sql
035b88fde   Kload   Try local externa...
104

c89e83d2b   Alexis Gavoty   Update install
105
106
  sudo chown -hR owncloud:owncloud $final_path
  sudo chown -hR owncloud:owncloud $data_path
2e16abc50   Alexis Gavoty   Update install
107
  sudo chmod 755 /home/yunohost.app
08c2e70be   Julien Malik   [fix] Support spa...
108
109
  sudo find $final_path -type f -print0 | xargs -0 sudo chmod 664
  sudo find $final_path -type d -print0 | xargs -0 sudo chmod 775
2e16abc50   Alexis Gavoty   Update install
110
  sudo chmod -R 770 $data_path
c89e83d2b   Alexis Gavoty   Update install
111

be1d85a81   Alexis Gavoty   Update install
112
  # Make an LDAP user as admin
c898b96f2   Alexis Gavoty   Update install
113
  mysql -u $db_user -p$db_pwd $db_user -e "INSERT INTO oc_group_user VALUES ('admin','$user');"
be1d85a81   Alexis Gavoty   Update install
114

31b7f2792   Kload   Upgrade to ownclo...
115
  sudo yunohost app ssowatconf
03e52840d   Kload   Init
116
117
118
  
  # Remove temporary entry in /etc/hosts
  sudo sed -i '/yunoowncloud/d' /etc/hosts