#!/bin/sh ###################################################################### # Gary Keen version 0.0.5 # # 01/02/21 | 1/22/21 | 1/25/21 | 2/4/2021 | 10/12/21 | 3/27/24 # # 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 # -- I have tested this on Ubuntu and it works. 10/12/21 # -- I also removed a line from the from the bottom of this script removing a linex` # line at the top, so tail 18 not 19 -- 10/21/12 # -- I added a function to create the variables so they wouldn't spew out before # I check if the script had already been run, 10/12/21 # ###################################################################### # #========================= 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 =========================# # setvars () { 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..... " exit 0 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 " Directory and file location: startup script directory = $ROOTDIR Drop script here to have them executes at startup. unit file = $UNITFILE initscript = $INITSCRPT" >$REDME } # ibeenrun () { ls /root |grep StartupScripts >/dev/null 2<&1 EXITBEENRUN=$? if [ $EXITBEENRUN = 1 ] then contin else echo "====================================================" echo "Checking to see if this script has been run already." echo "====================================================" echo echo "The directory /root/StartupScripts EXISTS." echo "This would mean this script has ALREADY BEEN run." echo "Are you sure you want to run this script again ?" contin echo "Are you sure ?????????????????" contin fi } # 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 ibeenrun } # crtfiledirs () { mkdir $ROOTDIR sleep 1 touch $INITSCRPT chmod 755 $INITSCRPT touch $UNITFILE } # initscript () { ## cat $0 | tail -19 >$INITSCRPT cat $0 | tail -18 >$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 setvars 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