wpad: convert init.d script to ucode
authorJohn Crispin <john@phrozen.org>
Tue, 15 Oct 2024 04:57:46 +0000 (06:57 +0200)
committerJohn Crispin <john@phrozen.org>
Wed, 23 Oct 2024 12:14:38 +0000 (14:14 +0200)
Signed-off-by: John Crispin <john@phrozen.org>
package/network/services/hostapd/files/wpad.init

index 65d46df982a50cc9bd8714252bdda25da10553f4..918e743c0e4a2d1a51d4452e5d5cbb7a2a92b133 100644 (file)
@@ -1,43 +1,48 @@
-#!/bin/sh /etc/rc.common
+#!/usr/bin/ucode /usr/share/ucode/procd.uc
 
-START=19
-STOP=21
+function instances() {
+       let instances = [];
 
-USE_PROCD=1
-NAME=wpad
+       if (fs.stat('/usr/sbin/hostapd')) {
+               const hostapd = {
+                       name: 'hostapd',
+                       command: '/usr/sbin/hostapd -s -g /var/run/hostapd/global',
+                       respawn: procd_default_respawn(),
+                       jail: true,
+                       capabilities: '/etc/capabilities/wpad.json',
+                       limits: procd_core_dump(),
+                       user: 'network',
+                       group: 'network',
+               };
 
-start_service() {
-       if [ -x "/usr/sbin/hostapd" ]; then
-               mkdir -p /var/run/hostapd
-               chown network:network /var/run/hostapd
-               procd_open_instance hostapd
-               procd_set_param command /usr/sbin/hostapd -s -g /var/run/hostapd/global
-               procd_set_param respawn 3600 1 0
-               procd_set_param limits core="unlimited"
-               [ -x /sbin/ujail -a -e /etc/capabilities/wpad.json ] && {
-                       procd_add_jail hostapd
-                       procd_set_param capabilities /etc/capabilities/wpad.json
-                       procd_set_param user network
-                       procd_set_param group network
-                       procd_set_param no_new_privs 1
-               }
-               procd_close_instance
-       fi
+               fs.mkdir('/var/run/hostapd');
+               fs.chown('/var/run/hostapd', 'network', 'network');
 
-       if [ -x "/usr/sbin/wpa_supplicant" ]; then
-               mkdir -p /var/run/wpa_supplicant
-               chown network:network /var/run/wpa_supplicant
-               procd_open_instance supplicant
-               procd_set_param command /usr/sbin/wpa_supplicant -n -s -g /var/run/wpa_supplicant/global
-               procd_set_param respawn 3600 1 0
-               procd_set_param limits core="unlimited"
-               [ -x /sbin/ujail -a -e /etc/capabilities/wpad.json ] && {
-                       procd_add_jail wpa_supplicant
-                       procd_set_param capabilities /etc/capabilities/wpad.json
-                       procd_set_param user network
-                       procd_set_param group network
-                       procd_set_param no_new_privs 1
-               }
-               procd_close_instance
-       fi
+               push(instances, hostapd);
+       }
+
+       if (fs.stat('/usr/sbin/wpa_supplicant')) {
+               const supplicant = {
+                       name: 'wpa_supplicant',
+                       command: '/usr/sbin/wpa_supplicant -n -s -g /var/run/wpa_supplicant/global',
+                       respawn: procd_default_respawn(),
+                       jail: true,
+                       capabilities: '/etc/capabilities/wpad.json',
+                       limits: procd_core_dump(),
+                       user: 'network',
+                       group: 'network',
+               };
+               fs.mkdir('/var/run/wpa_supplicant');
+               fs.chown('/var/run/wpa_supplicant', 'network', 'network');
+               
+               push(instances, supplicant);
+       }
+
+       return instances;
 }
+
+procd_service('wpad', {
+       start: 19,
+       stop: 21,
+       instances,
+});