#!/bin/sh ###################################################################### # Gary Keen version 0.0.4 # 01/02/21 | 1/22/21 | 1/25/21 | 2/4/2021 # # Description: # A script to put in place all the files,permissions,directories # needed to convert systemd startup to systemV startup. # # /root/StartupScripts -- All startup script that do not start with READ # will get executed # /usr/lib/systemd/system/mystartup.service -- Unit file # /etc/rc.d/init.d/StartUp --- Must be executable # # # Notes/Updates: # -- Changed the way the init script is built. Tail the bottom of this script. # I know not very elegant but the $variables and exe code wouldn't show up. # -- Ubuntuized for future use and the nart. 1/25/2021 # ###################################################################### # #========================= What OS am I ===========================# cat /etc/*release* |grep ID_LIKE | awk -F"=" '{print $2}' | grep rhel >/dev/null 2<&1 EXIT1=$? cat /etc/*release* |grep ID_LIKE | awk -F"=" '{print $2}' | grep debian >/dev/null 2<&1 EXIT2=$? #========================= Create variables =========================# # ROOTDIR=/root/StartupScripts REDME=$ROOTDIR/README.txt if [ $EXIT1 = 0 ] then INITSCRPT=/etc/rc.d/init.d/StartUp UNITFILE=/usr/lib/systemd/system/mystartup.service fi # if [ $EXIT1 = 0 ] then echo "[Unit] Description=My startup scripts After=network.target [Service] ExecStart=/etc/rc.d/init.d/StartUp & [Install] WantedBy=multi-user.target WantedBy=graphical.target" > $UNITFILE fi # if [ $EXIT2 = 0 ] then INITSCRPT=/etc/init.d/StartUp UNITFILE=/lib/systemd/system/mystartup.service fi # if [ $EXIT2 = 0 ] then echo "[Unit] Description=My startup scripts After=network.target [Service] ExecStart=/etc/init.d/StartUp & [Install] WantedBy=multi-user.target WantedBy=graphical.target" > $UNITFILE fi # if [ $EXIT1 = 1 -a $EXIT2 = 1 ] then echo echo " Unknown OS --- exiting..... " fi echo echo "This is the init script and the unit file that will be used, respectfully." echo echo "init script" echo $INITSCRPT echo "unit file" echo $UNITFILE echo echo "Displaying the unit file to be used." echo cat $UNITFILE echo echo "Press enter." read ANSW0 # #======================== Build functions ============================# # contin () { echo "Press enter to continue." read ANSW0 } # enablescript () { systemctl enable mystartup.service systemctl status mystartup.service } # readme () { echo " Anything dropped in this directory that DOSE NOT begin with the word READ. Will be executed during startup. Directory and file location: startup script directory = $ROOTDIR Drop script here to have them executes at startup. unit file = $UNITFILE initscript = $INITSCRPT" >$REDME } # open () { echo echo "This script creates a directory in /root call StartupScripts" echo "Anything dropped in that directory that DOSE NOT begin with" echo "the word READ. Will be executed during startup." echo echo "This script creates a systemd unit file and a script to be" echo "executed from that unit file." echo contin } # crtfiledirs () { mkdir $ROOTDIR sleep 1 touch $INITSCRPT chmod 755 $INITSCRPT touch $UNITFILE } # initscript () { cat $0 | tail -19 >$INITSCRPT } # # rhelunitfile () { # echo "[Unit] # Description=My startup scripts # After=network.target # [Service] # ExecStart=/etc/rc.d/init.d/StartUp & # [Install] # WantedBy=multi-user.target # WantedBy=graphical.target" > $UNITFILE # } # # ubununitfile () { # echo "[Unit] # Description=My startup scripts # After=network.target # [Service] # ExecStart=/etc/init.d/StartUp & # [Install] # WantedBy=multi-user.target # WantedBy=graphical.target" > $UNITFILE # } # crtlinks () { # ln -s /etc/rc.d/init.d/StartUp $ROOTDIR/README_startup_init_script ln -s $INITSCRPT $ROOTDIR/README_startup_init_script ln -s $UNITFILE $ROOTDIR/README_mystartup_unit_file # ln -s /usr/lib/systemd/system/mystartup.service $ROOTDIR/README_mystartup_unit_file echo echo "Drop executable script in the /root/StartupScripts to have them executed at startup." echo } # # #============================ Execute functions =============================# # echo echo "I'm not sure this script is ready for prime time yet." echo "Use at your own risk until I can confirm it works as it should." echo contin open crtfiledirs initscript sleep 1 enablescript crtlinks readme #------EOF--------DO NOT CHANGE ANYTHING BELOW THIS LINE-------EOF----------# #!/bin/sh ###################################################################### # Gary Keen # # # One startup to rule them all # # # # ###################################################################### SCRIPTDIR=/root/StartupScripts for A in `ls $SCRIPTDIR | grep -v READM` do echo $A $SCRIPTDIR/$A done