Blame view

scripts/install 3.67 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
9
10
11
  # Check user parameter
  ls /home | grep $user
  if [[ ! $? -eq 0 ]]; then
      echo "Wrong user"
bcdcd2d21   Alexis Gavoty   Update install
12
13
      exit 1
  fi
03e52840d   Kload   Init
14
15
16
17
18
  # Check domain/path availability
  sudo yunohost app checkurl $domain$path -a owncloud
  if [[ ! $? -eq 0 ]]; then
      exit 1
  fi
348d91c95   Alexis Gavoty   Update install
19
20
  # Install dependencies
  sudo apt-get install acl
03e52840d   Kload   Init
21
22
23
24
25
26
27
28
29
30
31
  # 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
71f9ee4c3   Alexis Gavoty   Update install
32
  sudo useradd -d /var/www/owncloud owncloud
03e52840d   Kload   Init
33
34
35
  
  # Copy files to the right place
  final_path=/var/www/owncloud
035b88fde   Kload   Try local externa...
36
  data_path=/home/yunohost.app/owncloud/data
03e52840d   Kload   Init
37
  sudo mkdir -p $final_path
035b88fde   Kload   Try local externa...
38
  sudo mkdir -p $data_path
03e52840d   Kload   Init
39
40
41
  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
1b87c3257   Kload   Increase file upl...
42
  sudo cp ../conf/php-fpm.ini /etc/php5/fpm/conf.d/20-owncloud.ini
03e52840d   Kload   Init
43
44
45
46
47
48
  
  # 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...
49
  # Set permissions to owncloud directories and /home directories + add Home external storage
03e52840d   Kload   Init
50
51
52
53
  for i in $(ls /home)
  do
      if [[ ! $i == yunohost.* ]];
      then
353bbee12   Alexis Gavoty   Update install
54
          sudo setfacl -m g:owncloud:rwx /home/$i
b6ed77c7e   Kload   woops
55
56
          sudo mkdir $data_path/$i
          echo "{\"user\":{\"$i\":{\"/\$user/files/Home\":{\"class\":\"\\OC\\Files\\Storage\\Local\",\"options\":{\"datadir\":\"/home/$i\"}}}}}" | sudo tee $data_path/$i/mount.json
03e52840d   Kload   Init
57
58
      fi
  done
035b88fde   Kload   Try local externa...
59
60
  sudo chown -hR owncloud: $final_path
  sudo chown -hR owncloud: $data_path
03e52840d   Kload   Init
61
62
  
  # Reload Nginx and regenerate SSOwat conf
82d689175   Alexis Gavoty   Update install
63
  sudo service php5-fpm restart
03e52840d   Kload   Init
64
  sudo service nginx reload
31b7f2792   Kload   Upgrade to ownclo...
65
  sudo yunohost app setting owncloud skipped_uris -v "/"
03e52840d   Kload   Init
66
67
68
69
  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
70
  sleep 1
035b88fde   Kload   Try local externa...
71
  curl -kL -X POST https://$domain$path/index.php --data "install=true&adminlogin=$user&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
72

035b88fde   Kload   Try local externa...
73
  # Enable plugins
03e52840d   Kload   Init
74
  sleep 5
035b88fde   Kload   Try local externa...
75
76
77
78
  curl -kL -X POST https://$domain$path/index.php/settings/ajax/enableapp.php --data "appid=files_external" -u "$user:$db_pwd" > /dev/null 2>&1
  curl -kL -X POST https://$domain$path/index.php/settings/ajax/enableapp.php --data "appid=user_ldap" -u "$user:$db_pwd" > /dev/null 2>&1
  
  # Check if the Mysql database is initialized & running
03e52840d   Kload   Init
79
80
81
82
83
  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...
84
85
86
87
88
89
90
91
92
      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
93
  done
035b88fde   Kload   Try local externa...
94
  # Configure LDAP plugin
82d689175   Alexis Gavoty   Update install
95
  mysql -u $db_user -p$db_pwd $db_user < ../conf/ldap_config.sql
035b88fde   Kload   Try local externa...
96
97
  
  # Unprotect URIs
bd5efccb8   Alexis Gavoty   Update install
98
  sudo yunohost app setting owncloud skipped_uris -v "/public.php,/core,/apps/files,/index.php/apps/files"
8173dbb68   Alexis Gavoty   Update install
99
  sudo yunohost app setting owncloud unprotected_uris -v "/remote.php,/cron.php,/status.php"
31b7f2792   Kload   Upgrade to ownclo...
100
  sudo yunohost app ssowatconf
03e52840d   Kload   Init
101
102
103
  
  # Remove temporary entry in /etc/hosts
  sudo sed -i '/yunoowncloud/d' /etc/hosts