Blame view

scripts/install 4.02 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
769474052   matanya   check if admin ex...
9
  sudo yunohost user list --json | grep -qi "\"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
7db095639   Alexis Gavoty   Update install
21
22
  # Remove trailing "/" for next commands
  path=${path%/}
348d91c95   Alexis Gavoty   Update install
23
  # Install dependencies
9e3ff650a   Alexis Gavoty   Update install
24
  sudo apt-get install acl smbclient -y -qq
348d91c95   Alexis Gavoty   Update install
25

03e52840d   Kload   Init
26
  # Generate random password
be1d85a81   Alexis Gavoty   Update install
27
  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
28
29
30
31
32
33
34
35
36
  
  # 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
a0a7896f8   Alexis Gavoty   Update install
47
  sudo cp ../conf/mount.json $data_path
0f328c944   Alexis Gavoty   Update install
48
49
  sudo chown -hR owncloud:www-data $final_path
  sudo chown -hR owncloud:www-data $data_path
d4f5dce5a   npze   Parent dir of /da...
50
  sudo chown owncloud:www-data /home/yunohost.app/owncloud
a87b65ea9   Alexis Gavoty   Update install
51
  sudo chmod 755 /home/yunohost.app
d658270fc   Alexis Gavoty   Update install
52
  sudo chmod 664 -R $final_path
08c2e70be   Julien Malik   [fix] Support spa...
53
  sudo find $final_path -type d -print0 | xargs -0 sudo chmod 775
233e6c697   Alexis Gavoty   Update install
54
  sudo chmod -R 770 $data_path
03e52840d   Kload   Init
55
56
57
58
59
60
  
  # 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...
61
  # Set permissions to owncloud directories and /home directories + add Home external storage
03e52840d   Kload   Init
62
63
  for i in $(ls /home)
  do
d459457a6   Alexis Gavoty   [fix] typo
64
      sudo yunohost user list --json | grep -q "\"username\": \"$i\""
538aac04e   Alexis Gavoty   [fix] Properly ch...
65
      if [[ $? -eq 0 ]];
03e52840d   Kload   Init
66
      then
353bbee12   Alexis Gavoty   Update install
67
          sudo setfacl -m g:owncloud:rwx /home/$i
b6ed77c7e   Kload   woops
68
          sudo mkdir $data_path/$i
03e52840d   Kload   Init
69
70
71
72
      fi
  done
  
  # Reload Nginx and regenerate SSOwat conf
82d689175   Alexis Gavoty   Update install
73
  sudo service php5-fpm restart
03e52840d   Kload   Init
74
  sudo service nginx reload
302dc1613   Alexis Gavoty   Update install
75
  sudo yunohost app setting owncloud unprotected_uris -v "/"
03e52840d   Kload   Init
76
77
78
  sudo yunohost app ssowatconf
  
  # Owncloud installation via curl
cd048276c   Alexis Gavoty   Update install
79
  curl -kL -H "Host: $domain" -X POST https://127.0.0.1/$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
cd048276c   Alexis Gavoty   Update install
83
84
  curl -kL -H "Host: $domain" -X POST https://127.0.0.1/$path/index.php/settings/ajax/enableapp.php --data "appid=files_external" -u "admin:$db_pwd" > /dev/null 2>&1
  curl -kL -H "Host: $domain" -X POST https://127.0.0.1/$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
      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
4f6b0d456   Alexis Gavoty   Update install
97
          echo "Web installation failed"
035b88fde   Kload   Try local externa...
98
99
100
          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