Init Service for Slackware

Publicado por César (última atualização em 24/07/2019)

[ Hits: 2.067 ]

Download 6994.

Download 1562246399.service (versão 2)




O script service foi elaborado para simplificar a inicialização de serviços no Sysvinit, onde o mesmo pode ser portado para outros SO's da família *nix. Script elaborado em Shell Script puro para garantir maior portabilidade.

Espero que seja útil façam bom proveito.

  



Versões atualizadas deste script

Versão 2 - Enviado por César em 04/07/2019

Changelog: nova versão do script Init Service for Slackware

Download 1562246399.service


Esconder código-fonte

#!/bin/sh
######################################################################################################
#                                                                                                                                                                                                        #
# Autor: Jean Zonta                                                                                                                                                                        #
# Pseudonym: wiki.anon                                                                                                                                                                #
# Script Name: it's self                                                                                                                                                                   #
# License: GNU/GPL V3                                                                                                                                                                  # 
# DateTime: Sáb 18 Mai 2019 21:35:06                                                                                                                                          #
# Os destination: Slackware and family                                                                                                                                       #
# echo "ykmk0cpqpB{cjqq0eqo0dt" | perl -pe \ 's/(.)/chr(ord($1)-2*1)/ge'                                                                               #
# echo 'comhttps://slackwarewww' | sed 's@\(com\)\(https://\)\(slackware\)\(www\)@\2\4.\3.\1 ..!!!@'                                   #
#                                                                                                                                                                                                        #
######################################################################################################
###############BEGIN TO INSTALL###############
#
# Copie para para o diretório /bin
# bash$ sudo cp service /bin/service
#
# Copie para para o diretório /sbin
# bash$ sudo cp service /sbin/service
#
# Dê permissão de execução
# bash$ sudo chmod -v 755 /{sbin,bin}/service
#
# Execution tests:
#
# bash$ sudo service + <enter>
# Usage: service <progname> or <rc.progname>
#
# bash$ sudo service a + <enter> 
# "a" do not valid service!
#
# bash$ sudo service 1 + <enter>
# "1" do not valid service!
#
# bash$ sudo service asdf + <enter>
# "asdf" do not valid service!
#
# bash$ sudo service <progname> or <rc.progname> + <enter>
# service <progname> "{start|stop|status|restart}"
#
# bash$ sudo service <progname> or <rc.progname> + a + <enter>
# service <progname> "{start|stop|status|restart}"
#
# bash$ sudo service <progname> or <rc.progname> + 1 + <enter>
# service <progname> "{start|stop|status|restart}"
#
# bash$ sudo service <progname> or <rc.progname> + asdf + <enter>
# service <progname> "{start|stop|status|restart}"
#
# bash$ sudo service rc.keymap
# Not exists options to "keymap"
#
# bash$ sudo service rc.fuse
# Not exists options to "fuse"
#
# bash$ sudo service rc.local
# Not exists options to "local"
#
# bash$ sudo service font
# Not exists options to "font"
#
# bash$ sudo service loop
# Not exists options to "loop"
#
# bash$ sudo service rc.modules
# Not exists options to "modules"
#
# bash$ sudo service rc.modules.local
# Not exists options to "modules.local"
#
################END TO INSTALL################

FILES=($(ls -1 /etc/rc.d/rc.*))

##################BEGIN BLOCO 1##################
if [ -z "${1}" ]; then
 echo -e "\nUsage: ${0##*/} <progname> or <rc.progname>\n"
  exit
   else
    SRVCNAME=${1#*.*} # Caso o usuário digite <rc.progname> retira rc. e SRVCNAME=<progname>
    NAME=${SRVCNAME/.conf/} #Retira extensão .conf no fim do programa caso exista
    
      # Busca o programa no vetor caso exista
       if grep -wq "${NAME}" <<< ${FILES[@]}; then
        
        FILE="/etc/rc.d/rc.${NAME}"
         
         PERMITION="$(ls -l ${FILE})"
         
          if [[ "${FILE##*rc.}" = "keymap" || "${FILE##*rc.}" = "fuse" || \
                "${FILE##*rc.}" = "local" || "${FILE##*rc.}" = "font" || \
                "${FILE##*rc.}" = "loop" || "${FILE##*rc.}" = "modules" || \
                "${FILE##*rc.}" = "modules.local" ]]; then
                
                echo -e "\nNot exists options to \"${FILE##*rc.}\"\n"
                 exit
                 
                  else
                  
                   #Se a permissão de execução for 644 e não igual a 700 ou 755
                    if [[ "${PERMITION/\ */}" != "-rwx------" || "${PERMITION/\ */}" != "-rwxr-xr-x" ]]; then
                     AUTORIZE=1
                      fi
          fi
       else
        echo -e "\n\"${NAME}\" do not valid service!\n"
         exit
          fi # Fim da busca de ${NAME} no vetor
fi # Fim se variável ${1} vazia
##################END BLOCO 1####################
#################################################
##################BEGIN BLOCO 2##################
if [ "${FILE##*rc.}" = "${NAME}" ]; then

#Aqui mesmo se o usuário digitar algum numero na variável $2
#ele executará para mostrar as opções padrão serviço.

if [[ $(echo ${2} | egrep "[^a-z0-9]$") -eq 0 ]]; then

OPT=${2#*.*} # Caso o usuário digite alguma string com ponto

# Estes pequenos if's abaixo verificam a sub opção do usuário ex:
#
# Bash Input:
# bash# <service> <progname> s
#
# Se <progname> for um serviço válido então mostrará todas opções:
#
# A Saida será:
# bash$ service <progname> "{start|stop|restart}"
#
# e não algo como:
# usage: /caminho/do/programa/<progname> "{start|stop|restart}"
#
if [[ -z "${OPT}" ]]; then
 OPT="${NAME}" #Se variável OPT estiver vazia então OPT=<scriptname>
 else
 if [[ ! -z "${OPT}" ]]; then 
  TAM=${#OPT} #Se variável OPT não estiver vazia mede o tamanho.
  
  if [[ ${TAM} -eq 1 ]]; then #Se o tamanho for igual a 1 contém pelo menos uma string.
   OPT="${NAME}" #Pega nome do script como uma opção para que mostre as opções padrão.
    fi
 fi
fi

# Pega as opções do serviço e retira aspas, tudo o que esta entre chave, espaço em branco no inicio e fim da linha
OPTIONS="$(egrep 'Usage|usage' ${FILE} | cut -f2 -d'0' | sed 's/"//g;s/{//g;s/}//g;s/^\s*//g;s/\s*$//g;')"

if [ -z "$(echo ${OPTIONS} | grep ${OPT})" ]; then

 #Usage: service <progname> "{start|stop|restart}"
  echo -e "\nUsage: ${0##*/} ${NAME} \"{${OPTIONS}}\"\n"
       
   else
   
    if [[ ${AUTORIZE} -eq 1 ]]; then
     chmod 755 ${FILE}
      ${FILE} ${OPT}
                   
      if [ $? -ne 0 ]; then
       #Falha ao fazer start, stop, restart etc ... in <progname>
        echo "Failed to \"${OPT}\" the ${FILE##*rc.}"
         exit
          fi #Fim Failed to start
          
      else
       ${FILE} ${OPT}
         
        if [ $? -ne 0 ]; then
         #Falha ao fazer start, stop, restart etc ... in <progname>
          echo "Failed to \"${OPT}\" the ${FILE##*rc.}"
           exit
            fi #Fim Failed to start
             
    fi #Fim check AUTORIZE
     
fi #Fim check OPTIONS and OPT

fi # Fim se variável ${OPT} é string

fi #Fim FILE = NAME
##################END BLOCO 2####################

Scripts recomendados

Mantenha seu relógio ajustado 2.0

Repasse de parâmetros de um script a outro

Script contra ataques de Brutal Force por SSH.

Montando sua máquina virtual para engenharia reversa em Linux

Limpando conexão ociosa


  

Comentários

Nenhum comentário foi encontrado.


Contribuir com comentário




Patrocínio

Site hospedado pelo provedor RedeHost.
Linux banner

Destaques

Artigos

Dicas

Tópicos

Top 10 do mês

Scripts