Posts mit dem Label nano pi werden angezeigt. Alle Posts anzeigen
Posts mit dem Label nano pi werden angezeigt. Alle Posts anzeigen

friendlyarm NenoPi Neo Air - Aliases and kill python processes with name

 vim ~/.bash_aliases  
1
2
alias kp="pgrep python | xargs sudo kill"  
alias tp="top -b -n1 | grep python"  

friendlyarm NenoPi Neo Air - systemd - WLAN AP auto config

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
[Unit]
Description=Copy user wpa_supplicant.conf
ConditionPathExists=/boot/wpa_supplicant.conf
Before=dhcpcd.service

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/bin/mv /boot/wpa_supplicant.conf /etc/wpa_supplicant/wpa_supplicant.conf
ExecStartPost=/bin/chmod 600 /etc/wpa_supplicant/wpa_supplicant.conf

[Install]
WantedBy=multi-user.target

friendlyarm NenoPi Neo Air - WIFI

VORGEHEN ZUM AKTIVIEREN BZW. ÄNDERN DES PI ALS WLAN HOTSPOT:

Über serielles Terminal (USB-Kabel) auf pi einloggen. Falls WLAN Hotspot bereits existiert, dann mit dem PC sich damit verbinden und ein SSH Terminal Sitzung zum WLAN 192.168.8.1 verbinden. Dann die folgendes eingeben:

1
2
Sudo touch /usr/share/network-conf/ap/iptables.up.rules
sudo turn-wifi-into-apmode yes

SSID und Passwort eingeben:
default: SSID=sensor-xx PASSWORD=123456789

ALTERNATIVES VORGEHEN ZUM EINRICHTEN DES PI ALS CLIENT:

# Wifi Hotspot am PC einrichten
# Über serielles Terminal auf pi einloggen, dann

1
2
sudo nmcli dev wifi
sudo nmcli dev wifi connect "SSID" password "PASSWORD" ifname wlan0

# die Einstellungen werden gespeichert und auch nach Neustart wird Verbindung aufgebaut.

FALLS SCHON MAL IN DEN NETZWERKEINSTELLUNGEN RUMGEFUSCHT WURDE:

1
sudo nmcli dev

#if the status of a device is "unmanaged" it means that device cannot be accessed by NetworkManager. To make it accessed you need to clear the settings under "/etc/network/interfaces" and reboot your system.

1
2
3
sudo nmcli r wifi on
sudo nmcli dev wifi
sudo nmcli dev wifi connect "SSID" password "PASSWORD" ifname wlan0

How do I grab an INI value within a shell script?

 

Just include your .ini file into bash body:

File example.ini:

1
2
3
DBNAME=test
DBUSER=scott
DBPASSWORD=tiger

File example.sh

1
2
3
4
5
#!/bin/bash
#Including .ini file
. example.ini
#Test
echo "${DBNAME}   ${DBUSER}  ${DBPASSWORD}"
[ Source: https://stackoverflow.com/questions/6318809/how-do-i-grab-an-ini-value-within-a-shell-script ] 

How to create a Systemd service in Linux

 

At times you create a script and then you want to have the scripts controlled by systemd or in some cases you wish to have the scripts getting restarted by itself when it is killed due to some reason. In such cases systemd in Linux helps to configure services which can be managed. To do so follow the following steps.

  1. 1
    cd /etc/systemd/system
    

  2. Create a file named your-service.service and include the following:
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    [Unit]
    Description=<description about this service>
    
    [Service]
    User=<user e.g. root>
    WorkingDirectory=<directory_of_script e.g. /root>
    ExecStart=<script which needs to be executed>
    Restart=always
    
    [Install]
    WantedBy=multi-user.target
    
     
  3. Reload the service files to include the new service.
    1
    sudo systemctl daemon-reload
    

  4. Start your service
    1
    sudo systemctl start your-service.service
    

  5. To check the status of your service
    1
    sudo systemctl status your-service.service
    

  6. To enable your service on every reboot
    1
    sudo systemctl enable your-service.service
    
     
  7. To disable your service on every reboot
    1
    sudo systemctl disable your-service.service
    


    That's it !

 [ Source: https://www.shubhamdipt.com/blog/how-to-create-a-systemd-service-in-linux/]

 

Creating /boot/ssh and /boot/wpa_supplicant.conf (for a headless setup) works, but how?

Have you ever wondered HOW this works? I did. And it was quite the rabbit hole to go down.
  • First I Googled and found the documentation about creating the file /boot/ssh
  • I never managed to find any official documentation on creating the file /boot/wpa_supplicant.conf (Though I did find lots of references that stated that it did work.)
  • Then I studied https://github.com/RPi-Distro/pi-gen extensively.
  • But I couldn't find anything that looked for /boot/ssh or /boot/wpa_supplicant.conf
  • Then I started looking for packages that may contain the implementation.
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    ~/src/pi-gen $ cat $(find stage[012] -type f -name '*package*') | tr " " "\n" | grep 'pi' | sort
    libraspberrypi-bin
    libraspberrypi-dev
    libraspberrypi-doc
    libraspberrypi0
    pi-bluetooth
    python-rpi.gpio
    raspberrypi-bootloader
    raspberrypi-net-mods
    raspberrypi-sys-mods
    raspi-config
    raspi-copies-and-fills
    rpi-update
    
  • I grabbed all the matching packages I could find in https://archive.raspberrypi.org/debian/pool/main/r/
  • I got lucky with raspberrypi-net-mods and raspberrypi-sys-mods
I finally discovered that it is a bit of systemd magic that makes each happen.

raspberrypi-net-mods.service
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
[Unit]
Description=Copy user wpa_supplicant.conf
ConditionPathExists=/boot/wpa_supplicant.conf
Before=dhcpcd.service

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/bin/mv /boot/wpa_supplicant.conf /etc/wpa_supplicant/wpa_supplicant.conf
ExecStartPost=/bin/chmod 600 /etc/wpa_supplicant/wpa_supplicant.conf

[Install]
WantedBy=multi-user.target
Notice the ConditionPathExists and ExecStart! That's pretty clever.

Similarly, but slightly more clever.

raspberrypi-sys-mods.sshswitch.service
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
[Unit]
Description=Turn on SSH if /boot/ssh is present
ConditionPathExistsGlob=/boot/ssh{,.txt}
After=regenerate_ssh_host_keys.service

[Service]
Type=oneshot
ExecStart=/bin/sh -c "update-rc.d ssh enable && invoke-rc.d ssh start && rm -f /boot/ssh ; rm -f /boot/ssh.txt"

[Install]
WantedBy=multi-user.target
Now that I've uncovered this, I can finally finish the project I started with this thread nearly 5 years ago. It's been a long journey of discovery, this $35 whim I indulged in back in May 2012

https://www.raspberrypi.org/forums/viewtopic.php?t=198660

Datei in einer windows.wim image ändern

 Um Dateien in einer Datei.wim zu ändern, und zwar nicht im 1. Index sondern 2. öffnet man Powershell (ich habs jetzt im admin Modus gestart...