Wednesday, June 29, 2022

regexmatch in google sheets

 https://spreadsheetpoint.com/regexmatch-function-google-sheets/

 Regexmatch() returns TRUE if expression matches, FALSE if it doesn't.

Syntax like
=if(regexmatch(D20,"NANDA"),if(regexmatch(D20,"LIFE"),G20,0),0)

means that the cell value would equal G20 if it matches both conditions, and 0 if it doesn't.

https://support.google.com/docs/answer/3093364?hl=en

IF(logical_expression, value_if_true, value_if_false)



Monday, June 27, 2022

adding applications to cinnamon menu

https://kerneltips.com/add-applications-to-cinnamon-menu-in-linux-mint-20

Right-click --> Configure --> Menu Editor --> New Item 

or

Right-click on Desktop --> Create new launcher here 

(it asks "Would you like to add this launcher to the menu also" and will add to the "Other" category.)

Sunday, June 26, 2022

notes on giving access to ad-hoc queries

Copy-pasting from an email exchange:

As you had asked :
who apart from admin can be given a role which will enable viewing and downloading ad-hoc data base query reports for example non editing teacher.

It is safer to keep the visibility of ad-hoc reports limited, because they are very powerful, and making a mistake can cause catastrophic damage to the database. 

But there is an option to send ad-hoc reports by email. Perhaps the non-admins can be sent the reports by email instead?
 
If we want to send those emails directly to those people, Moodle requires us to give access to the query to them - only then does it allow that user to be emailed the report. Instead, if the report is sent to you by email, and you forward it to the relevant users, would that be OK? 

The relevant queries for each user could be named in such a way that when you get emails from those queries, you could put in a GMail filter to automatically forward those emails to the respective people. 

I have set up a test query at
which will email daily at 3 pm. 


Saturday, June 25, 2022

local file sharing over wifi - Android to PC etc

https://linuxhint.com/wireless_file_sharing_apps_linux_android/

https://snapdrop.net

seemed to be the easiest option, since nothing needs to be installed. But right now it doesn't seem to work. Similarly,

https://www.sharedrop.io/

Maybe it is blocked by the Studio network, and would work at home?

Monday, June 06, 2022

changing DNS server for lookups on a systemd Linux machine using the terminal

GUI-based DNS changes are fine, but there seems to be a lot of conflicting info on changing the DNS server using the command line on Linux. For example, 

For Ubuntu 20.04, https://phoenixnap.com/kb/ubuntu-dns-nameservers needs the yaml file in /etc/netplan to be edited, but on Linux Mint 20.3, that yaml file does not contain anything except 

  # Let NetworkManager manage all devices on this system
network:
  version: 2
  renderer: NetworkManager

This post https://forums.linuxmint.com/viewtopic.php?t=321682 talks about installing resolvconf and creating / editing a file  /etc/resolvconf/resolv.conf.d/head which does not exist on Linux Mint 20.3

What does exist is 

/etc/systemd/resolved.conf

(but it has no entries) and also

/etc/resolv.conf

(but it says # This file is managed by man:systemd-resolved(8). Do not edit.
And it does not have the custom name server 8.8.8.8 I have configured via the GUI. )

From https://wiki.archlinux.org/title/Systemd-resolved#Manually I find that the file
/etc/systemd/resolved.conf.d/dns_servers.conf
does not exist - there is no directory called /etc/systemd/resolved.conf.d/

This thread
https://www.digitalocean.com/community/questions/fedora-33-how-to-persist-dns-settings-via-etc-resolv-conf
has some clues about why some methods work, and why some don't - various distros are changing the way in which DNS resolution works, so we would need to look at our specific distribution's docs for correct info.  

Edit: And this thread gives some details about Linux Mint 20.3 - basically saying that we have to use the GUI - https://forums.linuxmint.com/viewtopic.php?t=371120



Wednesday, June 01, 2022

restoring a Windows 11 laptop - Samsung Galaxy Book2 Windows 11 restore install with wifi not recognized

A Samsung Galaxy Book2 laptop which came with Windows 11 Home pre-loaded was not booting into Windows after MX Linux was installed. Checking, found that the reason why Windows was not booting was that MX Linux had been installed on top of the 200 GB Windows partition. The other Windows RE partition which was undisturbed was just the recovery partition, not the C drive. 

Going into "BIOS" settings was a bit of a chore. If Windows was booting, the method is to press Shift+click on Start - Reboot. Without Windows, we need to boot with some bootable device - if it is Grub based, there would be an entry similar to "System Settings", choosing which the machine would reboot into the "BIOS" screen - which in this case also had a GUI. Booting 3 times unsuccessfully is also supposed to take us to that screen. Then we can go to Boot - Boot Device Priority and choose a USB drive as the first boot device. 

Edit: Pressing F10 on power-on also gives the option to choose boot device and or change UEFI boot settings.

Creating a Windows 11 install disk on a 16 GB USB drive using Linux did not work, following the method given here. Perhaps it was due to the NTFS formatting? Or maybe due to some wrong boot flag? Anyway, created a bootable USB drive Windows 11 installer using Windows 10 on another computer, which took 2-3 hours because it downloaded around 5 GB. Booting from that device, once the installation was completed and "Restore from username" was chosen, files were restored from Microsoft OneDrive and activation of Windows 11 Home was also shown to be completed

Before the installation could complete, there was the same issue as with the Samsung Galaxy Book Go LTE, which is that the built in wifi network adapter was not recognized by the Windows 11 installer, so installation would stop at the point where it requires you to log in to a Microsoft account. The workaround in this case was to plug in a USB wifi adapter which was known to work with Linux, which also worked with the Windows 11 installer.   

Tuesday, May 31, 2022

cloning disks on Linux

Just a reminder to myself - dd can clone not just partitions but entire devices as well. https://linuxhint.com/clone-disk-using-dd-linux/ So, if only one partition needs to be cloned,

sudo dd if=/dev/sdb1 of=/dev/sdc1 status=progress

This will take only as much time as needed for the data present that one partition. 

If we want to make a complete clone of all partitions of one USB drive into another,

sudo dd if=/dev/sdb of=/dev/sdc status=progress

This will take much longer, even if the devices are mostly empty. For example, for 16 GB flash drives with only 2 GB of data, it took around 90 minutes on the Macbook Pro, using the default block size, going at around 3 MB per second.

16000 / 3 / 60 = 88.89 minutes.

Monday, May 30, 2022

checking battery cycles in Linux

Via https://forums.linuxmint.com/viewtopic.php?t=144301 
apt install tlp
and suggested packages
sudo apt install tp-smapi-dkms acpi-call-dkms smartmontools linux-tools-generic

sudo tlp-stat --battery
--- TLP 1.3.1 --------------------------------------------

+++ Battery Features: Charge Thresholds and Recalibrate
natacpi    = inactive (no kernel support)
tpacpi-bat = inactive (laptop not supported)
tp-smapi   = inactive (laptop not supported)

+++ Battery Status
No battery data available.

upower -i /org/freedesktop/UPower/devices/battery_BAT0
  native-path:          (null)
  power supply:         no
  updated:              Thursday 01 January 1970 05:30:00 AM (1653903861 seconds ago)
  has history:          no
  has statistics:       no
  unknown
    warning-level:       unknown
    battery-level:       unknown
    icon-name:          '(null)'

Sunday, May 29, 2022

suspend to RAM - sleep mode - issue with Linux Mint 20.3

After an upgrade to Linux Mint 20.3 from 19.3, the Macbook was showing a garbled screen when waking up from sleep - i.e. suspend to RAM had some issue, probably with the graphics card. The suspend would also take 1 to 3 minutes to complete, with the fan being on for that time with a blank screen. Ctrl+Option+Fn+F2 was allowing a text-mode terminal to be opened, and syslog showed "Buffer eviction failed" before the suspend was taking effect.

 
After waking up, the display driver nouveau would complain of invalid op-code.

At first, I thought it might have something to do with the two displays being detected on the Macbook as mentioned on this post,
https://hnsws.blogspot.com/2021/03/linux-mint-workspace-size.html
since I had mirrored displays instead of disabling one display. But even after disabling one display, the same issue continued. 


The workaround was, as that thread suggested, adding the kernel parameter  init_on_alloc=0 on boot. Since I use refind to boot, in my case, the adding of the kernel parameter was done by editing the /boot/refind_linux.conf as in my previous post,
https://hnsws.blogspot.com/2021/08/verbose-display-while-booting-with.html

After doing that, I could check the parameters passed to the kernel in various ways as listed here,
https://www.cyberciti.biz/faq/display-view-linux-kernel-parameters-for-booted/
like 
dmesg | grep "Command line"
[    0.000000] Command line: \\boot\vmlinuz-5.4.0-113-generic root=UUID=65c50557-my-disk-uuid-c7b5d84509d2 ro init_on_alloc=0 initrd=boot\initrd.img-5.4.0-113-generic

And now suspend to RAM works.


Friday, May 27, 2022

mapping custom domains to github pages on multiple repositories

I was under the impression that one user can only map one custom domain to one repository with Github pages. But this post shows how to map multiple custom domains to multiple repositories for the same username -
https://deanattali.com/blog/multiple-github-pages-domains/

So, instead of Nettigritty's flaky domain redirection which doesn't work half the time, I've now used a meta redirect on another repo which has only index.html to redirect one of our websites. So the steps are:

  1. Add A records with IP addresses obtained by dig username.github.io
  2. Add CNAME record pointing to username.github.io (this is the tricky part which people miss out)
  3. Enable github pages in the Github repository settings
  4. Enable custom domain in the Github repository settings.
  5. After site works, enforce HTTPS in the Github repository settings - if necessary, wait 24 hours before doing this for DNS to propagate.


Wednesday, May 25, 2022

privacy policy and other policies in Moodle

There was a request to add an amended privacy and usage policy on one of our Moodle servers. It was desirable that users click to agree to the policy on their next sign-in.

Under Site Administration - Users tab - Privacy and Policies - Policy settings,
there is the option to change from the Default policy handler (which has the option only for a single site policy and a single site policy for guests)
to the policy_tool policy handler, which has the option to add more policies.

https://docs.moodle.org/400/en/Policies
According to this page, when a new policy is added using this tool, all users will be required to agree to that policy on next login.

After the policy handler is changed to policy_tool , then
The new policy can be added using the page
Site Administration - Users tab - Privacy and Policies - Manage policies
https://our.domain/admin/tool/policy/editpolicydoc.php

The policy can be of type
Site policy
Privacy policy
3rd party policy
or
Other policy




Monday, May 23, 2022

dos disk repair on Linux

 https://askubuntu.com/questions/147228/how-to-repair-a-corrupted-fat32-file-system

So, either

sudo apt-get install dosfstools

sudo dosfsck -w -r -l -a -v -t /dev/sdc1 

or

fsck.vfat -a /dev/sdc1

fsck.fat 4.1 (2017-01-24)
Logical sector size is zero.


https://ubuntuforums.org/showthread.php?t=1908329

Apparently

testdisk is the solution. 

Disk /dev/sdc: 232.91 GiB, 250059350016 bytes, 488397168 sectors
Disk model: External USB HDD
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x4d2b50bb

Device     Boot Start       End   Sectors   Size Id Type
/dev/sdc1  *       63 488392064 488392002 232.9G 83 Linux

(In this case, found that the partition had been overwritten by a linux partition :)

Sunday, May 22, 2022

installing a printer on the samsung galaxy book go LTE laptop

Downloading and installing the drivers for the Pixma MG2440 multi-function device - printer and scanner - from Canon's website, the installation did not give any warnings or errors on the Samsung Galaxy Book Go LTE laptop, but the device did not work. No suitable driver found was the error message from the scanner / printer utility. This is probably because this machine has an ARM processor, and the Canon drivers are probably for x86. Even though the ARM-based Windows 11 is supposed to be able to run in emulation mode for 32-bit x86 apps, either the installer was installing 64-bit x86 drivers, or maybe 32-bit drivers don't work in emulation mode.

Anyway, the solution was to get Microsoft's generic Canon inkjet drivers from Windows Update. But the way to do this was not very intuitive. After clicking on "Update driver" in Control Panel, the Windows Update screen is shown, and after "Check for Updates", it shows "No updates found." But lower down, clicking on "Optional updates", it finds two drivers. Installing these made the printer work, albeit with a blank printout due to the ink being exhausted.

Saturday, May 21, 2022

troubleshooting ad-hoc query reports in Moodle

Number of files downloaded per user query

The following was my procedure for making corrections to this ad-hoc Moodle query:

Expanding out the sub-query and running it in DBeaver, could see the discrepancies in the count. Changed the select count() to just select, then went step by step to identify which rows were causing discrepancies, copy-pasting the filenames to adjacent columns on a temporary google sheet for easy comparison. 

It turns out the bugs in the query were due to some assumptions which I made about the prefix_logstore_standard_log table:
1. I assumed each file download led to a single log entry - no, there are multiple log entries for each download
2. I assumed that the shorter query which I used for counting the number of files will be sufficient, apparently it is not.
3. There were also overcounting in case the user was downloading the same file multiple times.

So, I have made some modifications to both the queries, now they shows the number of files downloaded which are of non-zero size. The files listing only shows one filename for each download and does not indicate multiple downloads, so now I have modified the number of files counted per user also to ignore multiple downloads of the same file.
 

In the case of these users I tested, one user has download some files many times, like

Even after this, there were mismatches in the count. The reason is that was, the query "Number of files downloaded per user" counted only distinct filenames.
Now, there are some files with the same name, but with different content, like Fractions.pdf which occurs with different content in different courses. The listing of files shows these separately.

I can correct for this by choosing
count(distinct f2.contenthash) instead of
count(distinct f2.filename)

But still the numbers won't match. This is because there are some files with exactly the same name and same content, in different courses.
For example,
VI Maths || Fractions || VC_Way of Sharing from the Whole.pptx || 779583
VI TNSSE Maths || Fractions Term III || VC_Way of Sharing from the Whole.pptx || 779583

which have both been downloaded by the user we checked.

So, in order to count these files also separately, I will count
count(distinct concat(f2.contenthash,l2.contextinstanceid) instead of simply
count(distinct f2.contenthash)

Then it matches for this user.

Files downloaded per user query

The reason for the "short name of the course, resource reviewed and files downloaded mismatch" for the other query was wrong mapping of resourceid in the log.

In our query, we have
left join vv_resource r on l.objectid = r.id
i.e. we are mapping the objectid to resourceid. But this seems to be wrong.

To see why, I went through all the columns in the logstore log table.
There is a column which says objecttable. For those entries where objecttable says resource, the mapping is correct. For example, pdf files. The contextinstanceid seems to be unique to each course section.

So, I modified the query so that instead of "Resource viewed", I have put the column "Course Module" which shows the correct course module -
vcs.name, from
left join {course_modules} vcm on l.contextinstanceid = vcm.id
left join {course_sections} vcs on vcm.section = vcs.id

Then the query gives correct results for pdf files as well as other file types like pptx.

 


Thursday, May 19, 2022

usrmerge message after fresh Linux Mint 20.3 Install

After a fresh installation of Linux Mint 20.1, which auto-updated to 20.3, there was a system report about usrmerge - 


https://community.linuxmint.com/software/view/usrmerge

This forum post
indicated that the command to be run, in case usrmerge had not yet happened,  
There are two scripts:
/usr/lib/convert-etc-shells
/usr/lib/convert-usrmerge
which execute the needed changes, in case they have not been done already.

But in my case, ls -l / was showing all the symlinks like bin -> usr/bin etc.  So I asked Mint to ignore this report and not show it again. 

Friday, May 13, 2022

Samsung Galaxy Book Go LTE - no wifi after factory reset

After a factory reset, I had shut down a Samsung Galaxy Book Go LTE laptop in order to give it to someone else. After a couple of days, when they were trying to set it up, initial setup was not proceeding after the point where it tries to connect to the network. Checking with a 4G SIM inserted, setup proceeded, and the laptop booted up into Windows 11. But no wifi networks were being detected. The wireless networking device was being flagged in Control Panel.

So, deleted the "Unknown device" in control panel, restarted the machine - now it recognized the wifi adapter, asked to connect to the network, and worked fine. 

Thursday, May 12, 2022

blocking phishing emails from Google Workspace

I was asked how an institution could block some phishing emails, which had the name of the current Vice-Chancellor in the "From" field, with some random gmail id. Excerpts from my reply:

1. Report phishing - You could ask the user to follow these steps - 
image.png

2. From admin.google.com , blocking this particular email - 
You can set up rules using the method at

For example, you could put in a filter so that any email which has
  • simple content search NameOfVC in headers
  • AND is from @gmail.com
  • should be blocked

Thursday, May 05, 2022

printing with HP LaserJet Tank 1020w with Android and Linux

Instead of just connecting the USB cable and using plug-and-play on Linux to install the drivers, thought I would directly try HP's Smart app on Android to install the printer. Worked OK, though it was nearly 100 MB in size. While printing documents shot as photos, my phone makes the background of the pics excessively grey - so probably need to edit the image, bump up brightness and contrast.

Trying to print from Linux Mint 19.3 Tricia, though the network printer was found, and as prompted by the wizard, I had installed the drivers it prompted, giving the print command did not lead to any action on the printer. Pressing the "i" information button was giving a test print on the printer, so the printer itself was fine. 
 
Found a youtube video detailing the installation of the HP Linux Imaging and Printing software hplip, which described the problem I faced exactly. In my case, it looked like hplip version 3.17.10+ was already installed by Linux Mint, but the printer needed a newer version as per

But going through the install process, came across multiple devel packages which the installer was not able to install for Linux Mint 19.3 - like SNMP devel package. 


Some forum posts indicate can make it work without the hplip package. Using the foo2zjs instead, method like
but using github as the source as indicated at

So, I first uninstalled the old version of hplip with apt (I had done this before trying to install the new version of hplip), and then

sudo apt-get update
 sudo apt-get remove cups hplip cups-filters hplip-data system-config-printer-udev
 sudo apt-get install cups build-essential tix groff dc axel
 sudo apt-get install cups-filters cups unp system-config-printer-gnome
 sudo rm -rf /usr/share/hplip
 cd /tmp
 rm foo*
git clone https://github.com/koenkooi/foo2zjs.git
cd foo2zjs
make

# Also, since source code from github already contains all firmware images,
# there is no need to run getweb, as per the askubuntu link above. 

sudo make install
sudo make install-hotplug

# Unplug and re-plug the USB printer into the PC
 # add new HP Laserjet 1020 printer via system-config-printer tool
 # and choose to use foo2zjs foomatic printer driver :

 system-config-printer

# at this step, my system was silent, since I did not connect via USB, but instead on network

Now when I tried a test page print via the network printer shown in Ubuntu, it worked. 
 
Edit 22 May -  On Linux Mint 20.3, which is based on Ubuntu 20.04, the printer installed automatically flawlessly. I just switched on the printer, which had already been set up on the wifi network, Linux automatically detected it and added the printer without me having to do anything, and a print from Gimp worked fine.

Monday, April 25, 2022

fixing an error in a moodle ad-hoc query

One of the ad-hoc queries in one of our moodle servers was returning "Error reading from database" when executing certain queries with certain parameters, working with other parameters.

Troubleshooting - The general issue is that with ad-hoc queries, only the generic error "Error reading from database" is shown, and not the exact cause of the error, which would be some problem with the SQL query. Running the same query using DBeaver, (I had to find/replace { with ourprefix_ and } with a space) 
I get the more helpful error message

SQL Error [1242] [21000]: Subquery returns more than 1 row

Commenting out all except the first subquery, I still got the error. So, there was an issue is with the first subquery.

Looking at the table ourprefix_feedback_value I saw that there are some entries where the name field with match
like '%Chapter%' but the typ field is not a textfield.

Assuming that this is what is causing the problem, I modified the query by adding an additional line in bold below
where
fc.timemodified = fc2.timemodified
and fi2.name like '%Chapter%'
and fi2.typ = 'textfield') as "Chapter name",

This also did not solve the issue. Then, checked the ourprefix_feedback_completed table looking for duplicates in the timestamps like
select fc3.timemodified, count(fc3.timemodified)
from
ourprefix_feedback_value  fv3
left join vv_feedback_item  fi3 on fi3.id = fv3.item
left join vv_feedback_completed  fc3 on fc3.id = fv3.completed
where
fi3.name like '%Main%Script%'
GROUP BY fc3.timemodified
HAVING COUNT(fc3.timemodified) > 1

found 1646480361 was repeated twice. Two feedback items had exactly the same timestamp. Changed the second one to 1646480362 and the problem was solved.


 

Saturday, April 23, 2022

troubleshooting a php framework / cms based site

A couple of websites went down after a server upgrade. Checking out the contents of public_html, found some directories named fuel and codeigniter. Initially thought it was a codeigniter-based site, 

Later, found some function calls like fuel_set_var() which on searching github and google led to FUEL CMS - 

My first impressions were that upgrading from the existing 0.9x version to 1.5x was not so straightforward - the migration tool, mentioned in the documentation above, did not run. Then there is the part of the documentation which says that it needs MySQL 4.x + - 
Hopefully it works with 5.x? Will have to try manually capitalizing filenames and class names as needed for codeigniter 3+. 
"If you have a current installation of 1.3x or less and are wanting to upgrade, there are a few things to be aware of. FUEL 1.4 uses CodeIgniter 3.x which includes a number of changes, the most prominent being the capitalization of controller and model names. Additionally it is more strict on reporting errors."