Added CT's NodeJS, NodeRed, z2mqtt & nextcloud

This commit is contained in:
2021-09-28 02:06:22 +00:00
parent 57c54aaa07
commit cc6f043f9e
14 changed files with 486 additions and 20 deletions

View File

@@ -0,0 +1,114 @@
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
server_tokens off;
client_body_buffer_size 10K;
client_header_buffer_size 1k;
client_max_body_size 8m;
large_client_header_buffers 4 4k;
server_names_hash_bucket_size 64;
root /usr/share/nginx/html;
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log off;
error_log /var/log/nginx/error.log;
#Server config for Nextcloud
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /opt/nextcloud;
# Set max upload size
client_max_body_size 1G;
#SetupBlockStart
add_header Content-Type text/html;
return 200 '<html><head></head><body>To setup this container edit and run the FirstRun script `/opt/Setup/Scripts/FirstRun.sh`</body></html>';
#SetupBlockEnd
add_header Referrer-Policy "no-referrer" always;
add_header X-Download-Options "noopen" always;
add_header X-Permitted-Cross-Domain-Policies "none" always;
add_header X-Robots-Tag "none" always;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_hide_header X-Powered-By;
fastcgi_buffers 64 4K;
gzip on;
gzip_vary on;
gzip_comp_level 4;
gzip_min_length 256;
gzip_proxied expired no-cache no-store private no_last_modified no_etag auth;
gzip_types application/atom+xml application/javascript application/json application/ld+json application/manifest+json application/rss+xml application/vnd.geo+json application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/bmp image/svg+xml image/x-icon text/cache-manifest text/css text/plain text/vcard text/vnd.rim.location.xloc text/vtt text/x-component text/x-cross-domain-policy;
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ^~ /.well-known {
location = /.well-known/carddav { return 301 /remote.php/dav/; }
location = /.well-known/caldav { return 301 /remote.php/dav/; }
location ^~ /.well-known { return 301 /index.php$uri; }
try_files $uri $uri/ =404;
}
location / {
rewrite ^ /index.php;
}
location ~ ^\/(?:build|tests|config|lib|3rdparty|templates|data)\/ {
deny all;
}
location ~ ^\/(?:\.|autotest|occ|issue|indie|db_|console) {
deny all;
}
location ~ ^\/(?:index|remote|public|cron|core\/ajax\/update|status|ocs\/v[12]|updater\/.+|oc[ms]-provider\/.+)\.php(?:$|\/) {
fastcgi_split_path_info ^(.+?\.php)(\/.*|)$;
set $path_info $fastcgi_path_info;
try_files $fastcgi_script_name =404;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $path_info;
fastcgi_param HTTPS on;
fastcgi_param modHeadersAvailable true;
fastcgi_param front_controller_active true;
fastcgi_pass unix:/run/php-fpm8/php-fpm.sock;
fastcgi_intercept_errors on;
fastcgi_request_buffering off;
}
location ~ ^\/(?:updater|oc[ms]-provider)(?:$|\/) {
try_files $uri/ =404;
index index.php;
}
location ~ \.(?:css|js|woff2?|svg|gif|map)$ {
try_files $uri /index.php$request_uri;
add_header Cache-Control "public, max-age=15778463";
add_header Referrer-Policy "no-referrer" always;
add_header X-Download-Options "noopen" always;
add_header X-Permitted-Cross-Domain-Policies "none" always;
add_header X-Robots-Tag "none" always;
access_log off;
}
location ~ \.(?:png|html|ttf|ico|jpg|jpeg|bcmap)$ {
try_files $uri /index.php$request_uri;
access_log off;
}
}
}

View File

@@ -0,0 +1,45 @@
[nextcloud]
user = nginx
group = nginx
listen = /run/php-fpm8/php-fpm.sock
listen.owner = nginx
listen.group = nginx
php_admin_value[disable_functions] = exec,passthru,system
php_admin_value[error_log] = /var/log/php-fpm.error.log
; OPCACHE SETTINGS
php_admin_value[opcache.memory_consumption] = 256
php_admin_value[opcache.enable] = 1
php_admin_value[opcache.interned_strings_buffer] = 32
php_admin_value[opcache.max_accelerated_files] = 50000
php_admin_value[opcache.max_wasted_percentage] = 5
php_admin_value[opcache.revalidate_freq] = 0
php_admin_value[opcache.validate_timestamps] = 1
; PERFORMANCE LIMITS
php_admin_value[max_input_vars] = 1000
php_admin_value[upload_max_filesize] = 1G
php_admin_value[post_max_size] = 1G
php_admin_value[max_input_time] = 60
php_admin_value[memory_limit] = 512M
; SECURITY
php_admin_value[cgi.fix_pathinfo] = 0
php_admin_value[allow_url_fopen] = Off
php_admin_value[file_uploads] = on
php_admin_value[open_basedir] = /opt/nextcloud/:/var/nextcloud:/run/php-fpm8/php-fpm.sock:/run/redis/redis.sock:/proc/meminfo:/proc/cpuinfo:/dev/urandom:/tmp
php_admin_value[session.use_strict_mode] = 1
php_admin_value[session.cookie_httponly] = 1
;HTTPSONLY php_admin_value[session.cookie_samesite] = Strict
;HTTPSONLY php_admin_value[session.cookie_secure] = 1
pm = dynamic
pm.max_children = 30
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 5
chdir = /
env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp

View File

@@ -0,0 +1,41 @@
#!/bin/ash
#UserSettings
ThisScriptConfigured=no
## Nextcloud Admin user
NextcloudUsername=<Username>
NexcloudPassword=<Password>
##Nextcloud
NextcloudWebProto=http
##DB
MysqlIP=127.0.0.1
MysqlPort=3306
MysqlUsername=nextcloud
MysqlDatabase=nextcloud
MysqlPassword=<Password>
#Check if script is configured
if [ $ThisScriptConfigured = no ]; then
echo "Script is not configured"
exit
fi
sudo -u nginx php8 /opt/nextcloud/occ maintenance:install --database mysql --database-name "$MysqlDatabase" --database-host "$MysqlIP" --database-port "$MysqlPort" --database-user "$MysqlUsername" --database-pass "$MysqlPassword" --database-table-space "" --admin-user "$NextcloudUsername" --admin-pass "$NexcloudPassword" --data-dir /var/nextcloud
sed -n -i '/#SetupBlockStart/{:a;N;/#SetupBlockEnd/!ba;N;s/.*//};p' /etc/nginx/nginx.conf
service nginx reload
sudo -u nginx php8 /opt/nextcloud/occ db:convert-filecache-bigint
sudo -u nginx php8 /opt/nextcloud/occ db:add-missing-indices
sudo -u nginx php8 /opt/nextcloud/occ app:disable firstrunwizard
sudo -u nginx php8 /opt/nextcloud/occ config:system:set default_language --value=nl
sudo -u nginx php8 /opt/nextcloud/occ config:system:set default_locale --value=nl
sudo -u nginx php8 /opt/nextcloud/occ config:system:set default_phone_region --value=nl
sudo -u nginx php8 /opt/nextcloud/occ config:system:set skeletondirectory --value=
sudo -u nginx php8 /opt/nextcloud/occ config:system:set memcache.local --value='\OC\Memcache\APCu'
sudo -u nginx php8 /opt/nextcloud/occ config:system:set trashbin_retention_obligation --value=30,30
sudo -u nginx php8 /opt/nextcloud/occ config:system:set memcache.distributed --value='\OC\Memcache\Redis'
sudo -u nginx php8 /opt/nextcloud/occ config:system:set memcache.locking --value='\OC\Memcache\Redis'
sudo -u nginx php8 /opt/nextcloud/occ config:system:set redis host --value=localhost
sudo -u nginx php8 /opt/nextcloud/occ config:system:set redis port --value=6379
sudo -u nginx php8 /opt/nextcloud/occ config:system:set trusted_domains 1 --value="$(ifconfig | grep -A 1 'eth0' | tail -1 | cut -d ':' -f 2 | cut -d ' ' -f 1)"
sudo -u nginx php8 /opt/nextcloud/occ config:system:set overwrite.cli.url --value="$NextcloudWebProto://$(ifconfig | grep -A 1 'eth0' | tail -1 | cut -d ':' -f 2 | cut -d ' ' -f 1)"
sudo -u nginx php8 /opt/nextcloud/occ config:system:set overwriteprotocol --value="$NextcloudWebProto"

View File

@@ -0,0 +1,28 @@
#!/bin/ash
#Setup Nginx repo
echo "@nginx http://nginx.org/packages/mainline/alpine/v$(egrep -o '^[0-9]+\.[0-9]+' /etc/alpine-release)/main" >> /etc/apk/repositories
mv /opt/Setup/nginx_signing.rsa.pub /etc/apk/keys/nginx_signing.rsa.pub
#Install Nginx
apk add nginx@nginx
#Configure Nginx
rm -rf /etc/nginx/conf.d
mv /opt/Setup/Configs/nginx.conf /etc/nginx/nginx.conf
#Configure Php-Fpm
rm -rf /etc/php8/php-fpm.d/*
mv /opt/Setup/Configs/php.conf /etc/php8/php-fpm.d/nextcloud.conf
#Install Nextcloud
mkdir /opt/nextcloud /var/nextcloud
tar jxf /opt/Setup/nextcloud.tar.bz2 -C /opt/nextcloud --strip 1
rm -rf /opt/Setup/nextcloud.tar.bz2
chown -R nginx:nginx /opt/nextcloud
chown -R nginx:nginx /var/nextcloud
echo "*/5 * * * * php8 -f /opt/nextcloud/cron.php > /dev/null 2>&1" >> /etc/crontabs/nginx
echo "apc.enable_cli=1" >> /etc/php8/php.ini
#Enable services on boot
rc-update add nginx
rc-update add php-fpm8
rc-update add redis

View File

@@ -0,0 +1,24 @@
#!/bin/ash
#Run folowing commands as 'node' user
sudo -u node ash << EOF
#Install nodered
mkdir -p /opt/node/node-red/app
npm install --prefix /opt/node/node-red/app node-red @node-red-contrib-themes/midnight-red
##Add to startup
#Save PM2 statup config
pm2 start --name nodered --cwd /opt/node/node-red/app ./node_modules/node-red/red.js -- -u /opt/node/node-red/data
pm2 save
pm2 kill
#Enable node-red dark theme
sed -i -e 's#//theme: "",#theme: "midnight-red",#g' /opt/node/node-red/data/settings.js
#Disable Node-red flow encription
sed -i -e 's#//credentialSecret: "a-secret-key",#credentialSecret: false,#g' /opt/node/node-red/data/settings.js
EOF
#Adding update scipt
mv /opt/Setup/Configs/Scripts/Update-NodeRed.sh /opt/Update-NodeRed.sh
#Cleanup
rm -rf /home/node/.npm/_cacache

View File

@@ -0,0 +1,9 @@
#!/bin/ash
#Run folowing commands as 'node' user
sudo -u node ash << EOF
pm2 stop nodered
npm install --prefix /opt/node/node-red/app node-red @node-red-contrib-themes/midnight-red
npm update --prefix /opt/node/node-red/app
pm2 start nodered
EOF

View File

@@ -0,0 +1,32 @@
#!/bin/ash
#Install Yarn Globaly for zwavejs2mqtt
npm install -g yarn
#Run folowing commands as 'node' user
sudo -u node ash << EOF
#Install zigbee2mqtt
git clone https://github.com/Koenkk/zigbee2mqtt.git /opt/node/zigbee2mqtt
npm --prefix /opt/node/zigbee2mqtt ci
##Update config
sed -i -e '/port:/c\ port: \/dev\/ttyACM-Zigbee' /opt/node/zigbee2mqtt/data/configuration.yaml
printf "frontend:\n port: 5002" >> /opt/node/zigbee2mqtt/data/configuration.yaml
#Install zwavejs2mqtt
git clone https://github.com/zwave-js/zwavejs2mqtt /opt/node/zwavejs2mqtt
yarn --cwd /opt/node/zwavejs2mqtt install
yarn --cwd /opt/node/zwavejs2mqtt run build
#Save PM2 statup config
pm2 start npm --name zigbee2mqtt --cwd /opt/node/zigbee2mqtt -- start
pm2 start yarn --name zwavejs2mqtt --cwd /opt/node/zwavejs2mqtt -- start
pm2 save
pm2 kill
EOF
#Adding update scipts
mv /opt/Setup/Scripts/Update-Zigbee2Mqtt.sh /opt/Update-Zigbee2Mqtt.sh
mv /opt/Setup/Scripts/Update-Zwave2mqtt.sh /opt/Update-Zwave2Mqtt.sh
#Cleanup
rm -rf /home/node/.npm/_cacache
rm -rf /home/node/.cache

View File

@@ -0,0 +1,10 @@
#!/bin/ash
#Run folowing commands as 'node' user
sudo -u node ash << EOF
pm2 stop zigbee2mqtt
cd /opt/node/zigbee2mqtt
ash update.sh
pm2 start zigbee2mqtt
EOF

View File

@@ -0,0 +1,11 @@
#!/bin/ash
#Run folowing commands as 'node' user
sudo -u node ash << EOF
pm2 stop zwavejs2mqtt
cd /opt/node/zwavejs2mqtt
git pull
yarn install
yarn run build
pm2 start zwavejs2mqtt
EOF