#!/bin/sh # ===================================================================== # Projet : DARKCONTAINER # Fichier : lib/initd # 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}" #|-------------------------------------------------------------| #| which "base" tools : cp | rm | echo | head | tail | #|-------------------------------------------------------------| # &&&&& #|-----------------------------------------------------------------------| #| which "directory" tools : mkdir | chmod | chgrp | mount | umount | #|-----------------------------------------------------------------------| # &&&&& #|------------------------------------------------------------------------------------| #| which "user right" tools : chmod | chown | chgrp | groupadd | useradd | chroot | #|------------------------------------------------------------------------------------| $(shInclude $rootDarkContainer/which/lib/base) && $(shInclude $rootDarkContainer/which/lib/userRight) cmdStartStopDaemon="$(which start-stop-daemon 2>/dev/null)" #initd_create $pName initd_create() { local log="initd_create" local pName="$1" shDebug "check if service $pName is running, if on, we stop them." if [ -n "$(/etc/init.d/$pName status | head -n 3 | tail -n 1 | grep running)" ];then shDebug "service $pName is running, we stop them." /etc/init.d/$pName stop fi } # initd_install_debug "$debugFile" "$pName" "$pChrootDir" "$pUser" "$pGroup" "$cmdApacheCtl start" "$listMountFolder" initd_install_debug() { local log="initd_install_debug" local debugFile="$1" local pName="$2" local pChrootDir="$3" local pUser="$4" local pGroup="$5" local ExecStart="$7" local listMountFolder="$6" $cmdEcho -e "#!/bin/sh \n\ racineSh=\"$racineSh\" \n\ \n\ . \$racineSh/lib/shTools \n\ rootDarkContainer=\"$rootDarkContainer\" \n\ \$(shInclude \$rootDarkContainer/lib/chroot) \n\ chroot_install "$pChrootDir" $(which bash) \n\ chroot_install "$pChrootDir" $(which ls) \n\ chroot_install "$pChrootDir" $(which ldd) \n\ chroot_install "$pChrootDir" $(which gdb) \n\ /etc/init.d/$pName stop \n\ " > "$debugFile" $cmdChmod u+x "$debugFile" chroot_gen_start "$pChrootDir" "$listMountFolder" "$pUser" "$pGroup">> "$debugFile" $cmdEcho -e "$cmdEcho -e \"$ExecStart\"" >> "$debugFile" $cmdEcho -e "$cmdChroot --userspec=root:root $pChrootDir" >> "$debugFile" chroot_gen_stop "$pChrootDir" "$listMountFolder" >> "$debugFile" } #pServiceDoc="man:dhcpd(8)" #initd_install $pName $pServiceInfo $pServiceDoc $pUser $pGroup $pChrootDir $listMountFolder #initd_install $pName $pServiceInfo $pServiceDoc $pUser $pGroup $pChrootDir $listMountFolder "$cmdDhcpd -- -cf /etc/darksrv/dhcp/data/dhcpd.conf -lf /var/run/dhcp/dhcpd.leases" "$cmdTouch $pChrootDir/var/run/dhcp/dhcpd.leases" #initd_install $pName $pServiceInfo $pServiceDoc $pUser $pGroup $pChrootDir $listMountFolder "$cmdNamed -- -f -u bind" "" "$cmdRndc stop > /dev/null 2>&1 || $cmdKill -TERM \$MAINPID" "$cmdRndc reload > /dev/null 2>&1 || $cmdKill -HUP \$MAINPID" #initd_install $pName $pServiceInfo $pServiceDoc $pUser $pGroup $pChrootDir $listMountFolder "$cmdNamed -- -f -u bind -t $pChrootDir" "" "$cmdRndc stop > /dev/null 2>&1 || $cmdKill -TERM \$MAINPID" "$cmdRndc reload > /dev/null 2>&1 || $cmdKill -HUP \$MAINPID" #initd_install $pName $pServiceInfo $pServiceDoc $pUser $pGroup $pChrootDir $listMountFolder "$cmdChroot -- $pDir $cmdNamed -4 -f -u bind" "" "$cmdRndc stop > /dev/null 2>&1 || $cmdKill -TERM \$MAINPID" "$cmdRndc reload > /dev/null 2>&1 || $cmdKill -HUP \$MAINPID" initd_install () { local log="initd_install" local pName="$1" local pServiceInfo="$2" local pServiceDoc="$3" local pUser="$4" local pGroup="$5" local pChrootDir="$6" local listMountFolder="$7" local ExecStart="$8" local ExecStartPre="$9" local ExecStop="${10}" local ExecReload="${11}" touch /etc/init.d/${pName} chmod u+x /etc/init.d/${pName} initd_unit_gen "$pName" "$pServiceInfo" "$pServiceDoc" > /etc/init.d/${pName} initd_service_gen "$pName" "$pUser" "$pGroup" "$pChrootDir" "$listMountFolder" \ "$ExecStart" "$ExecStartPre" "$ExecStop" "$ExecReload" >> /etc/init.d/${pName} /etc/init.d/${pName} start /etc/init.d/${pName} status } #initd_unit_gen $pName $pServiceInfo $pServiceDoc initd_unit_gen() { local pName="$1" local pServiceInfo="$2" local pServiceDoc="$3" $cmdEcho -e "#!/bin/sh\n\ ### BEGIN INIT INFO\n\ # Provides: ${pName}\n\ # Required-Start: $local_fs\n\ # Required-Stop: $local_fs\n\ # Default-Start: 2 3 4 5\n\ # Default-Stop: 0 1 6\n\ # Short-Description: Start chroot ${pName} daemon\n\ # Description: Provide a service '${pName}' in chroot env\n\ ### END INIT INFO\n\ \n\ set -e\n\ \n\ " } #initd_service_gen $pName $pUser $pGroup $pChrootDir $listMountFolder $ExecStart $ExecStartPre $ExecStop $ExecReload initd_service_gen() { local log="initd_install" local pName="$1" local pUser="$2" local pGroup="$3" local pChrootDir="$4" local listMountFolder="$5" local ExecStart="$6" local ExecStartPre="$7" local ExecStop="$8" local ExecReload="$9" local pidfile="/var/run/named/named.pid" local pidFile="#PIDFile=$pChrootDir/var/run/$pName/$pName.pid" local Type="Type=forking" if [ "$pName" = "bind9" ];then local pidFile="PIDFile=$pChrootDir/var/run/named/named.pid" local Type="" fi if [ -z "$ExecStop" ];then if [ -z "$(echo $ExecStart | grep $pChrootDir)" ];then local ExecStop="ExecStop=$cmdStartStopDaemon --stop --pid \$MAINPID" else local ExecStop="" fi else local ExecStop="ExecStop=$ExecStop" fi if [ -n "$ExecStartPre" ];then local ExecStartPre="ExecStartPre=$ExecStartPre" fi if [ -n "ExecStart" ];then if [ -z "$(echo $ExecStart | grep $pChrootDir)" ];then local ExecStart="$cmdStartStopDaemon --chroot $pChrootDir --start --exec $ExecStart" fi fi if [ -n "$ExecReload" ];then local ExecReload="ExecReload=$ExecReload" fi local systemdExecStartPre="$(chroot_gen_start "$pChrootDir" "$pUser" "$pGroup" "$listMountFolder")" local systemdExecStopPost="$(chroot_gen_stop "$pChrootDir" "$listMountFolder")" $cmdEcho -e " \n\ case \"\$1\" in \n\ start) \n\ $systemdExecStartPre \n\ $ExecStartPre \n\ $ExecStart \n\ ;; \n\ reload) \n\ $ExecReload \n\ ;; \n\ stop) \n\ $ExecStop \n\ $systemdExecStopPost \n\ ;; \n\ #$pidFile \n\ esac \n\ " }