|
3 | 3 | # Home Assistant Community Add-on: Bookstack |
4 | 4 | # This file validates config, creates the database and configures the app key |
5 | 5 | # ============================================================================== |
6 | | - |
| 6 | +declare host |
7 | 7 | declare key |
| 8 | +declare password |
| 9 | +declare port |
| 10 | +declare username |
| 11 | + |
| 12 | +if bashio::config.has_value 'remote_mysql_host'; then |
| 13 | + if ! bashio::config.has_value 'remote_mysql_database'; then |
| 14 | + bashio::exit.nok \ |
| 15 | + "Remote database has been specified but no database is configured" |
| 16 | + fi |
| 17 | + |
| 18 | + if ! bashio::config.has_value 'remote_mysql_username'; then |
| 19 | + bashio::exit.nok \ |
| 20 | + "Remote database has been specified but no username is configured" |
| 21 | + fi |
8 | 22 |
|
9 | | -if bashio::config.has_value 'remote_mysql_host';then |
10 | | - if ! bashio::config.has_value 'remote_mysql_database';then |
11 | | - bashio::log.fatal \ |
12 | | - "Remote database has been specified but no database is configured" |
13 | | - bashio::exit.nok |
14 | | - fi |
15 | | - if ! bashio::config.has_value 'remote_mysql_username';then |
16 | | - bashio::log.fatal \ |
17 | | - "Remote database has been specified but no username is configured" |
18 | | - bashio::exit.nok |
19 | | - fi |
20 | | - if ! bashio::config.has_value 'remote_mysql_password';then |
21 | | - bashio::log.fatal \ |
22 | | - "Remote database has been specified but no password is configured" |
23 | | - bashio::exit.nok |
24 | | - fi |
25 | | - if ! bashio::config.exists 'remote_mysql_port';then |
26 | | - bashio::log.fatal \ |
27 | | - "Remote database has been specified but no port is configured" |
28 | | - bashio::exit.nok |
29 | | - fi |
| 23 | + if ! bashio::config.has_value 'remote_mysql_password'; then |
| 24 | + bashio::log.fatal \ |
| 25 | + "Remote database has been specified but no password is configured" |
| 26 | + fi |
| 27 | + |
| 28 | + if ! bashio::config.exists 'remote_mysql_port'; then |
| 29 | + bashio::exit.nok \ |
| 30 | + "Remote database has been specified but no port is configured" |
| 31 | + fi |
30 | 32 | else |
31 | | - if ! bashio::services.available 'mysql';then |
32 | | - bashio::log.fatal \ |
33 | | - "Local database access should be provided by the MariaDB addon" |
34 | | - bashio::log.fatal \ |
35 | | - "Please ensure it is installed and started" |
36 | | - bashio::exit.nok |
37 | | - fi |
38 | | - host=$(bashio::services "mysql" "host") |
39 | | - password=$(bashio::services "mysql" "password") |
40 | | - port=$(bashio::services "mysql" "port") |
41 | | - username=$(bashio::services "mysql" "username") |
| 33 | + if ! bashio::services.available 'mysql'; then |
| 34 | + bashio::log.fatal \ |
| 35 | + "Local database access should be provided by the MariaDB addon" |
| 36 | + bashio::exit.nok \ |
| 37 | + "Please ensure it is installed and started" |
| 38 | + fi |
| 39 | + |
| 40 | + host=$(bashio::services "mysql" "host") |
| 41 | + password=$(bashio::services "mysql" "password") |
| 42 | + port=$(bashio::services "mysql" "port") |
| 43 | + username=$(bashio::services "mysql" "username") |
| 44 | + |
| 45 | + bashio::log.warning "Bookstack is using the Maria DB addon" |
| 46 | + bashio::log.warning "Please ensure this is included in your backups" |
| 47 | + bashio::log.warning "Uninstalling the MariaDB addon will remove any data" |
42 | 48 |
|
43 | | - bashio::log.warning "Bookstack is using the Maria DB addon" |
44 | | - bashio::log.warning "Please ensure this is included in your backups" |
45 | | - bashio::log.warning "Uninstalling the MariaDB addon will remove any data" |
46 | | - bashio::log.info "Creating database for Bookstack if required" |
47 | | - mysql \ |
48 | | - -u "${username}" -p"${password}" \ |
49 | | - -h "${host}" -P "${port}" \ |
50 | | - -e "CREATE DATABASE IF NOT EXISTS \`bookstack\` ;" |
51 | | - |
| 49 | + bashio::log.info "Creating database for Bookstack if required" |
| 50 | + mysql \ |
| 51 | + -u "${username}" -p"${password}" \ |
| 52 | + -h "${host}" -P "${port}" \ |
| 53 | + -e "CREATE DATABASE IF NOT EXISTS \`bookstack\` ;" |
52 | 54 | fi |
| 55 | + |
53 | 56 | if ! bashio::fs.directory_exists "/data/bookstack/uploads"; then |
54 | 57 | bashio::log "Creating uploads directory" |
55 | 58 | mkdir -p /data/bookstack/uploads |
56 | 59 | chown nginx:nginx /data/bookstack/uploads |
57 | 60 | fi |
| 61 | + |
58 | 62 | if ! bashio::fs.directory_exists "/data/bookstack/files"; then |
59 | 63 | bashio::log "Creating files directory" |
60 | 64 | mkdir -p /data/bookstack/files |
61 | 65 | chown nginx:nginx /data/bookstack/files |
62 | 66 | fi |
| 67 | + |
63 | 68 | if ! bashio::fs.directory_exists "/data/bookstack/images"; then |
64 | 69 | bashio::log "Creating images directory" |
65 | 70 | mkdir -p /data/bookstack/images |
66 | 71 | chown nginx:nginx /data/bookstack/images |
67 | 72 | fi |
| 73 | + |
68 | 74 | rm -r /var/www/bookstack/storage/uploads/files |
69 | 75 | rm -r /var/www/bookstack/storage/uploads/images |
70 | 76 | rm -r /var/www/bookstack/public/uploads |
71 | 77 | ln -s /data/bookstack/files /var/www/bookstack/storage/uploads/files |
72 | 78 | ln -s /data/bookstack/images /var/www/bookstack/storage/uploads/images |
73 | 79 | ln -s /data/bookstack/uploads /var/www/bookstack/public/uploads |
| 80 | +ln -sf /dev/stderr /var/www/bookstack/storage/logs/laravel.log |
74 | 81 |
|
75 | 82 | # Create API key if needed |
76 | 83 | if ! bashio::fs.file_exists "/data/bookstack/appkey.txt"; then |
77 | | - bashio::log.info "Generating app key" |
78 | | - key=$(php /var/www/bookstack/artisan key:generate --show) |
79 | | - echo "${key}" > /data/bookstack/appkey.txt |
80 | | - bashio::log.info "App Key generated: ${key}" |
| 84 | + bashio::log.info "Generating app key" |
| 85 | + key=$(php /var/www/bookstack/artisan key:generate --show) |
| 86 | + echo "${key}" > /data/bookstack/appkey.txt |
| 87 | + bashio::log.info "App Key generated: ${key}" |
81 | 88 | fi |
82 | | -ln -sf /dev/stderr /var/www/bookstack/storage/logs/laravel.log |
|
0 commit comments