#!/bin/bash do { #//////////////////////////////////// # DietPi AutoStart Script # #//////////////////////////////////// # Created by Daniel Knight / daniel.knight@dietpi.com / dietpi.com # #//////////////////////////////////// # # Info: # - filename /DietPi/dietpi/dietpi-autostart # # Usage: # - dietpi-autostart (menu system) # - dietpi-autostart int (set value only) #//////////////////////////////////// #Grab Input (valid interger) setglobal INPUT = '-1' if [[ $1 =~ ^-?[0-9]+$ ]] { setglobal INPUT = $1 } #Import DietPi-Globals --------------------------------------------------------------- source /DietPi/dietpi/func/dietpi-globals G_CHECK_ROOT_USER export G_PROGRAM_NAME='DietPi-Autostart' #Import DietPi-Globals --------------------------------------------------------------- #///////////////////////////////////////////////////////////////////////////////////// # MENUS #///////////////////////////////////////////////////////////////////////////////////// setglobal WHIP_BACKTITLE = ''DietPi-AutoStart'' setglobal WHIP_TITLE = $WHIP_BACKTITLE setglobal CHOICE = '0' setglobal OPTION = '0' setglobal TARGETMENUID = '0' setglobal AUTO_START_INDEX = '0' proc Apply_Boot_Index{ #Always disable LightDM systemctl disable lightdm.service &> /dev/null # - Amiberry | always disable services, service launched by DietPi/boot if non fastboot mode systemctl disable amiberry.service &> /dev/null systemctl disable amiberry-sdl2.service &> /dev/null sed -i '/^boot_delay=0/d' /DietPi/config.txt if test -f /boot/cmdline.txt { sed -i 's/logo.nologo//' /boot/cmdline.txt sed -i 's/loglevel=3//' /boot/cmdline.txt sed -i 's/console=tty3/console=tty1/' /boot/cmdline.txt } # - Disable custom launch service rm /etc/systemd/system/dietpi-autostart_custom.service &> /dev/null # - Disable auto login rm /etc/systemd/system/getty@tty1.service.d/autologin.conf &> /dev/null #---------------------------------------------------------------------- #Enable autoboot options # Custom script, service without auto login: https://github.com/Fourdee/DietPi/issues/1024 if sh-expr ' $AUTO_START_INDEX == 14 ' { cat << """ > /etc/systemd/system/dietpi-autostart_custom.service [Unit] Description=DietPi autostart (Custom /var/lib/dietpi/dietpi-autostart/custom.sh) After=dietpi-boot.service dietpi-ramdisk.service dietpi-ramlog.service rc-local.service Requires=dietpi-boot.service dietpi-ramdisk.service [Service] Type=idle ExecStartPre=/bin/bash echo -e 'Starting DietPi-Autostart (Custom) script' ExecStart=/bin/bash -c /var/lib/dietpi/dietpi-autostart/custom.sh StandardOutput=tty RemainAfterExit=yes [Install] WantedBy=multi-user.target """ > /etc/systemd/system/dietpi-autostart_custom.service [Unit] Description=DietPi autostart (Custom /var/lib/dietpi/dietpi-autostart/custom.sh) After=dietpi-boot.service dietpi-ramdisk.service dietpi-ramlog.service rc-local.service Requires=dietpi-boot.service dietpi-ramdisk.service [Service] Type=idle ExecStartPre=/bin/bash echo -e 'Starting DietPi-Autostart (Custom) script' ExecStart=/bin/bash -c /var/lib/dietpi/dietpi-autostart/custom.sh StandardOutput=tty RemainAfterExit=yes [Install] WantedBy=multi-user.target _EOF_ systemctl enable dietpi-autostart_custom.service # Uae4arm special | fast boot via enabled service } elif sh-expr ' $AUTO_START_INDEX == 6 || $AUTO_START_INDEX == 12 ' { #SDL1 if sh-expr ' $AUTO_START_INDEX == 6 ' { systemctl enable amiberry.service #SDL2 } else { systemctl enable amiberry-sdl2.service } # - apply tweaks if sh-expr ' ! $(cat /DietPi/config.txt | grep -ci -m1 '^boot_delay=0') ' { echo -e "boot_delay=0\n" >> /DietPi/config.txt } if sh-expr ' ! $(cat /boot/cmdline.txt | grep -ci -m1 ' logo.nologo') ' { sed -i 's/rootwait/rootwait logo.nologo/' /boot/cmdline.txt } if sh-expr ' ! $(cat /boot/cmdline.txt | grep -ci -m1 ' loglevel=3') ' { sed -i 's/rootwait/rootwait loglevel=3/' /boot/cmdline.txt } if sh-expr ' ! $(cat /boot/cmdline.txt | grep -ci -m1 ' console=tty3') ' { sed -i 's/console=tty1/console=tty3/' /boot/cmdline.txt } # Enable auto login } elif sh-expr ' $AUTO_START_INDEX > 0 ' { mkdir -p /etc/systemd/system/getty@tty1.service.d &> /dev/null cat << """ > /etc/systemd/system/getty@tty1.service.d/autologin.conf [Service] ExecStart= ExecStart=-/sbin/agetty --autologin root %I $TERM """ > /etc/systemd/system/getty@tty1.service.d/autologin.conf [Service] ExecStart= ExecStart=-/sbin/agetty --autologin root %I $TERM _EOF_ } #Amiberry (RPi) lower framebuffer size to increase memory performance: https://github.com/Fourdee/DietPi/issues/474#issuecomment-243124631 if sh-expr ' $G_HW_MODEL < 10 ' { if sh-expr ' $AUTO_START_INDEX == 6 || $AUTO_START_INDEX == 8 || $AUTO_START_INDEX == 12 || $AUTO_START_INDEX == 13 ' { sed -i '/framebuffer_width=/c\framebuffer_width=854' /DietPi/config.txt sed -i '/framebuffer_height=/c\framebuffer_height=480' /DietPi/config.txt } } #Save boot index. echo -e $AUTO_START_INDEX > /DietPi/dietpi/.dietpi-autostart_index systemctl daemon-reload } #TARGETMENUID=0 proc Menu_Main{ #existing boot flag setglobal AUTO_START_INDEX = $[cat /DietPi/dietpi/.dietpi-autostart_index] local option_name=( '0' 'Console: Manual login (default)' '7' 'Console: Automatic login' '6' 'AmiBerry SDL1: Fast boot' '8' 'AmiBerry SDL1: Standard boot' '12' 'AmiBerry SDL2: Fast boot' '13' 'AmiBerry SDL2: Standard boot' '10' 'CAVA Spectrum' '11' 'Chromium: Without desktop' '14' 'Custom: /var/lib/dietpi/dietpi-autostart/custom.sh' '2' 'Desktops: Automatic login (recommended)' '16' 'Desktops: LightDM login prompt' '5' 'DietPi-Cloudshell' '9' 'DXX-Rebith: Descent 1/2' '15' 'JRiver' '1' 'Kodi' '4' 'OpenTyrian' '3' 'RetroPie' ) setglobal OPTION = $[whiptail --title $WHIP_TITLE --menu "Current AutoStart Option: $AUTO_START_INDEX\n\nNB: If your choice is not \"Console:\", please ensure required software is installed (or selected for install) in DietPi-Software." --cancel-button "Back" --backtitle $WHIP_BACKTITLE --default-item $AUTO_START_INDEX 20 75 9 $(option_name[@]) !3 > !1 !1 > !2 !2 > !3] setglobal CHOICE = $Status if sh-expr ' $CHOICE == 0 ' { #Apply Selected boot option setglobal AUTO_START_INDEX = $OPTION Apply_Boot_Index #AmiBerry fast boot info if sh-expr ' $OPTION == 6 ' { whiptail --title "AmiBerry: (Fast boot)" --msgbox "AmiBerry: (Fast boot):\nA highly optimized and tweaked boot mode.\nThis mode allows for a < 2.5 second boot on a RPi 3, into AmiBerry.\n\nIf you experience boot issues with this mode, please try (Standard Boot)" --backtitle $WHIP_BACKTITLE 14 70 } #Custom info if sh-expr ' $OPTION == 14 ' { # create template if test ! -f /var/lib/dietpi/dietpi-autostart/custom.sh { mkdir -p /var/lib/dietpi/dietpi-autostart cat << """ > /var/lib/dietpi/dietpi-autostart/custom.sh #!/bin/bash #---Examples--- # - Chromium #xinit chromium # - LXDE #startx # - Print hello #echo -e "Hello" #---Put your code below this line--- """ > /var/lib/dietpi/dietpi-autostart/custom.sh #!/bin/bash #---Examples--- # - Chromium #xinit chromium # - LXDE #startx # - Print hello #echo -e "Hello" #---Put your code below this line--- _EOF_ chmod +x /var/lib/dietpi/dietpi-autostart/custom.sh # Service whiptail --title "Custom: /var/lib/dietpi/dietpi-autostart/custom.sh" --msgbox "A template script has been created:\n - /var/lib/dietpi/dietpi-autostart/custom.sh\n\nPlease edit this file and enter the required commands you wish to launch. DietPi will then execute this script during boot." --backtitle $WHIP_BACKTITLE 14 70 } } } else { #Exit setglobal TARGETMENUID = '-1' } unset option_name } #///////////////////////////////////////////////////////////////////////////////////// # Main Loop #///////////////////////////////////////////////////////////////////////////////////// #Start Menu if sh-expr ' $INPUT == -1 ' { while sh-expr ' $TARGETMENUID > -1 ' { #Clear Screen buffer clear if sh-expr ' $TARGETMENUID == 0 ' { Menu_Main } } #Apply boot index } elif sh-expr ' $INPUT >= 0 ' { setglobal AUTO_START_INDEX = $INPUT Apply_Boot_Index } #----------------------------------------------------------------------------------- exit #----------------------------------------------------------------------------------- }