TN5250 Emulation on Raspberry Pi 5 with Auto Login & Auto Start
First we have to prepare the Pi's SD card! I'm doing this on a Mac but the process should be similar on a PC.
- Download Rapberry Pi Imager
- Launch the application and use the following:
- Raspberry Pi Device: Raspberry Pi 5
- Raspberry Pi OS: Raspberry Pi OS Lite (64-bit)
Once the card has been prepped go ahead and insert into the Raspberry Pi and connect the Pi to a keyboard and a monitor and power of course!
First lets get the font size just right!
sudo dpkg-reconfigure console-setup
- Encoding: UTF-8
- Character Set: Guess optimal
- Terminus
- 16x32
You may also need to select a country before WiFi can be enabled:
sudo raspi-config
- Localization Options
- WLAN Country
- Choose your country
- Finish
Reboot
Configure the WiFi connection
nmtui
- Edit a connection
- Add
- Wi-Fi
- Fill in Profile Name (default is ok), SSID, Security, Password
- Scroll down to ok, press enter
- Back
- Quit
Now let's setup a good screen resolution!
sudo nano /boot/firmware/cmdline.txt
at the end of the file add
video=HDMI-A-1:1280x720@60
Save the file and reboot the Pi
Let's install the required dependencies!
sudo apt update
sudo apt install build-essential libncurses5-dev libssl-dev autoconf libtool
sudo apt install git
Download the TN5250 source code!
git clone https://github.com/tn5250/tn5250.git
Compile the source code!
cd tn5250
mkdir m4
./autogen.sh
./configure
make
sudo make install
Let's test and make sure we can open a session!
tn5250 your-as400-ip-address
In some cases, the lib5250.so.0 can't be found so we ahve to add the library to ld.so.conf
First lets make sure we know where the lib5250.so.0 file is
sudo find / -name "lib5250.so.0"
Once found lets add it to the ld.so.conf
echo "/usr/local/lib" | sudo tee /etc/ld.so.conf.d/tn5250.conf
Update the Linker Cache
sudo ldconfig
Now that everything works lets setup Auto Login
Open the getty service override file for the tty1 console in a text editor
sudo systemctl edit getty@tty1.service
Add the following lines to the file to enable auto-login:
[Service]
ExecStart=
ExecStart=-/sbin/agetty --autologin pi --noclear %I $TERM
Replace pi
with your username if you are not using the default pi
user.
The ExecStart=
line is cleared first to remove the default value, and then the new value is added.
Save the file and exit the editor (CTRL+X, then Y, and Enter)
Reload the Systemd Daemon
sudo systemctl daemon-reload
Restart the getty Service
sudo systemctl restart getty@tty1.service
That gets us to the point of logging into the OS automatically, we now have another login to automate and that is to get logged into the AS/400 session!
AS/400 Auto Login
To do this, we will first need to install some software!
sudo apt install expect
Now lets create the script that will handle the login
nano tn5250_auto_login.sh
Copy and paste the following script, making sure to edit host, user, password, and device!
#!/usr/bin/expect -f
set timeout 1
set host "your-as400-ip-address"
set user "YOUR_USERNAME"
set password "YOUR_PASSWORD"
set device "MYWSID"
sleep 5
spawn tn5250 $host env.DEVICE=$device
expect "User"
send "$user\t"
expect "Password"
send "$password\r"
interact
Make the script executable
chmod +x tn5250_auto_login.sh
Run the script to test!
./tn5250_auto_login.sh
This should launch the TN5250 session and auto login using the credentials you supplied in the script!
Next is Auto Launch so that the script launches once the OS is booted!
nano ~/.bashrc
Add the following lines at the end of the file
if [ "$(tty)" = "/dev/tty1" ]; then
/path/to/your/script.sh
logout
fi
Save and Reboot, if all went well, your Raspberry Pi should be logging into the OS automatically, launching TN5250 and establishing a session with your AS/400. It should auto login using the credentials you supplied!
That's it hope this was useful for someone, this was more or less just a brain dump for me!!