Ubuntu 22.0.4 and 4G USB Modem Dongle (Huawei) E3372-325

For 4G USB Modem Dongle (Huawei) E3372-325 — first seconds you can see in lsusb Bus 005 Device 013: ID 3566:2001 Mobile Mobile and after Bus 005 Device 015: ID 12d1:155e Huawei Technologies Co., Ltd. Mobile

Full instruction here https://blog.tanatos.org/posts/huawei_e3372h-325_brovi_with_linux/.

So 2 scripts are below

/usr/local/bin/brovi_switch (make it executable!)

#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
# vim: filetype=bash

#   2023-01-28 Pavel Piatruk, piatruk.by

ID=$$

USB_ID=$(basename $DEVPATH)


{
#set|sort 

#ls -la /sys/$DEVPATH

echo bInterfaceClass on ports as follows

grep -H .  /sys$DEVPATH/1*/bInterfaceClass

IC=$( grep -h .  /sys$DEVPATH/*:1.0/bInterfaceClass )

echo "got bInterfaceClass on 1st port $IC"
    echo usb_modeswitch -b $BUSNUM -g $DEVNUM -v 3566 -p 2001

case $IC in
08) 
    echo Storage MODE
    ;;
e0)

    echo "Already RNDIS"
    LOCKFILE=/var/run/brovi.$USB_ID.lock
    if [[ -e $LOCKFILE ]]
    then    
        LOCKFILE_AGE=$(( $(date +%s ) - $(stat  $LOCKFILE -c %Y) )) 
        echo LOCKFILE_AGE=$LOCKFILE_AGE
    fi

    if [[ -n $LOCKFILE_AGE ]] && [[ $LOCKFILE_AGE -lt  10 ]]
    then    echo was switched VERY recently, noop
    else

    set > $LOCKFILE

    CMDS=(
        "usb_modeswitch -b $BUSNUM -g $DEVNUM -v $ID_VENDOR_ID -p $ID_MODEL_ID  -W -R  -w 400 "
        "usb_modeswitch -b $BUSNUM -g $DEVNUM -v $ID_VENDOR_ID -p $ID_MODEL_ID  -W -R "
    )

    i=0

    for CMD in "${CMDS[@]}"
    do
        i=$(($i+1))
        echo "=====STEP$i, run: $CMD"
        $CMD
    done
    fi

    ;;
ff)
    echo Serial Port
    ;;
*)
    echo Unknown mode
    ;;
esac

} | logger -t BROVI

exit 0

and UDEV script /etc/udev/rules.d/40-huawei.rules

ACTION!="add", GOTO="modeswitch_rules_end"
SUBSYSTEM!="usb", GOTO="modeswitch_rules_end"

# All known install partitions are on interface 0
ATTRS{bInterfaceNumber}!="00", GOTO="modeswitch_rules_end"

GOTO="modeswitch_rules_begin"

LABEL="modeswitch_rules_begin"
# Huawei E3372-325
ATTR{idVendor}=="3566", ATTR{idProduct}=="2001", RUN+="/usr/local/bin/brovi_switch %k %p"

LABEL="modeswitch_rules_end"

Serial (COM port) to USB cable for old APC UPS

Firstly find and buy cable on aliexpress by keywords «APC Smart UPS DB9, CP2102, USB RS232, serial 9 D-Sub, cable 940-0024C, Windows 7/8/10, Mac, Linux».

Continue reading

Debug Angular application in VSCode and Chromium

If you want debug Angular application in VSCode and Chromium in Linux that you should’t install extensions for that! You need add only one file launch.json in your project with this configuration:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Launch Chrome",
      "request": "launch",
      "type": "chrome",
      "url": "http://localhost:4200/#",
      "webRoot": "${workspaceFolder}",
      "runtimeExecutable": "/usr/bin/chromium",
      "runtimeArgs": [
        "http://localhost:4200",
        "--new-window",
        "-user-data-dir=${workspaceFolder}/DevProfile",
        "--remote-debugging-port=9222",
        "--disable-background-networking"
      ]
    }
  ]
}

Important notes

  1. check path to chromium binary file, for me it’s «/usr/bin/chromium».
  2. maybe you don’t need create user-data-dir for debug action.
  3. if you see error «unverified breakpoint» in VSCode that meen you need check path url and webRoot fields in your launch.json.

Bash scripts with NodeJS

Use Google’s package ZX for bash scripts on NodeJS: github and npm package.

Example:

#!/usr/bin/env zx

await $`cat package.json | grep name`

let branch = await $`git branch --show-current`
await $`dep deploy --branch=${branch}`

await Promise.all([
  $`sleep 1; echo 1`,
  $`sleep 2; echo 2`,
  $`sleep 3; echo 3`,
])

let name = 'foo bar'
await $`mkdir /tmp/${name}`

ImageMagick PDF and JPG useful examples

ImageMagick convert PDF to JPG

Crop, rotate and set jpg quality on multipage PDF to JPG convert:

convert -density 150 -resize 968x -gravity NorthEast -extent 968x692 -rotate "-90" 1.pdf -quality 90 1.jpg

 

ImageMagick PDF to JPG sometimes results in black background

Need remove alpha in PDF:

convert -density 150 -resize 1000x -fill white -alpha remove *.pdf -quality 90 1.jpg

 

Bash script with ImageMagick that resize and change qulity a lof of images

#!/bin/bash

if [ -d photos ]; then
	rm -rf photos
fi

mkdir photos

for img in ./*
do
	filename=$(basename "$img")
	filename="${filename%.*}"
	
	convert "$img" -auto-orient -resize 1000x -quality 85% "photos/$filename.jpg"
done;

Ventoy is tool to create bootable USB drive for ISO/WIM/IMG/VHD(x)/EFI files

  • Ventoy is an open source tool to create bootable USB drive for ISO/WIM/IMG/VHD(x)/EFI files.
  • With ventoy, you don’t need to format the disk over and over, you just need to copy the ISO/WIM/IMG/VHD(x)/EFI files to the USB drive and boot them directly.
  • You can copy many files at a time and ventoy will give you a boot menu to select them.
  • x86 Legacy BIOS, IA32 UEFI, x86_64 UEFI, ARM64 UEFI and MIPS64EL UEFI are supported in the same way.
  • Most type of OS supported (Windows/WinPE/Linux/ChromeOS/Unix/VMware/Xen…).

Ventoy site

ventoy

ventoy