Listing posts

Displaying posts 1 - 5 of 181 in total
Strip video metadata
mouse 82 · person cloud · link
Last update
2019-01-15
2019
01-15
« — »
1
2
3
4
5
6
7
8
9
10
11
12
13
# print metadata
exiftool  in.mp4 | grep -i title
mediainfo in.mp4 # another tool

# remove metadata with ffmpeg/avconv
ffmpeg -i in.mp4 -map_metadata -1 -c:v copy -c:a copy out.mp4

# remove tags from MKV files:
mkvpropedit in.mkv --tags all: --delete title

# massive operations: detect and convert (fish shell)
for i in *.{mp4,avi,mkv}; echo -n "$i -- "; exiftool $i | grep -i title; or echo; end
for i in *.{mp4,avi}; ffmpeg -i $i -map_metadata -1 -c:v copy -c:a copy _$i; and mv _$i $i; end

Source: Superuser


~~~ * ~~~

PdfTk | Extract PDF page range
mouse 301 · person cloud · link
Last update
2019-01-15
2019
01-15
« — »
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# extract pages from 1 to 10:
pdftk in.pdf cat 1-10 output out.pdf

# extract range 1-10 and pages 15, 20:
pdftk in.pdf cat 1-10 15 20 output out.pdf

# extract pages from page 2 till the end:
pdftk in.pdf cat 2-end output out.pdf

# extract all pages except the last one
pdftk in.pdf cat ~end output out.pdf

# extract all pages except the last 3 (reverse range)
pdftk in.pdf cat ~r3-r1 output out.pdf

# extract range from multiple documents:
pdftk A=in1.pdf B=in2.pdf cat A1-10 B1-3 output out.pdf

Source: PDFtk homepage


~~~ * ~~~

Remove NOOBS from RaspberryPi sdcard
mouse 6 · person cloud · link
Last update
2019-01-12
2019
01-12
« — »

After installing NOOBS you will have this sdcard partition table (eg. 16GB sdcard):

1
root# sfdisk -d /dev/mmcblk0
1
2
3
4
5
6
7
8
9
10
label: dos
label-id: 0x00084f9c
device: /dev/mmcblk0
unit: sectors

/dev/mmcblk0p1 : start=        8192, size=     2280871, type=e
/dev/mmcblk0p2 : start=     2289063, size=    28827225, type=5
/dev/mmcblk0p5 : start=     2293760, size=       65534, type=83
/dev/mmcblk0p6 : start=     2359296, size=      129024, type=c
/dev/mmcblk0p7 : start=     2490368, size=    28625920, type=83

and we have to create another one like this (eg. 32GB sdcard):

1
2
3
4
5
6
7
label: dos
label-id: 0x00084f9c
device: /dev/sdc
unit: sectors

/dev/sdc1 : start=        8192, size=       85405, type=c
/dev/sdc2 : start=       94208, size=    62239744, type=83

save the last output to a file sdcard.ptable and:

1
2
3
4
5
6
7
8
9
10
11
12
13
# write partition table
sfdisk /dev/sdc < sdcard.ptable

# format partitions
mkfs.vfat -v /dev/sdc1
mkfs.ext4 -m 1 -b 4096 -O ^metadata_csum -v /dev/sdc2

mkdir src dst

# copy partition 1 data
mount /dev/mmcblk0p1 src
mount /dev/sdc1      dst
rsync -avihh --stats --progress --inplace --delete --delete-before --delete-excluded src/ dst/

edit cmdline.txt and set the correct boot partition with root=PARTUUID=00084f9c-02, then:

1
2
3
4
5
6
7
umount src dst

# copy partition 2 data
mount /dev/mmcblk0p1 src
mount /dev/sdc1      dst
rsync -avihh --stats --progress --inplace --delete --delete-before --delete-excluded src/ dst/
umount src dst

and edit etc/fstab with the correct partition labels :

1
2
PARTUUID=00084f9c-01  /boot           vfat    defaults          0       2
PARTUUID=00084f9c-02  /               ext4    defaults,noatime  0       1

Note: Alternatively you can also update the NOOBS installer.


Source: Remove NOOBS and migrate Raspbian to new microSD card, Raspberry Pi 3 Model B+ Will Not Boot!,


~~~ * ~~~

Setup an UPS monitor
mouse 427 · person cloud · link
Last update
2019-01-12
2019
01-12
«NUT - Network UPS Tools»
1
apt-get install nut # install server

Set MODE=standalone in /etc/nut/nut.conf.

Append the user definition in /etc/nut/upsd.users:

1
2
3
4
[monuser]
  password = ApAssWorD
  allowfrom = localhost
  upsmon master

If you use an USB to serial converter, find it via lsusb:

1
lsusb | grep Serial # Bus 001 Device 009: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port

then add a udev rule to fix its device name:

1
2
# /etc/udev/rules.d/10-local.rules
ACTION=="add", KERNEL=="ttyUSB[0-9]*", SUBSYSTEMS=="usb", ATTRS{idVendor}=="067b", ATTRS{idProduct}=="2303", SYMLINK+="ttyUSB_UPS"

Append the UPS definition in /etc/nut/ups.conf (mine is a powercom model):

1
2
3
4
5
6
[myups]
  driver = powercom
  port = /dev/ttyUSB_UPS
  desc = "Main supply"
  loadPercentage = {6.1343,-0.3808,1.075,0.1811}
  batteryPercentage = {5.0000,0.3268,-825.00,0.46511,0}

Configure the monitor in /etc/nut/upsmon.conf:

1
2
3
4
5
6
7
8
9
10
11
12
13
MONITOR myups@localhost 1 monuser ApAssWorD master

# setup a custom script to notify you
NOTIFYCMD /opt/ups/nut_notify_cmd.sh

# customize notification messages
NOTIFYMSG ONBATT "Power failure! UPS %s is on battery!"
NOTIFYMSG SHUTDOWN "UPS %s is low on battery! Shutting down the system..."

# enable some logging
NOTIFYFLAG ONLINE SYSLOG+EXEC
NOTIFYFLAG ONBATT SYSLOG+EXEC
NOTIFYFLAG SHUTDOWN SYSLOG+WALL

Add the nut user to dialout group:

1
useradd -G dialout nut

Restart the services and test the ups:

1
2
3
4
5
6
systemctl restart nut-driver
systemctl restart nut-server
systemctl restart nut-monitor

upsc -l     # list all monitored UPSes
upsc myups  # show UPS details and status

Note: To cleanly unmount VeraCrypt volumes you can use this NOTIFYCMD script:

1
2
3
4
5
6
7
8
9
10
11
12
13
#!/bin/bash

# /opt/ups/nut_notify_cmd.sh - nut NOTIFYCMD script

# put in /etc/sudoers.d/local:
# nut raoul = (root)  NOPASSWD: /sbin/shutdown, /opt/systemd-units/vc-mounter.rb

if [ "$NOTIFYTYPE" = "ONBATT" ]; then
  /opt/bin/shutdown -h 600 &
elif [ "$NOTIFYTYPE" = "ONLINE" ]; then
  sleep 3 # wait for first command to start
  /opt/bin/shutdown -c     &
fi

that uses this useful shutdown script:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/ruby

$VERBOSE = nil

# /opt/bin/shutdown - emulate shutdown command and unmount VeraCrypt volumes

require 'optparse'
require 'shellwords'

opts = {}
OptionParser.new{|o|
  o.banner = "Usage: #{File.basename __FILE__} [options]"

  o.on('-r', '--reboot   [N]', Float, 'Reboot   after N seconds (default=0)') do |n|
    opts.merge! action: :reboot, delay: n.to_f
  end

  o.on('-h', '--poweroff [N]', Float, 'Poweroff after N seconds (default=0)') do |n|
    opts.merge! action: :shutdown, delay: n.to_f
  end

  o.on('-c', '--cancel', 'Cancel a pending operation') do |enabled|
    opts.merge! action: :cancel
  end

  opts.merge! help: o.to_s
}.parse!

case opts[:action]
  when :cancel
    `pgrep -fl vc-mounter.rb`
    if $?.to_i == 0
      puts 'aborted'
      exit
    end
    # kill all but yourself
    pids = `pgrep -f ruby.*shutdown`.split("\n").map(&:to_i) - [Process.pid]
    pids.each{|pid| system "kill #{pid}" }
  when :reboot, :shutdown
    sleep opts[:delay]
    `sudo swapon | grep " file " | cut -f 1 -d " "`.strip.split("\n").
      each{|f| system "sudo swapoff #{f.shellescape}" }
    system 'sudo /opt/systemd-units/vc-mounter.rb try-umount'
    system "sudo /sbin/shutdown -#{opts[:action] == :reboot ? :r : :h} 0 &"
  else
    puts opts[:help]
end

~~~ * ~~~

youtube-dl usage
mouse 9 · person cloud · link
Last update
2019-01-11
2019
01-11
« — »
1
2
3
4
5
6
7
8
9
10
# to parse a playlist use "--yes-playlist url" or simply "playlist_id"

# downoload a playlist audio only
youtube-dl -i -o "%(title)s.%(ext)s" \
  -f bestaudio --extract-audio --audio-format mp3 --audio-quality 2 \
  <playlist_id>

# download a specific combination of audio and video in a single file
youtube-dl -F <url> # detect desired format codes
youtube-dl --merge-output-format mkv -f <code1>+<code2> <url>

Source: stackoverflow.com, askubuntu.com