Blame view

scripts/install 3.75 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
ff8b78768   Alexis Gavoty   Update install
7
  password=$4
03e52840d   Kload   Init
8

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

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