Copying from a thumb drive into our Termux world takes a bit of doing. It’s actually yet another “expert friendly” part of Android. If you don’t already know where things go you can’t find them. I had an 8 Gig thumb drive in my Android 2 in 1 while doing the other Termux stuff. I mention that because I don’t know if the Android device did it or running the program to make storage available did, but an Android directory tree was created out there with a directory for each application.
Disk Storage
Yes, I know, many people don’t know they aren’t folders, they are directories. An entire generation has grown up not understanding disk storage.
I’m glad I didn’t start with a 64 Gig thumb like I tried later. Android, when it wakes up from sleep mode, feels compelled to “check the drive for errors” before letting you enter your password. I guess that is why so many of these devices go around unsecured. I’m a good 5 minutes in and I still haven’t received the password prompt to unlock the device. I have to keep hitting the shift key so it doesn’t go back into sleep mode. I stuck that thumb drive in because it was handy. I stuck in the other thumb because I am curious as to whether Android automatically creates this storage when it “checks for errors” or if it was the thing we ran in Termux.
The second directory tree is similar to the one you find on the internal storage device. The fact they are both much the same is my source of confusion. I do notice the bluemail email app and a few others are not on the thumb drive.
Copying Files
Basically we need to select 2 different sets of files. Copy one to the com.termux directory found on the thumb drive and copy the other to the com.termux directory we find in the internal storage tree. You can forget about being able to copy directly to your “home” directory because it isn’t visible.
PostgreSQL Again
As discussed in the previous post that particular directory tree is blocked from view in the GUI even though the command line created a directory out there we can access from within the termux environment. You do remember that for PostgreSQL we issued the following command don’t you?
pg_ctl -D /data/data/com.termux/files/home/pg -l logfile start
We will get around to looking at that in a bit.
I chose a text file containing my email signature. Something small, simple, and easily looked at. Once you have the file you want visible on the screen you need to hit the three vertical dots in the upper right corner of the window. This makes the control menu appear as shown in the image. After that you can touch one or more files on the screen to select them. Notice the blue highlight indicating the file has been selected. After you have selected the needed file(s) you then touch the copy icon which looks like 2 sheets of paper and is in the same toolbar as the control menu.
Your toolbar will change once files have been copied. Notice the clipboard now appears. The copy and trashcan have both disappeared. I navigated back and pasted this file in the com.termux directory of the thumb drive.
Next I wanted different files for our second location test. I selected my hidden jed configuration file and the jed quick reference guide. Sadly jed has not yet been included in termux packages. It’s a rather serious terminal based editor running on many different platforms including OpenVMS.
Now I navigated to the internal storage com.termux directory to paste them. In part I chose the hidden file just for grins to see if it would show up.
We are now ready to see what it is we can see from within termux. No great magic, just the ls command.
Sorry about that first image. Notice that our second image listing storage/shared puts up a directory tree which looks just like the default file manager listing. If you are willing to squint at the first image you will notice that storage/external-2 is the thumb drive. I presume storage/external-1 is the micro SD card. Yes, we find our quick reference file in storage/shared/Android/data/com.termux/files.
No Access to /tmp
We now have to discuss a rather annoying thing. The /tmp directory. You don’t have access to it. This meant I had to hack the import script I’ve used for years (decades?)
declare -i tax_year=1992 declare -i current_year=$(date +%Y)+1 export PGUSER=roland export PGPASSWORD=spooge_1 if [ -z $TMPDIR]; then export TMPDIR=/tmp fi echo "Current Year $current_year" # # With needed parameters setup and environment verified # delcare all functions which will be used later on. # function tax_db_open_error { echo "creating database" createdb tax_$tax_year 'Tax information for $tax_year' psql -q -d tax_$tax_year -f create_tax_tables.sql echo "database created" } echo ";;;;;" echo ";;;;;" echo ";;;;; Copying csv files to $TMPDIR" echo ";;;;;" echo ";;;;;" cp -f -v ~/postgres_tax_backups/*.csv $TMPDIR chmod a+r "$TMPDIR"/*.csv while [ $tax_year -lt $current_year ] do echo ";;;;;" echo ";;;;;" echo ";;;;; Loading $tax_year" echo ";;;;;" echo ";;;;;" old_error_trace=$(set +o | grep errtrace) # keep track of old error traps set -o errtrace trap tax_db_open_error ERR # setup trap for open error echo "creating tax tables" psql -q -f create_tax_tables.sql tax_$tax_year trap - ERR # reset ERR trap echo "copy payees from '$TMPDIR/tax_${tax_year}_payees.csv' csv header;" > import_it.sql echo "copy categories from '$TMPDIR/tax_${tax_year}_categories.csv' csv header;" >> import_it.sql echo "copy expenses from '$TMPDIR/tax_${tax_year}_expenses.csv' csv header;" >> import_it.sql echo " Extracting ... $tax_year" psql -q -f import_it.sql tax_$tax_year psql -q -d tax_$tax_year -c "select setval( 'expenses_tran_id_seq', (select max(tran_id) from expenses)+100);" let "tax_year += 1" done
Basically I had to add that if statement to force an exported definition of TMPDIR if one didn’t exist because that is the environment variable termux provides the shell.
Success!
After everything imports I can run a little query to show my data.
$ $ psql tax_1998 psql (9.6.3) Type "help" for help. tax_1998=# select * from expenses limit 10; tran_id | tran_dt | category | tax_ded | payee | amount ---------+------------+---------------------------+---------+----------------------------------------------------+-------- 1 | 1998-01-02 | AUTOMOBILE FUEL | t | Shell Oil | 6.00 2 | 1998-01-02 | CLIENT ENTERTAINMENT | t | Tub House Ltd. | 30.00 3 | 1998-01-02 | AUTOMOBILE FUEL | t | Shell Oil | 15.50 4 | 1998-01-03 | MEDICAL | t | Glen Ellyn Clinic | 20.00 5 | 1998-01-03 | AUTOMOBILE FUEL | t | Shell Oil | 5.00 6 | 1998-01-04 | CLIENT ENTERTAINMENT | t | Pockets | 50.00 7 | 1998-01-05 | AUTOMOBILE FUEL | t | Shell Oil | 10.00 8 | 1998-01-09 | RENT | t | Telmark Inc. | 277.00 9 | 1998-01-09 | BOOKS/EDUCATION | t | Amazon.com, Inc. | 56.85 10 | 1998-01-09 | AUTOMOBILE FUEL | t | Shell Oil | 12.00 (10 rows) tax_1998=#
So, we now know PostgreSQL runs under termux. It doesn’t automatically start because they don’t have services. It is also highly unlikely a true Android app running in the GUI will be able to find the database listening on the correct port but that is a test for another day.
Our next step is to install PostgreSQL on my Raspberry Pi, do the data import, perform the query, then compile the current application as-is to make sure everything runs there as expected.
After that we redevelop the app in a more Qt 5.x consistent manner because after 10+ years many of the bugs I coded around have been fixed and because I know more now. I just never had a reason to rewrite it because it always worked. Then we can foray into cross compiling.
Related posts:
Where Did My QDebug Output Go?