freedombone-app-koel 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # koel application
  12. # https://gist.github.com/bplower/613a99156d603abac083
  13. #
  14. # License
  15. # =======
  16. #
  17. # Copyright (C) 2017 Bob Mottram <bob@freedombone.net>
  18. #
  19. # This program is free software: you can redistribute it and/or modify
  20. # it under the terms of the GNU Affero General Public License as published by
  21. # the Free Software Foundation, either version 3 of the License, or
  22. # (at your option) any later version.
  23. #
  24. # This program is distributed in the hope that it will be useful,
  25. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  27. # GNU Affero General Public License for more details.
  28. #
  29. # You should have received a copy of the GNU Affero General Public License
  30. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  31. VARIANTS='full full-vim media'
  32. IN_DEFAULT_INSTALL=0
  33. SHOW_ON_ABOUT=1
  34. KOEL_DOMAIN_NAME=
  35. KOEL_CODE=
  36. KOEL_ONION_PORT=8118
  37. KOEL_PORT=9002
  38. KOEL_REPO="https://github.com/phanan/koel"
  39. KOEL_COMMIT='70464a8977b1058f3bd0a4ec77877fe7894d8d84'
  40. KOEL_ADMIN_PASSWORD=
  41. koel_variables=(ONION_ONLY
  42. KOEL_DOMAIN_NAME
  43. KOEL_CODE
  44. DDNS_PROVIDER
  45. MY_EMAIL_ADDRESS
  46. MY_USERNAME)
  47. function remove_user_koel {
  48. remove_username="$1"
  49. ${PROJECT_NAME}-pass -u $remove_username --rmapp koel
  50. }
  51. function add_user_koel {
  52. new_username="$1"
  53. new_user_password="$2"
  54. ${PROJECT_NAME}-pass -u $new_username -a koel -p "$new_user_password"
  55. echo '0'
  56. }
  57. function install_interactive_koel {
  58. if [ ! $ONION_ONLY ]; then
  59. ONION_ONLY='no'
  60. fi
  61. if [[ $ONION_ONLY != "no" ]]; then
  62. KOEL_DOMAIN_NAME='koel.local'
  63. else
  64. KOEL_DETAILS_COMPLETE=
  65. while [ ! $KOEL_DETAILS_COMPLETE ]
  66. do
  67. data=$(tempfile 2>/dev/null)
  68. trap "rm -f $data" 0 1 2 5 15
  69. if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
  70. dialog --backtitle $"Freedombone Configuration" \
  71. --title $"Koel Configuration" \
  72. --form $"\nPlease enter your Koel details. The background image URL can be left blank.\n\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 16 65 3 \
  73. $"Domain:" 1 1 "$(grep 'KOEL_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
  74. $"Code:" 2 1 "$(grep 'KOEL_CODE' temp.cfg | awk -F '=' '{print $2}')" 2 25 33 255 \
  75. 2> $data
  76. else
  77. dialog --backtitle $"Freedombone Configuration" \
  78. --title $"Koel Configuration" \
  79. --form $"\nPlease enter your Koel details. The background image URL can be left blank.\n\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 16 65 3 \
  80. $"Domain:" 1 1 "$(grep 'KOEL_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
  81. 2> $data
  82. fi
  83. sel=$?
  84. case $sel in
  85. 1) exit 1;;
  86. 255) exit 1;;
  87. esac
  88. KOEL_DOMAIN_NAME=$(cat $data | sed -n 1p)
  89. if [ $KOEL_DOMAIN_NAME ]; then
  90. if [[ $KOEL_DOMAIN_NAME == "$HUBZILLA_DOMAIN_NAME" ]]; then
  91. KOEL_DOMAIN_NAME=""
  92. fi
  93. TEST_DOMAIN_NAME=$KOEL_DOMAIN_NAME
  94. validate_domain_name
  95. if [[ $TEST_DOMAIN_NAME != $KOEL_DOMAIN_NAME ]]; then
  96. KOEL_DOMAIN_NAME=
  97. dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
  98. else
  99. if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
  100. KOEL_CODE=$(cat $data | sed -n 2p)
  101. validate_freedns_code "$KOEL_CODE"
  102. if [ ! $VALID_CODE ]; then
  103. KOEL_DOMAIN_NAME=
  104. fi
  105. fi
  106. fi
  107. fi
  108. if [ $KOEL_DOMAIN_NAME ]; then
  109. KOEL_DETAILS_COMPLETE="yes"
  110. fi
  111. done
  112. # save the results in the config file
  113. write_config_param "KOEL_CODE" "$KOEL_CODE"
  114. fi
  115. write_config_param "KOEL_DOMAIN_NAME" "$KOEL_DOMAIN_NAME"
  116. APP_INSTALLED=1
  117. }
  118. function change_password_koel {
  119. curr_username="$1"
  120. new_user_password="$2"
  121. read_config_param 'KOEL_DOMAIN_NAME'
  122. ${PROJECT_NAME}-pass -u "$curr_username" -a koel -p "$new_user_password"
  123. }
  124. function koel_create_database {
  125. if [ -f $IMAGE_PASSWORD_FILE ]; then
  126. KOEL_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
  127. else
  128. if [ ! $KOEL_ADMIN_PASSWORD ]; then
  129. KOEL_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
  130. fi
  131. fi
  132. if [ ! $KOEL_ADMIN_PASSWORD ]; then
  133. return
  134. fi
  135. function_check create_database
  136. create_database koel "$KOEL_ADMIN_PASSWORD" $MY_USERNAME
  137. }
  138. function reconfigure_koel {
  139. echo -n ''
  140. }
  141. function configure_interactive_koel {
  142. echo -n ''
  143. }
  144. function upgrade_koel {
  145. if grep -q "koel domain" $COMPLETION_FILE; then
  146. KOEL_DOMAIN_NAME=$(get_completion_param "koel domain")
  147. fi
  148. # update to the next commit
  149. function_check set_repo_commit
  150. set_repo_commit /var/www/$KOEL_DOMAIN_NAME/htdocs "koel commit" "$KOEL_COMMIT" $KOEL_REPO
  151. chown -R www-data:www-data /var/www/${KOEL_DOMAIN_NAME}/htdocs
  152. }
  153. function backup_local_koel {
  154. KOEL_DOMAIN_NAME='koel'
  155. if grep -q "koel domain" $COMPLETION_FILE; then
  156. KOEL_DOMAIN_NAME=$(get_completion_param "koel domain")
  157. fi
  158. source_directory=/var/www/${KOEL_DOMAIN_NAME}/htdocs
  159. if [ -d $source_directory ]; then
  160. dest_directory=koel
  161. function_check suspend_site
  162. suspend_site ${KOEL_DOMAIN_NAME}
  163. function_check backup_directory_to_usb
  164. backup_directory_to_usb $source_directory $dest_directory
  165. function_check backup_database_to_usb
  166. backup_database_to_usb koel
  167. function_check restart_site
  168. restart_site
  169. fi
  170. }
  171. function restore_local_koel {
  172. if ! grep -q "koel domain" $COMPLETION_FILE; then
  173. return
  174. fi
  175. KOEL_DOMAIN_NAME=$(get_completion_param "koel domain")
  176. if [ $KOEL_DOMAIN_NAME ]; then
  177. echo $"Restoring koel"
  178. temp_restore_dir=/root/tempkoel
  179. koel_dir=/var/www/${KOEL_DOMAIN_NAME}/htdocs
  180. function_check koel_create_database
  181. koel_create_database
  182. restore_database koel ${KOEL_DOMAIN_NAME}
  183. if [ -d $temp_restore_dir ]; then
  184. rm -rf $temp_restore_dir
  185. fi
  186. fi
  187. }
  188. function backup_remote_koel {
  189. if grep -q "koel domain" $COMPLETION_FILE; then
  190. KOEL_DOMAIN_NAME=$(get_completion_param "koel domain")
  191. temp_backup_dir=/var/www/${KOEL_DOMAIN_NAME}/htdocs
  192. if [ -d $temp_backup_dir ]; then
  193. function_check suspend_site
  194. suspend_site ${KOEL_DOMAIN_NAME}
  195. function_check backup_database_to_friend
  196. backup_database_to_friend koel
  197. echo $"Backing up Koel installation"
  198. function_check backup_directory_to_friend
  199. backup_directory_to_friend $temp_backup_dir koel
  200. function_check restart_site
  201. restart_site
  202. else
  203. echo $"koel domain specified but not found in ${temp_backup_dir}"
  204. fi
  205. fi
  206. }
  207. function restore_remote_koel {
  208. if grep -q "koel domain" $COMPLETION_FILE; then
  209. echo $"Restoring koel"
  210. KOEL_DOMAIN_NAME=$(get_completion_param "koel domain")
  211. # stop the daemons
  212. cd /var/www/${KOEL_DOMAIN_NAME}/htdocs
  213. su -c "sh scripts/stopdaemons.sh" -s /bin/sh www-data
  214. function_check koel_create_database
  215. koel_create_database
  216. function_check restore_database_from_friend
  217. restore_database_from_friend koel ${KOEL_DOMAIN_NAME}
  218. if [ -d /root/tempkoel ]; then
  219. rm -rf /root/tempkoel
  220. fi
  221. # start the daemons
  222. cd /var/www/${KOEL_DOMAIN_NAME}/htdocs
  223. su -c "sh scripts/startdaemons.sh" -s /bin/sh www-data
  224. echo $"Restore of koel complete"
  225. fi
  226. }
  227. function remove_koel {
  228. if [ ${#KOEL_DOMAIN_NAME} -eq 0 ]; then
  229. return
  230. fi
  231. systemctl stop koel
  232. systemctl disable koel
  233. if [ -f /etc/systemd/system/koel.service ]; then
  234. rm /etc/systemd/system/koel.service
  235. fi
  236. function_check remove_nodejs
  237. remove_nodejs koel
  238. read_config_param "KOEL_DOMAIN_NAME"
  239. read_config_param "MY_USERNAME"
  240. echo "Removing $KOEL_DOMAIN_NAME"
  241. nginx_dissite $KOEL_DOMAIN_NAME
  242. remove_certs $KOEL_DOMAIN_NAME
  243. if [ -d /var/www/$KOEL_DOMAIN_NAME ]; then
  244. rm -rf /var/www/$KOEL_DOMAIN_NAME
  245. fi
  246. if [ -f /etc/nginx/sites-available/$KOEL_DOMAIN_NAME ]; then
  247. rm /etc/nginx/sites-available/$KOEL_DOMAIN_NAME
  248. fi
  249. function_check drop_database
  250. drop_database koel
  251. function_check remove_onion_service
  252. remove_onion_service koel ${KOEL_ONION_PORT}
  253. if grep -q "koel" /etc/crontab; then
  254. sed -i "/koel/d" /etc/crontab
  255. fi
  256. remove_app koel
  257. remove_completion_param install_koel
  258. sed -i '/koel/d' $COMPLETION_FILE
  259. remove_backup_database_local koel
  260. sed -i '/koel-firewall/d' /etc/crontab
  261. function_check remove_ddns_domain
  262. remove_ddns_domain $KOEL_DOMAIN_NAME
  263. }
  264. function install_koel_main {
  265. if [ ! $KOEL_DOMAIN_NAME ]; then
  266. echo $'No domain name was given for koel'
  267. exit 7359
  268. fi
  269. if [[ $(app_is_installed koel_main) == "1" ]]; then
  270. return
  271. fi
  272. function_check install_mariadb
  273. install_mariadb
  274. function_check get_mariadb_password
  275. get_mariadb_password
  276. function_check repair_databases_script
  277. repair_databases_script
  278. apt-get -yq install php-gettext php5-curl php5-gd php5-mysql git curl php-xml-parser
  279. apt-get -yq install php5-memcached php5-intl exiftool
  280. if [ ! -d /var/www/$KOEL_DOMAIN_NAME ]; then
  281. mkdir /var/www/$KOEL_DOMAIN_NAME
  282. fi
  283. if [ ! -d /var/www/$KOEL_DOMAIN_NAME/htdocs ]; then
  284. function_check git_clone
  285. git_clone $KOEL_REPO /var/www/$KOEL_DOMAIN_NAME/htdocs
  286. if [ ! -d /var/www/$KOEL_DOMAIN_NAME/htdocs ]; then
  287. echo $'Unable to clone koel repo'
  288. exit 365735
  289. fi
  290. fi
  291. cd /var/www/$KOEL_DOMAIN_NAME/htdocs
  292. git checkout $KOEL_COMMIT -b $KOEL_COMMIT
  293. set_completion_param "koel commit" "$KOEL_COMMIT"
  294. chown -R www-data:www-data /var/www/$KOEL_DOMAIN_NAME/htdocs
  295. function_check koel_create_database
  296. koel_create_database
  297. function_check add_ddns_domain
  298. add_ddns_domain $KOEL_DOMAIN_NAME
  299. koel_nginx_site=/etc/nginx/sites-available/$KOEL_DOMAIN_NAME
  300. if [[ $ONION_ONLY == "no" ]]; then
  301. function_check nginx_http_redirect
  302. nginx_http_redirect $KOEL_DOMAIN_NAME "index index.php"
  303. echo 'server {' >> $koel_nginx_site
  304. echo ' listen 443 ssl;' >> $koel_nginx_site
  305. echo ' listen [::]:443 ssl;' >> $koel_nginx_site
  306. echo " server_name $KOEL_DOMAIN_NAME;" >> $koel_nginx_site
  307. echo '' >> $koel_nginx_site
  308. function_check nginx_compress
  309. nginx_compress $KOEL_DOMAIN_NAME
  310. echo ' gzip_comp_level 9;' >> $koel_nginx_site
  311. echo '' >> $koel_nginx_site
  312. echo ' # Security' >> $koel_nginx_site
  313. function_check nginx_ssl mobile
  314. nginx_ssl $KOEL_DOMAIN_NAME
  315. function_check nginx_disable_sniffing
  316. nginx_disable_sniffing $KOEL_DOMAIN_NAME
  317. echo ' add_header Strict-Transport-Security max-age=15768000;' >> $koel_nginx_site
  318. echo '' >> $koel_nginx_site
  319. echo ' # Logs' >> $koel_nginx_site
  320. echo ' access_log /dev/null;' >> $koel_nginx_site
  321. echo ' error_log /dev/null;' >> $koel_nginx_site
  322. echo '' >> $koel_nginx_site
  323. echo ' # Root' >> $koel_nginx_site
  324. echo " root /var/www/$KOEL_DOMAIN_NAME/htdocs;" >> $koel_nginx_site
  325. echo '' >> $koel_nginx_site
  326. echo ' # Index' >> $koel_nginx_site
  327. echo ' index index.php;' >> $koel_nginx_site
  328. echo '' >> $koel_nginx_site
  329. echo ' # Whitelist only index.php, robots.txt, and those start with public/ or api/' >> $koel_nginx_site
  330. echo ' if ($request_uri !~ ^/$|index\.php|robots\.txt|api/|public/) {' >> $koel_nginx_site
  331. echo ' return 404;' >> $koel_nginx_site
  332. echo ' }' >> $koel_nginx_site
  333. echo '' >> $koel_nginx_site
  334. echo ' location /media/ {' >> $koel_nginx_site
  335. echo ' internal;' >> $koel_nginx_site
  336. echo '' >> $koel_nginx_site
  337. echo ' # A X-Media-Root should be set to media_path settings from upstream' >> $koel_nginx_site
  338. echo ' alias $upstream_http_x_media_root;' >> $koel_nginx_site
  339. echo '' >> $koel_nginx_site
  340. echo ' }' >> $koel_nginx_site
  341. echo '' >> $koel_nginx_site
  342. echo ' # PHP' >> $koel_nginx_site
  343. echo ' location ~ \.php {' >> $koel_nginx_site
  344. echo ' include snippets/fastcgi-php.conf;' >> $koel_nginx_site
  345. echo ' fastcgi_pass unix:/var/run/php5-fpm.sock;' >> $koel_nginx_site
  346. echo ' }' >> $koel_nginx_site
  347. echo '' >> $koel_nginx_site
  348. echo ' # Location' >> $koel_nginx_site
  349. echo ' location / {' >> $koel_nginx_site
  350. function_check nginx_limits
  351. nginx_limits $KOEL_DOMAIN_NAME '15m'
  352. echo ' try_files $uri $uri/ @koel;' >> $koel_nginx_site
  353. echo ' }' >> $koel_nginx_site
  354. echo '' >> $koel_nginx_site
  355. echo ' # Fancy URLs' >> $koel_nginx_site
  356. echo ' location @koel {' >> $koel_nginx_site
  357. echo ' rewrite ^(.*)$ /index.php?p=$1 last;' >> $koel_nginx_site
  358. echo ' }' >> $koel_nginx_site
  359. echo '' >> $koel_nginx_site
  360. echo ' # Restrict access that is unnecessary anyway' >> $koel_nginx_site
  361. echo ' location ~ /\.(ht|git) {' >> $koel_nginx_site
  362. echo ' deny all;' >> $koel_nginx_site
  363. echo ' }' >> $koel_nginx_site
  364. echo '' >> $koel_nginx_site
  365. echo '}' >> $koel_nginx_site
  366. else
  367. echo -n '' > $koel_nginx_site
  368. fi
  369. echo 'server {' >> $koel_nginx_site
  370. echo " listen 127.0.0.1:$KOEL_ONION_PORT default_server;" >> $koel_nginx_site
  371. echo " server_name $KOEL_DOMAIN_NAME;" >> $koel_nginx_site
  372. echo '' >> $koel_nginx_site
  373. function_check nginx_compress
  374. nginx_compress $KOEL_DOMAIN_NAME
  375. echo ' gzip_comp_level 9;' >> $koel_nginx_site
  376. echo '' >> $koel_nginx_site
  377. echo ' # Logs' >> $koel_nginx_site
  378. echo ' access_log /dev/null;' >> $koel_nginx_site
  379. echo ' error_log /dev/null;' >> $koel_nginx_site
  380. echo '' >> $koel_nginx_site
  381. echo ' # Root' >> $koel_nginx_site
  382. echo " root /var/www/$KOEL_DOMAIN_NAME/htdocs;" >> $koel_nginx_site
  383. echo '' >> $koel_nginx_site
  384. echo ' # Index' >> $koel_nginx_site
  385. echo ' index index.php;' >> $koel_nginx_site
  386. echo '' >> $koel_nginx_site
  387. echo ' # Whitelist only index.php, robots.txt, and those start with public/ or api/' >> $koel_nginx_site
  388. echo ' if ($request_uri !~ ^/$|index\.php|robots\.txt|api/|public/) {' >> $koel_nginx_site
  389. echo ' return 404;' >> $koel_nginx_site
  390. echo ' }' >> $koel_nginx_site
  391. echo '' >> $koel_nginx_site
  392. echo ' location /media/ {' >> $koel_nginx_site
  393. echo ' internal;' >> $koel_nginx_site
  394. echo '' >> $koel_nginx_site
  395. echo ' # A X-Media-Root should be set to media_path settings from upstream' >> $koel_nginx_site
  396. echo ' alias $upstream_http_x_media_root;' >> $koel_nginx_site
  397. echo '' >> $koel_nginx_site
  398. echo ' }' >> $koel_nginx_site
  399. echo '' >> $koel_nginx_site
  400. echo ' # PHP' >> $koel_nginx_site
  401. echo ' location ~ \.php {' >> $koel_nginx_site
  402. echo ' include snippets/fastcgi-php.conf;' >> $koel_nginx_site
  403. echo ' fastcgi_pass unix:/var/run/php5-fpm.sock;' >> $koel_nginx_site
  404. echo ' }' >> $koel_nginx_site
  405. echo '' >> $koel_nginx_site
  406. echo ' # Location' >> $koel_nginx_site
  407. echo ' location / {' >> $koel_nginx_site
  408. function_check nginx_limits
  409. nginx_limits $KOEL_DOMAIN_NAME '15m'
  410. echo ' try_files $uri $uri/ @koel;' >> $koel_nginx_site
  411. echo ' }' >> $koel_nginx_site
  412. echo '' >> $koel_nginx_site
  413. echo ' # Fancy URLs' >> $koel_nginx_site
  414. echo ' location @koel {' >> $koel_nginx_site
  415. echo ' rewrite ^(.*)$ /index.php?p=$1 last;' >> $koel_nginx_site
  416. echo ' }' >> $koel_nginx_site
  417. echo '' >> $koel_nginx_site
  418. echo ' # Restrict access that is unnecessary anyway' >> $koel_nginx_site
  419. echo ' location ~ /\.(ht|git) {' >> $koel_nginx_site
  420. echo ' deny all;' >> $koel_nginx_site
  421. echo ' }' >> $koel_nginx_site
  422. echo '' >> $koel_nginx_site
  423. echo '}' >> $koel_nginx_site
  424. sed -i 's|gzip_types.*|gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript application/json;|g' $koel_nginx_site
  425. sed -i 's|DENY;|SAMEORIGIN;|g' $koel_nginx_site
  426. function_check configure_php
  427. configure_php
  428. function_check create_site_certificate
  429. create_site_certificate $KOEL_DOMAIN_NAME 'yes'
  430. # Ensure that the database gets backed up locally, if remote
  431. # backups are not being used
  432. function_check backup_databases_script_header
  433. backup_databases_script_header
  434. function_check backup_database_local
  435. backup_database_local koel
  436. function_check nginx_ensite
  437. nginx_ensite $KOEL_DOMAIN_NAME
  438. KOEL_ONION_HOSTNAME=$(add_onion_service koel 80 ${KOEL_ONION_PORT})
  439. KOEL_SERVER=${KOEL_DOMAIN_NAME}
  440. if [[ $ONION_ONLY != 'no' ]]; then
  441. KOEL_SERVER=${KOEL_ONION_HOSTNAME}
  442. fi
  443. systemctl restart php5-fpm
  444. systemctl restart nginx
  445. ${PROJECT_NAME}-pass -u $MY_USERNAME -a koel -p "$KOEL_ADMIN_PASSWORD"
  446. set_completion_param "koel domain" "$KOEL_DOMAIN_NAME"
  447. install_completed koel_main
  448. }
  449. function install_koel {
  450. if [ ! $ONION_ONLY ]; then
  451. ONION_ONLY='no'
  452. fi
  453. function_check install_nodejs
  454. install_nodejs koel
  455. install_koel_main
  456. cd /var/www/$KOEL_DOMAIN_NAME/htdocs
  457. # curl -sS https://getcomposer.org/installer | php
  458. if [ -f ~/freedombone/image_build/composer_install ]; then
  459. cat ~/freedombone/image_build/composer_install | php
  460. else
  461. if [ -f /home/$MY_USERNAME/freedombone/image_build/composer_install ]; then
  462. cat /home/$MY_USERNAME/freedombone/image_build/composer_install | php
  463. fi
  464. fi
  465. npm install
  466. php composer.phar install
  467. function_check get_mariadb_password
  468. get_mariadb_password
  469. cp .env.example .env
  470. sed -i "s/ADMIN_EMAIL=.*/ADMIN_EMAIL=$MY_EMAIL_ADDRESS/g" .env
  471. sed -i "s/ADMIN_NAME=.*/ADMIN_NAME=$MY_USERNAME/g" .env
  472. sed -i "s/ADMIN_PASSWORD=.*/ADMIN_PASSWORD=$KOEL_ADMIN_PASSWORD/g" .env
  473. sed -i 's/DB_CONNECTION=.*/DB_CONNECTION=mysql/g' .env
  474. sed -i 's/DB_HOST=.*/DB_HOST=127.0.0.1/g' .env
  475. sed -i 's/DB_DATABASE=.*/DB_DATABASE=koel/g' .env
  476. sed -i 's/DB_USERNAME=.*/DB_USERNAME=root/g' .env
  477. sed -i "s/DB_PASSWORD=.*/DB_PASSWORD=$MARIADB_PASSWORD/g" .env
  478. sed -i 's/MAIL_HOST=.*/MAIL_HOST=localhost/g' .env
  479. sed -i 's/MAIL_PORT=.*/MAIL_PORT=25/g' .env
  480. php artisan koel:init
  481. chown -R www-data:www-data /var/www/$KOEL_DOMAIN_NAME/htdocs
  482. # daemon
  483. echo '[Unit]' > /etc/systemd/system/koel.service
  484. echo 'Description=Koel (music player)' >> /etc/systemd/system/koel.service
  485. echo 'After=syslog.target' >> /etc/systemd/system/koel.service
  486. echo 'After=network.target' >> /etc/systemd/system/koel.service
  487. echo '' >> /etc/systemd/system/koel.service
  488. echo '[Service]' >> /etc/systemd/system/koel.service
  489. echo 'Type=simple' >> /etc/systemd/system/koel.service
  490. echo 'User=www-data' >> /etc/systemd/system/koel.service
  491. echo 'Group=www-data' >> /etc/systemd/system/koel.service
  492. echo "WorkingDirectory=/var/www/$KOEL_DOMAIN_NAME/htdocs" >> /etc/systemd/system/koel.service
  493. echo "ExecStart=/usr/bin/php artisan serve --port=$KOEL_PORT" >> /etc/systemd/system/koel.service
  494. echo 'Restart=on-failure' >> /etc/systemd/system/koel.service
  495. echo '' >> /etc/systemd/system/koel.service
  496. echo '[Install]' >> /etc/systemd/system/koel.service
  497. echo 'WantedBy=multi-user.target' >> /etc/systemd/system/koel.service
  498. systemctl enable koel.service
  499. systemctl daemon-reload
  500. systemctl start koel.service
  501. if [ ! -d /music ]; then
  502. mkdir /music
  503. fi
  504. chown -R www-data:www-data /music
  505. systemctl restart nginx
  506. APP_INSTALLED=1
  507. }
  508. # NOTE: deliberately there is no "exit 0"