Blame view

scripts/install 3.82 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
  # Install dependencies
9e3ff650a   Alexis Gavoty   Update install
20
  sudo apt-get install acl smbclient -y -qq
348d91c95   Alexis Gavoty   Update install
21

03e52840d   Kload   Init
22
  # Generate random password
be1d85a81   Alexis Gavoty   Update install
23
  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
24
25
26
27
28
29
30
31
32
  
  # 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
33
  sudo useradd -d /var/www/owncloud owncloud
03e52840d   Kload   Init
34
35
36
  
  # Copy files to the right place
  final_path=/var/www/owncloud
035b88fde   Kload   Try local externa...
37
  data_path=/home/yunohost.app/owncloud/data
03e52840d   Kload   Init
38
  sudo mkdir -p $final_path
035b88fde   Kload   Try local externa...
39
  sudo mkdir -p $data_path
03e52840d   Kload   Init
40
41
42
  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...
43
  sudo cp ../conf/php-fpm.ini /etc/php5/fpm/conf.d/20-owncloud.ini
a0a7896f8   Alexis Gavoty   Update install
44
  sudo cp ../conf/mount.json $data_path
03e52840d   Kload   Init
45
46
47
48
49
50
  
  # 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
1f5030bd3   Kload   Add hook
51
52
53
54
  sudo sed -i "s@NAMETOCHANGE@owncloud@g" ../hooks/post_user_create
  
  # Add hooks
  sudo yunohost hook add post_user_create ../hooks/post_user_create "50-owncloud"
03e52840d   Kload   Init
55

035b88fde   Kload   Try local externa...
56
  # Set permissions to owncloud directories and /home directories + add Home external storage
03e52840d   Kload   Init
57
58
59
60
  for i in $(ls /home)
  do
      if [[ ! $i == yunohost.* ]];
      then
353bbee12   Alexis Gavoty   Update install
61
          sudo setfacl -m g:owncloud:rwx /home/$i
b6ed77c7e   Kload   woops
62
          sudo mkdir $data_path/$i
03e52840d   Kload   Init
63
64
      fi
  done
035b88fde   Kload   Try local externa...
65
66
  sudo chown -hR owncloud: $final_path
  sudo chown -hR owncloud: $data_path
03e52840d   Kload   Init
67
68
  
  # Reload Nginx and regenerate SSOwat conf
82d689175   Alexis Gavoty   Update install
69
  sudo service php5-fpm restart
03e52840d   Kload   Init
70
  sudo service nginx reload
31b7f2792   Kload   Upgrade to ownclo...
71
  sudo yunohost app setting owncloud skipped_uris -v "/"
03e52840d   Kload   Init
72
73
74
75
  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
76
  sleep 1
44bcf46d1   Alexis Gavoty   Update install
77
  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
78

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

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

035b88fde   Kload   Try local externa...
106
  # Unprotect URIs
bd5efccb8   Alexis Gavoty   Update install
107
  sudo yunohost app setting owncloud skipped_uris -v "/public.php,/core,/apps/files,/index.php/apps/files"
8173dbb68   Alexis Gavoty   Update install
108
  sudo yunohost app setting owncloud unprotected_uris -v "/remote.php,/cron.php,/status.php"
31b7f2792   Kload   Upgrade to ownclo...
109
  sudo yunohost app ssowatconf
03e52840d   Kload   Init
110
111
112
  
  # Remove temporary entry in /etc/hosts
  sudo sed -i '/yunoowncloud/d' /etc/hosts