Creating a service to run a systemd-nspawn server
By admin | January 28, 2021
debootstrap –include=systemd-container –components=main,universe focal myContainer
http://nova.clouds.archive.ubuntu.com/ubuntu/
https://bbs.archlinux.org/viewtopic.php?id=232804
Edit /usr/lib/systemd/system/systemd-nspawn@.service
ExecStart= -> remove -U
Add
[Exec]
PrivateUsers=off
https://wiki.debian.org/nspawn#Booting_a_Container
sudo systemctl daemon-reload
sudo systemctl restart systemd-nspawn@myContainer
Topics: Linux | No Comments »
Git refuses to discover new remote branches
By admin | January 23, 2021
In addition to the excellent suggestions at https://stackoverflow.com/questions/1783405/how-do-i-check-out-a-remote-git-branch, take a look in .git/config and make sure fetch is specified to only fetch the master branch:
[remote "origin"] url = git@github.com:example/coolproject.git fetch = +refs/heads/master:refs/remotes/origin/master # bad
You’ll want to change the fetch line to fetch all branches instead:
[remote "origin"] url = git@github.com:example/coolproject.git fetch = +refs/heads/*:refs/remotes/origin/*
Topics: Linux | 1 Comment »
ImageMagick snippet: batch crop, dither, and guillotine
By admin | November 12, 2020
# Create output dirs mkdir -p cropped dithered output rm cropped/*.png dithered/*.png output/*.png # Crop (3000x2000 at position 200, 200) mogrify -crop 3000x2000+200+200 -path ./cropped *.png # Dither (to indexed colours) mogrify +dither -colors 4 -path ./dithered cropped/*.png # Guillotine mogrify -crop 2x1@ +repage -path ./output dithered/*.png
Topics: Linux | No Comments »
Concatenating PDFs while padding/extending odd-length PDFs
By admin | October 10, 2020
When concatenating PDFs to consolidate print jobs, it is nice to have single-page or PDFs with odd numbers of pages to not have to share sides with another unrelated document.
There is a short script available at https://unix.stackexchange.com/questions/66418/how-can-i-merge-pdf-files-so-that-each-file-begins-on-an-odd-page-number ; however, it does not appear to be updated for PyPDF2. So here is an update for Python3 and PyPDF2.
Prep:
sudo apt install python3-pypdf2
#!/usr/bin/env python3
# Inspired from https://unix.stackexchange.com/a/66455
import copy
import sys
from PyPDF2 import PdfFileWriter, PdfFileReader
def main():
if len(sys.argv) < 2:
print("No input PDFs specified", file=sys.stderr)
return 1
pdf_writer = PdfFileWriter()
output_page_number = 0
alignment = 2 # to align on even pages
# So we can close the file objects later.
# https://stackoverflow.com/questions/44375872/pypdf2-returning-blank-pdf-after-copy
file_objects = []
for filename in sys.argv[1:]:
# Store the file object for closing
f = open(filename, 'rb')
file_objects.append(f)
# Open the input PDF
pdf_reader = PdfFileReader(f)
# Add input pages
for page in pdf_reader.pages:
pdf_writer.addPage(page)
output_page_number += 1
# Add filler pages
while output_page_number % alignment != 0:
pdf_writer.addBlankPage()
output_page_number += 1
# Write output PDF while input files are still open.
pdf_writer.write(sys.stdout.buffer)
# Close open files.
while len(file_objects) > 0:
file_objects.pop().close()
return 0
sys.exit(main())
Topics: Linux | No Comments »
Scanning with Brother DCP-7065DN in Ubuntu
By admin | September 12, 2020
First, make sure the printer is detected in lsusb:
$ lsusb | grep Brother Bus 001 Device 011: ID 04f9:024a Brother Industries, Ltd
Then, either add a udev rule to ensure that we have permission to access it, or use the following one-time hack:
sudo chmod 777 /dev/bus/usb/001/011
Now, install the correct driver for the printer from support.brother.com. For the DCP-7065DN on Ubuntu 64-bit, the following package worked:
5937473842d95571b0d8ff50d6095198 brscan4-0.4.9-1.amd64.deb
Check that sane-find-scanner can see it:
$ sane-find-scanner # sane-find-scanner will now attempt to detect your scanner. If the # result is different from what you expected, first make sure your # scanner is powered up and properly connected to your computer. # No SCSI scanners found. If you expected something different, make sure that # you have loaded a kernel SCSI driver for your SCSI adapter. found USB scanner (vendor=0x04f9, product=0x024a) at libusb:001:011 # Your USB scanner was (probably) detected. It may or may not be supported by # SANE. Try scanimage -L and read the backend's manpage. # Not checking for parallel port scanners. # Most Scanners connected to the parallel port or other proprietary ports # can't be detected by this program. # You may want to run this program as root to find all devices. Once you # found the scanner devices, be sure to adjust access permissions as # necessary.
Finally, check that scanimage can see it. If this succeeds, then the scanner is operational (and can be used from Simple Scan or any other scan software).
$ scanimage -L device `brother4:bus1;dev4' is a Brother DCP-7065DN USB scanner
Topics: Linux | 1 Comment »
Simple recursive DNS server with Unbound DNS
By admin | July 30, 2020
This is a simple configuration for running a recursive DNS server (passes DNS requests to another server and caches responses) with the Unbound DNS server.
Installation (Ubuntu):
sudo apt-get install -y unbound
Open the config
sudo vim /etc/unbound/unbound.conf
Configuration
Replace 8.8.8.8 below with the desired upstream DNS server.
# The following line includes additional configuration files from the # /etc/unbound/unbound.conf.d directory. #include: "/etc/unbound/unbound.conf.d/*.conf" # NOTE: needed to comment out the above line avoid a "status: SERVFAIL" response server: # Enable verbose debugging messages verbosity: 1000 # Run on all interfaces interface: 0.0.0.0 # Hide the server name and version hide-identity: yes hide-version: yes # Who should be able to query the server access-control: 0.0.0.0/0 allow do-ip4: yes do-ip6: no do-udp: yes # Enable this to support TCP DNS which is required in some applications do-tcp: yes # Allow forwarding to another 127.0.0.0/8 DNS server (e.g. another local dnsmasq or systemd-resolve) do-not-query-localhost: no forward-zone: name: "." # Replace 8.8.8.8 with your desired upstream DNS server # You can have multiple forward-addr lines forward-addr: 8.8.8.8@53
Starting the server
sudo systemctl restart unbound
Debugging / Troubleshooting
Query the server
dig @your_server_here example.com
Read the DNS server log
sudo systemctl status unbound -n 50
References:
Topics: Linux | 1 Comment »
Generating POT files for WordPress plugins
By admin | July 6, 2020
The easiest non-GUI way appears to be using WP CLI.
Run the following in the plugin folder:
wp i18n make-pot . output.pot
Topics: HTTP (Internet) | No Comments »
Make fails silently
By admin | February 28, 2017
Run make <...> -d &> log.txt
and examine the log. Likely there is some prerequisite which is missing, in the form of “File `foo’ does not exist.”
Topics: Linux | 1 Comment »
LaTeX macros ending in numbers
By admin | February 13, 2016
Only letters are directly permitted in macro names, but by using csname to create definitions along with a variable command, we can simulate them.
First, define the macros with numbers using \csname:
\expandafter\def\csname xR1\endcsname{-3} \expandafter\def\csname xR2\endcsname{9}
Now, create a command which takes in one variable argument, and simply expands it to call the appropriate macro (“xR” + variable) defined above.
\newcommand{\xR}[1]{\expandafter\csname xR#1\endcsname}
And to use the macros:
The first is \xR1 and the second is \xR2.
Topics: Linux | No Comments »
Phabricator LDAP (and other) account integration table
By admin | January 17, 2016
phabricator_user.user_externalaccount
See also https://secure.phabricator.com/T4279
For LDAP, the following structure is used:
- id – auto-increment
- phid – random unique id
- userPHID – associated user or NULL
- accountType – “ldap”
- accountDomain – “self”
- accountSecret` – random characters
- accountID – LDAP username
- displayName – NULL
- dateCreated – Unix timestamp
- dateModified – Unix timestamp
- username – registration pre-fill for username
- realName – registration pre-fill for real name
- email – NULL
- emailVerified – 0
- accountURI – NULL
- profileImagePHID – NULL
- properties – “[]”
Topics: PHP | No Comments »