AKZN Notes

Archives for My Lazy and Forgetful Mind

Install Server Stack to Armbian for CVCMA

Last Modified on

This article is my notes for step by step to install and configure set top box Armbian into kiosk device.

List of Bugs

  1. browser failed to launch immediately

    solution :
    add sleep 60 before launching the browser

  2. display need to restart or reattach the hdmi cable if system rebooted.

    solution:
    use xrandr to relaunch the display driver. Jump to bash part

  3. system boot failur after installing teamviewer.

    not fixed yet, maybe because 8GB SD card is insufficient because teamviewer dependencies is really big (800mb++).

  4. kiosk bash script fail to launch?

    maybe because main monitor is turned off when device restarted. For now we try to add cron with xrandr to detect main monitor.

INSTALL LAMP

To install the LAMP stack (Linux, Apache, MySQL, PHP) on Armbian, you can follow these general steps:

  1. Update your package list:

    sudo apt update
  2. Install Apache:

    sudo apt install apache2
  3. Install MySQL (MariaDB):

    sudo apt install mariadb-server
  4. Secure your MySQL installation:

    sudo mysql_secure_installation
  5. Install PHP and necessary modules:

    sudo apt install php php-mysql
  6. Restart Apache for the changes to take effect:

    sudo systemctl restart apache2

After completing these steps, you should have the LAMP stack installed on your Armbian system. Please note that the instructions might vary slightly depending on the version of Armbian you're using. If you encounter any issues, refer to the Armbian documentation or community for further assistance.

Install PHPMYADMIN

To install phpMyAdmin on your Armbian system with the LAMP stack, follow these steps:

  1. Install phpMyAdmin and PHP extensions:

    sudo apt install phpmyadmin php-mbstring php-*gettext
  2. During the installation, you'll be prompted to choose a web server to configure. Select apache2 by pressing the spacebar and then hit Enter.

  3. Choose 'Yes' when asked if you want to use dbconfig-common to set up the database. You'll be prompted to provide a MySQL application password.

  4. Configure Apache to recognize phpMyAdmin. Create a symbolic link:

    sudo ln -s /usr/share/phpmyadmin /var/www/html
  5. Edit the Apache configuration file to allow access to phpMyAdmin. Open the file for editing:

    sudo nano /etc/apache2/apache2.conf
  6. Add the following lines at the end of the file:

    Include /etc/phpmyadmin/apache.conf
  7. Save and exit the text editor (Ctrl+O, Enter, Ctrl+X).

  8. Restart Apache to apply the changes:

    sudo systemctl restart apache2
  9. If you cant log in to mysql trought phpmyadmin without password, easiest way is adding pasword to your mysql user.

You should now be able to access phpMyAdmin by opening your web browser and navigating to http://your_server_ip/phpmyadmin.

Please replace your_server_ip with the actual IP address or hostname of your Armbian system. If you encounter any issues, refer to the phpMyAdmin documentation or Armbian community for assistance.

setting up MySQL user Password

For example, to change the root password for MySQL, follow these steps:

  1. Log in to MySQL:
    Open a terminal and log in to the MySQL server as the root user. You will be prompted for the current root password:

    mysql -u root -p
  2. Change Password:
    Once logged in, you can change the root password using the following MySQL command. Replace 'newpassword' with your desired new password:

    ALTER USER 'root'@'localhost' IDENTIFIED WITH 'mysql_native_password' BY 'newpassword';

    if above not working, use this

    ALTER USER 'root'@'localhost' IDENTIFIED BY 'newpassword';
    
  3. Flush Privileges and Exit:
    After changing the password, you need to flush privileges for the changes to take effect and then exit MySQL:

    FLUSH PRIVILEGES;
    EXIT;
  4. Restart MySQL:
    Restart the MySQL service to apply the changes:

    sudo systemctl restart mysql
  5. Test New Password:
    Verify that the new password works by logging in to MySQL with the new password:

    mysql -u root -p

Please make sure to choose a strong password and keep it secure. Changing the root password enhances the security of your MySQL installation.

If you encounter any issues during this process, please let me know, and I'll be happy to assist you further.

Install Teamviewer

you can use TeamViewer to access your Armbian device from a remote computer, including a Windows computer. Here's how to set it up:

  1. Install TeamViewer on Armbian:
    You'll need to download and install TeamViewer on your Armbian device. TeamViewer provides a Linux version for ARM devices. You can download it from the TeamViewer website or use the following commands in the terminal:

    wget https://download.teamviewer.com/download/linux/teamviewer-host_armhf.deb
    sudo dpkg -i teamviewer-host_armhf.deb
    sudo apt-get install -f
  2. Start TeamViewer:
    After installation, start the TeamViewer service on your Armbian device:

    sudo teamviewer --daemon start

    please note that teamviewer cant use sudo for security concern.

  3. Connect to Teamviewer account
    After running above command, a TeamViewer dialog will open, asking you to connect your TeamViewer account.
    For remote access using TeamViewer on Linux, connecting the TeamViewer application to an account is a prerequisite.

  4. Obtain TeamViewer ID and Password:
    Once the TeamViewer service is running, you'll need to obtain the TeamViewer ID and temporary password for your Armbian device. You can find this information by running:

    sudo teamviewer info
  5. Troubleshooting error installation

    1. if you encounter issues during accoutn connection, easies way are reinstalling.
      sudo apt-get remove teamviewer-host
      sudo apt-get purge teamviewer-host
      sudo rm -rf /opt/teamviewer
      sudo rm -rf ~/.config/teamviewer
      sudo apt-get install teamviewer-host
  6. Install TeamViewer on Windows:
    Download and install the TeamViewer application on your Windows computer from the TeamViewer website.

  7. Connect to Armbian from Windows:
    Open TeamViewer on your Windows computer and enter the TeamViewer ID of your Armbian device. If prompted, enter the temporary password you obtained earlier.

  8. Remote Access:
    You should now be able to remotely access your Armbian device from your Windows computer using TeamViewer.

Please keep in mind that using remote desktop applications like TeamViewer might involve sharing your device's screen and control over the internet, which may have security and privacy implications. Be sure to use secure passwords and follow best practices for securing remote access.

If you encounter any issues during the setup, refer to the TeamViewer documentation or community for assistance.

Launch Firefox on reboot

easiest way

   sudo crontab -e

then

   @reboot sleep 60 && su {user} -c "DISPLAY=:0.0 /usr/bin/firefox --new-window http://www.google.com"

This cron job directive, @reboot sleep 60 && su $user -c "DISPLAY=:0.0 /usr/bin/firefox --new-window http://www.google.com", ensures that upon system reboot (@reboot), a delay of 60 seconds (sleep 60) is applied before executing a command.

The command uses the su utility to run a specific command as the user $user. The -c flag allows the subsequent command to be executed. The command being executed is designed to launch Firefox (/usr/bin/firefox) with the specified URL (http://www.google.com) in a new window, making it automatically open after the system restarts. The DISPLAY=:0.0 part is used to specify the display environment for the graphical application to appear on the primary display.

Other way to open firefox on launch

Introduction:
This guide outlines a step-by-step process to automatically launch Firefox and open a specific URL when your Armbian device reboots. This can be useful for various purposes, such as displaying information on a dedicated screen.

Prerequisites:

  • Basic familiarity with the Linux command line.
  • Access to your Armbian device.

Steps:

  1. Create a Script:

    • Open a terminal on your Armbian device.
    • Create a script file, for example, start_firefox.sh:
      nano start_firefox.sh
    • Add the following lines to the script file. Replace https://www.example.com with the desired URL:
      #!/bin/bash
      sleep 60  # Delay for 1 minute
      DISPLAY=:0.0 /usr/bin/firefox --new-window http://www.google.com
    • Save the file and exit (Ctrl + O, then Enter, followed by Ctrl + X).
  2. Make Script Executable:

    • Make the script executable:
      chmod +x start_firefox.sh
  3. Move Script to a Suitable Location:
    Move the script to a suitable location, such as /usr/local/bin/ to make it easily accessible:

    sudo mv start_firefox.sh /usr/local/bin/
  4. Edit Cron Jobs:

    • Open the crontab file for editing:
      crontab -e
  5. Add Cron Job with Delay:

    • Add the following line to the crontab file to schedule the script with a delay after reboot (e.g., 2 minutes in this example):
      */2 * * * * /usr/local/bin/start_firefox.sh
  6. Save and Exit:

    • Save the crontab file and exit the text editor.
  7. Reboot:

    • Reboot your Armbian device to test the setup:
      sudo reboot

Explanation:

  • The script start_firefox.sh is created to launch Firefox with the specified URL.
  • The @reboot cron job with a delay is set to run the script after a specified period when the system reboots.
  • The delay ensures that the system fully initializes before executing the script.

Using Chromium

  • fullscreen no restore

    @reboot sleep 60 && su {user} -c "DISPLAY=:0.0 /usr/bin/chromium-browser --new-window --start-fullscreen --no-restore-session http://www.google.com"
  • no cursor (kiosk mode)

    1. install unclutter to hide mouse cursor
      sudo apt-get install unclutter
    2. launch in kiosk mode and unclutter
      @reboot sleep 30 && su {user} -c "DISPLAY=:0.0 unclutter -idle 0.1 -root"
      @reboot sleep 60 && su {user} -c "DISPLAY=:0.0 /usr/bin/chromium-browser --noerrdialogs --disable-infobars --kiosk --incognito --disable-session-crashed-bubble --disable-session-restore http://www.google.com"

change {user} to the active user
in kiosk mode, to exit the fullscreen, use ctrl+w

Conclusion:
By following these steps, you can configure your Armbian device to automatically launch Firefox and open a specific URL upon reboot. This can be useful for displaying information, dashboards, or other web-based content.

Please remember that automatically launching applications on startup may have security and performance implications, so use these instructions responsibly and ensure your device's security.

bash script launch chromium

for the xrandr line, first we need to know which display is detected, then we can move on to relaunch the display

  1. list detected display

    export DISPLAY=:0.0
    
    xrandr
  2. then we can continue to make bash script for cron

    #!/bin/bash
    
    # Give some time for the X server to start
    sleep 60
    
    # fix for armbian not detecting hdmi device on boot
    export DISPLAY=:0.0 XAUTHORITY=/HOME/${user/.Xauthority
    
    xrandr --output HDMI-1 --auto
    
    # Give some time for the display to settle
    sleep 10
    
    # launch chromiun as kiosk mode
    export DISPLAY=:0.0 XAUTHORITY=/HOME/${user}/.Xauthority
    
    /usr/bin/chromium --noerrdialogs --disable-infobars --kiosk --incognito --disable-session-crashed-bubble --disable-session-restore https://google.com

    change ${user} to the logged in user

  3. script to relaunch display if no display avtive (but connected).

    I personally use below script on cron with interval 10 minutes

    #!/bin/bash
    
    # Set main monitor and X display authority
    main_monitor="HDMI-1"
    export DISPLAY=:0.0 XAUTHORITY=/home/$USER/.Xauthority
    
    chromium_command="/usr/bin/chromium --noerrdialogs --disable-infobars --kiosk --incognito --disable-session-crashed-bubble --disable-session-restore https://my.masaj.id/view.masjid?preview=3032084D38"
    
    # Function to restart Chromium
    restart_chromium() {
        pkill chromium
        $chromium_command
    }
    
    # Get current date and time
    timestamp=$(date "+%Y-%m-%d %H:%M:%S")
    
    # Check if HDMI-1 is found in the xrandr output
    if /usr/bin/xrandr | grep -q "$main_monitor connected"; then
        # Get the currently active display
        active_display=$(/usr/bin/xrandr | awk '/\ connected/ && /[[:digit:]]x[[:digit:]].*+/{print $1}')
    
        # Check if the active display is the main monitor
        if [ "$active_display" = "$main_monitor" ]; then
            echo "$timestamp - Active Display: $active_display"
    
            # Check if Chromium is running using top
            isthere=$(top -b -n 1 | grep -w chromium)
    
            if [ -n "$isthere" ]; then
                echo "$timestamp - Chromium is already running on $main_monitor"
            else
                echo "$timestamp - Chromium is not running on $main_monitor, launching..."
                restart_chromium
            fi
    
        else
            # Switch to the main monitor if it's not the active display
            export DISPLAY=:0.0 XAUTHORITY=/home/$USER/.Xauthority
    
            echo "$timestamp - Active Display: $active_display"
    
            # Turn off the current display, switch to the main monitor, and restart it
            xrandr --output $active_display --off
            xrandr --output $main_monitor --auto
            echo "$timestamp - $main_monitor restarted"
    
            # Wait for the changes to take effect
            sleep 5
    
            # Terminate any existing Chromium processes and launch a new instance
            restart_chromium
        fi
    else    
        # If HDMI-1 is not found, terminate Chromium and log the monitor status
        pkill chromium
    
        echo "$timestamp - $main_monitor monitor is down"
    fi
    

Leave a Reply

Your email address will not be published.