#!/bin/sh # ===================================================================== # Projet : DARKCONTAINER # Fichier : lib/service-initv # Auteur : Nicolas "DarkHack" Chapuis (c) 2026 # ================== DARKHACK ================== # [ darkweb.fr - system online ] # Powered by Perplexity, your AI assistant # https://www.perplexity.ai # ============================================== # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # ===================================================================== if ! type "shInclude" > /dev/null 2>&1; then racineSh="${racineSh:-/etc/darksh}"; . "$racineSh/lib/shTools"; shDebugEnable="1";fi rootDarkContainer="${rootDarkContainer:-/etc/darkcontainer}" [ ! -d "$rootDarkContainer" ] && shDebug 0 "exit cause rootDarkContainer is not dir:$rootDarkContainer" >&2 && exit 0 #|-------------------------------------------------------------| #| which "base" tools : cp | rm | echo | head | tail | #|-------------------------------------------------------------| # &&&&& #|------------------------------------------------------------------------------------| #| which "user right" tools : chmod | chown | chgrp | groupadd | useradd | chroot | #|------------------------------------------------------------------------------------| $(shInclude $rootDarkContainer/which/lib/base) && $(shInclude $rootDarkContainer/which/lib/userRight) cmdKill="$(which kill)" cmdSh="${cmdSh:-$(which sh)}" cmdUpdateRcd="${cmdUpdateRcd:-$(which update-rc.d 2>/dev/null)}" # pName="$pName" services_initv_create services_initv_create() { local log="services_initv_create:" shErrorOnMissing "pName" shDebug 1 ""$log" $pName" if [ -x /etc/init.d/$pName ];then /etc/init.d/$pName stop fi } #pName="$pName" pServiceInfo="$pServiceInfo" pServiceDoc="$pServiceDoc"\ #pStart="$pStart" pStartPre="$pStartPre" pStop="$pStop" pReload="$pReload"\ #pUser="$pUser" pGroup="$pGroup" pChrootDir="$pChrootDir" pMountFolders="$pMountFolders"\ #pDirUserGroupRight="$pDirUserGroupRight"\ #pIdFile="$pIdFile"\ #pInitVRequiredStart="$pInitVRequiredStart" pInitVRequiredStop="$pInitVRequiredStop"\ #pInitVShouldStart="$pInitVShouldStart" pInitVShouldStop="$pInitVShouldStop"\ #pInitVDefaultStart="$pInitVDefaultStart" pInitVDefaultStop="$pInitVDefaultStop"\ #services_initv_install services_initv_install() { local log="services_initv_install" shErrorOnMissing "pName pServiceInfo pServiceDoc" shErrorOnMissing "pStart pStop" shWarnOnMissing "pUser pGroup pChrootDir pMountFolders pDirUserGroupRight" shWarnOnMissing "pIdFile pStartPre pReload" if [ -z "$pIdFile" ];then local pIdFile="$pChrootDir/var/run/$pName/$pName.pid";fi shWarnOnMissing "pInitVRequiredStart pInitVRequiredStop" if [ -z "$pInitVRequiredStart" ];then local pInitVRequiredStart="\$remote_fs";fi if [ -z "$pInitVRequiredStop" ];then local pInitVRequiredStop="\$remote_fs";fi shWarnOnMissing "pInitVShouldStart pInitVShouldStop" if [ -z "$pInitVShouldStart" ];then local pInitVShouldStart="\$network \$syslog";fi if [ -z "$pInitVShouldStop" ];then local pInitVShouldStop="\$network \$syslog";fi shWarnOnMissing "pInitVDefaultStart pInitVDefaultStop" if [ -z "$pInitVDefaultStart" ];then local pInitVDefaultStart="2 3 4 5";fi if [ -z "$pInitVDefaultStop" ];then local pInitVDefaultStop="0 1 6";fi local serviceFile="/etc/init.d/${pName}" shDebug 1 ""$log" service file:$serviceFile" # pName="$pName" pServiceInfo="$pServiceInfo" pServiceDoc="$pServiceDoc"\ pInitVRequiredStart="$pInitVRequiredStart" pInitVRequiredStop="$pInitVRequiredStop"\ pInitVShouldStart="$pInitVShouldStart" pInitVShouldStop="$pInitVShouldStop"\ pInitVDefaultStart="$pInitVDefaultStart" pInitVDefaultStop="$pInitVDefaultStop" services_initv_unit_gen > "$serviceFile" # pName="$pName"\ # pStart="$pStart" pStartPre="$pStartPre" pStop="$pStop" pReload="$pReload"\ # pIdFile="$pIdFile" # pName="$pName"\ # pStart="$pStart" pStartPre="$pStartPre" pStop="$pStop" pReload="$pReload"\ # pIdFile="$pIdFile"\ # pUser="$pUser" pGroup="$pGroup" pChrootDir="$pChrootDir" pMountFolders="$pMountFolders"\ # pDirUserGroupRight="$pDirUserGroupRight"\ services_initv_gen >> "$serviceFile" $cmdChmod u+x $serviceFile if [ -x "$cmdUpdateRcd" ];then $cmdUpdateRcd ${pName} defaults;fi } # pName="$pName" pServiceInfo="$pServiceInfo" pServiceDoc="$pServiceDoc"\ # pInitVRequiredStart="$pInitVRequiredStart" pInitVRequiredStop="$pInitVRequiredStop" # pInitVShouldStart="$pInitVShouldStart" pInitVShouldStop="$pInitVShouldStop" # pInitVDefaultStart="$pInitVDefaultStart" pInitVDefaultStop="$pInitVDefaultStop" #services_initv_unit_gen services_initv_unit_gen() { shErrorOnMissing "pName pServiceInfo pServiceDoc" shErrorOnMissing "pInitVRequiredStart pInitVRequiredStop" shErrorOnMissing "pInitVShouldStart pInitVShouldStop" shErrorOnMissing "pInitVDefaultStart pInitVDefaultStop" $cmdEcho -e "#!/bin/sh -e\n\ \n\ ### BEGIN INIT INFO\n\ # Provides: $pName\n\ # Required-Start: $pInitVRequiredStart\n\ # Required-Stop: $pInitVRequiredStop\n\ # Should-Start: $pInitVShouldStart\n\ # Should-Stop: $pInitVShouldStop\n\ # Default-Start: $pInitVDefaultStart\n\ # Default-Stop: $pInitVDefaultStop\n\ # Short-Description: Start and stop $pName\n\ # Description: $pServiceInfo\n\ ### END INIT INFO\n\ \n\ if [ -f /lib/lsb/init-functions ];then . /lib/lsb/init-functions;fi\n\ " } # pName="$pName" pIdFile="$pIdFile"\ # pStart="$pStart" pStartPre="$pStartPre" pStop="$pStop" pReload="$pReload"\ # pUser="$pUser" pGroup="$pGroup" pChrootDir="$pChrootDir" pMountFolders="$pMountFolders"\ # pDirUserGroupRight="$pDirUserGroupRight"\ # services_initv_gen services_initv_gen() { local log="services_initv_gen" shErrorOnMissing "pName pIdFile pUser pGroup" shWarnOnMissing "pStart pStop pDirUserGroupRight pStartPre pReload pChrootDir pMountFolders" local pIdFile="$(echo $pIdFile | tr '%' '\$')" local pStart="$(echo $pStart | tr '%' '\$')" if [ -n "$pChrootDir" ];then chroot_gen_conf "$pChrootDir" "$pName" "$pUser" "$pGroup" "$pMountFolders" "$pDirUserGroupRight" if [ -z "$pStop" ] || [ -z "$(echo $pStop | grep $pChrootDir)" ];then if [ -n "$cmdStartStopDaemon" ];then local pStop="$cmdStartStopDaemon --pidfile \${pChrootDir}/\${pIdFile} --stop || $cmdEcho \"echec stop service\"" else local pStop="$cmdKill -9 \"\$($cmdCat \${pChrootDir}/\${pIdFile})\" || $cmdEcho \"echec stop service\"" fi fi if [ -n "$pStart" ] && [ -z "$(echo $pStart | grep $pChrootDir)" ];then if [ -n "$cmdStartStopDaemon" ];then local pStart="$cmdStartStopDaemon --chroot $pChrootDir --pidfile \${pChrootDir}/\${pIdFile} --start --exec $pStart" else local pStart="$cmdEcho --chroot $pChrootDir --pidfile \${pChrootDir}/\${pIdFile} --start --exec $pStart" fi fi fi $cmdEcho -e " \n\ i=\"\$2\" \n\ pChrootDir=\"$pChrootDir\" \n\ pIdFile=\"$pIdFile\" \n\ pIdFolder=\"\$($cmdEcho \$pIdFile | $cmdRev | $cmdCut -d/ -f2- | $cmdRev)\" \n\ dataFile=\"$rootDarkContainer/data/$(echo $pChrootDir | base64 -i)\" \n\ if [ ! -d \"\$pIdFolder\" ];then mkdir -p \"\$pIdFolder\";fi \n\ case \"\$1\" in \n\ start) \n\ if type "log_daemon_msg" > /dev/null 2>&1; then \n\ log_daemon_msg \"Starting service...\" \"$pName\" \n\ fi \n\ \n\ " if [ -n "$pChrootDir" ];then $cmdEcho -e " \n\ sh \"$rootDarkContainer/bin/container\" start \"\$dataFile\" \n\ ";fi $cmdEcho -e " \n\ $pStartPre \n\ $pStart \n\ " if [ -n "$pChrootDir" ];then $cmdEcho -e " \n\ sh \"$rootDarkContainer/bin/container\" register-pid \"\$dataFile\" \"\$pIdFile\" \n\ ";fi $cmdEcho -e " \n\ if type "log_end_msg" > /dev/null 2>&1; then \n\ log_end_msg 0 \n\ fi \n\ ;; \n\ stop) \n\ if type "log_daemon_msg" > /dev/null 2>&1; then \n\ log_daemon_msg \"Stopping service...\" \"$pName\" \n\ fi \n\ $pStop \n\ " if [ -n "$pChrootDir" ];then $cmdEcho -e " \n\ sh \"$rootDarkContainer/bin/container\" stop \"\$dataFile\" \"\$pIdFile\" \n\ ";fi $cmdEcho -e " \n\ if type "log_end_msg" > /dev/null 2>&1; then \n\ log_end_msg 0 \n\ fi \n\ ;; \n\ reload|force-reload) \n\ if type "log_daemon_msg" > /dev/null 2>&1; then \n\ log_daemon_msg \"Reloading service...\" \"$pName\" \n\ fi \n\ $pReload >/dev/null && log_end_msg 0 || log_end_msg 1 \n\ ;; \n\ restart) \n\ \$0 stop \$2 || if ! type "log_daemon_msg" > /dev/null 2>&1; then log_daemon_msg \"Stopping service echec\" \"$pName\";fi \n\ \$0 start \$2 \n\ ;; \n\ execute) \n\ sh \"$rootDarkContainer/bin/container\" execute \"\$dataFile\" \"\$2\" \n\ ;; \n\ status) \n\ ret=0 \n\ if type "status_of_proc" > /dev/null 2>&1; then status_of_proc -p \${pChrootDir}/\${pIdFile} $pName 2>/dev/null || ret=\$?;fi \n\ exit \$ret \n\ ;; \n\ *) \n\ if type "log_action_msg" > /dev/null 2>&1; then \n\ log_action_msg \"Usage: \$0 {start|stop|reload|restart|force-reload|status}\" \n\ else \n\ echo \"Usage: \$0 {start|stop|reload|restart|force-reload|status}\" \n\ fi \n\ exit 1 \n\ ;; \n\ esac \n\ exit 0 \n\ " }