Tag Archives: Debian

Static IP with NetworkManager

Couple of days ago I had to configure a static IP on the Orange PI wifi interface. Had to use cli, since it is running as a server and there’s no need for a graphical interface. Below is the bash script I made:

#!/bin/bash

CONN="conn_name" # Enter connection name
SSID="myessid" # Define WIFI SSID
IP="192.168.1.15/24" # Enter IP, example "192.168.0.100/24"
GW="192.168.1.1" # Enter gateway
DNS="1.1.1.1,9.9.9.9" # Define DNS servers

nmcli dev wifi list
echo "Adding wifi ${CONN} to SSID ${SSID}."
nmcli connection add type wifi con-name ${CONN} ifname wlan0 ssid ${SSID}
echo "Configuring ${CONN} IP, GW and DNS."
nmcli connection modify ${CONN} ipv4.method manual ipv4.addresses ${IP} ipv4.gateway ${GW} ipv4.dns ${DNS}
echo "Configuring wifi security."
nmcli connection modify ${CONN} wifi-sec.key-mgmt wpa-psk
read -s -p "Enter wifi password: " PASSWORD
nmcli connection modify ${CONN} wifi-sec.psk  ${PASSWORD}
echo "Bringing up connection ${CONN}."
nmcli connection up ${CONN} 

Here are some resources I used:

Debian Wifi HowTo

Debian NetworkManager

networking with nmcli

LeetCode problem 167

Back online after quite some time. Lately I’ve been playing with leetcode, so below is solution to problem 167. This problem is an easy one and no complex structures are needed in order to solve it.

#!/usr/bin/env python

''' LeetCode problem 167 
Given a 1-indexed array of integers numbers that is already sorted in non-decreasing order, 
find two numbers such that they add up to a specific target number. 
Let these two numbers be numbers[index1] and numbers[index2] where 1 <= first < second <= numbers.length.
2 <= numbers.length <= 3 * 104
-1000 <= numbers[i] <= 1000
numbers is sorted in non-decreasing order.
-1000 <= target <= 1000
The tests are generated such that there is exactly one solution. '''

def twoSum(numbers, target):
	for i in numbers:
		if (target - i) in numbers[numbers.index(i)+1:]:
			return [numbers.index(i), numbers.index(i) + numbers[numbers.index(i)+1:].index(target - i)+1]


#twoSum([-5, -3, -1, 0, 10], -1)
print(f"{twoSum([-5, -3, -1, 0, 10], -1)}")
#twoSum([2, 7, 11, 15], 9)
print(f"{twoSum([2,7,11,15], 9)}")
#twoSum([2, 3, 4], 6)
print(f"{twoSum([2, 3, 4], 6)}")
#twoSum([5, 25, 75], 100)
print(f"{twoSum([5, 25,75], 100)}")
#twoSum([0, 0, 3, 4], 0)
print(f"{twoSum([0, 0, 3, 4], 0)}")

I'll try to post more often from now on. I'll try to make it at least once a week.

Resize sdcard with parted

So I had to reinstall Debian in the sdcard of my Orange Pi Lite. Thing is original image / fs is only 4Gb, which on a 64Gb sdcard leaves 60Gb unused.

Here is where parted comes to the rescue. Easier than fdisk for me. Below example extends ext4 partition to 62Gb and creates a 2Gb swap partition.

sudo parted  /dev/mmcblk0 
GNU Parted 3.2 
Using /dev/mmcblk0 
Welcome to GNU Parted! Type 'help' to view a list of commands. (parted) print
Model: SD BC2QT (sd/mmc) 
Disk /dev/mmcblk0: 64,0GB 
Sector size (logical/physical): 512B/512B 
Partition Table: msdos 
Disk Flags:  

Number  Start   End     Size    Type     File system  Flags  
1      21,0MB  73,4MB  52,4MB  primary  fat16        lba  
2      73,4MB  3743MB  3670MB  primary  ext4 

(parted) resizepart
Partition number? 2
End?  [3743MB]? 62000MB
(parted) print
Model: SD BC2QT (sd/mmc)
Disk /dev/mmcblk0: 64,0GB 
Sector size (logical/physical): 512B/512B 
Partition Table: msdos 
Disk Flags:  

Number  Start   End     Size    Type     File system  Flags  
1      21,0MB  73,4MB  52,4MB  primary  fat16        lba  
2      73,4MB  62,0GB  61,9GB  primary  ext4 

(parted) mkpart                                                            Partition type?  primary/extended? primary
File system type?  [ext2]? linux-swap
Start? 62.0GB
End? 64.0GB
(parted) print
Model: SD BC2QT (sd/mmc)
Disk /dev/mmcblk0: 64,0GB 
Sector size (logical/physical): 512B/512B 
Partition Table: msdos 
Disk Flags:  

Number  Start   End     Size    Type     File system     Flags  
1      21,0MB  73,4MB  52,4MB  primary  fat16           lba  
2      73,4MB  62,0GB  61,9GB  primary  ext4  
3      62,0GB  64,0GB  2022MB  primary  linux-swap(v1)  lba 
(parted)  
(parted) quit 
Information: You may need to update /etc/fstab. 

Continue reading

OpenDKIM in Debian

Lately I’ve been playing with postfix and ways to validate my mail. That’s how I reached DKIM records. Something like ssh keys (a public and private key) but for mail. Installation in Debian GNU/Linux is pretty simple via apt-get as usual, we need to install opendkim and opendkim-tools.

dpkg -l | grep dkim
ii  libmail-dkim-perl              0.40-1                           all          cryptographically identify the sender of email - perl library
ii  libopendkim9                   2.9.2-2+deb8u1                   amd64        Library for signing and verifying DomainKeys Identified Mail signatures
ii  opendkim                       2.9.2-2+deb8u1                   amd64        Milter implementation of DomainKeys Identified Mail
ii  opendkim-tools                 2.9.2-2+deb8u1                   amd64        Set of command line tools for OpenDKIM

We need to open a port for opendkim (8891 in my case), we need to edit /etc/default/opendkim in order to do this as below.

grep -v "^#" /etc/default/opendkim 
SOCKET="inet:8891@localhost" # listen on loopback on port 8891

Continue reading

Docker in DietPi

So I was trying to install docker in my raspberry pi with DietPi and initially installed it via repo/aptitude, but that version is pretty old and not supported anymore.

dpkg -l | grep dock
ii  docker.io                      1.3.3~dfsg1-2              armhf        Linux container runtime 
sudo docker version 
Client version: 1.3.3
Client API version: 1.15
Go version (client): go1.3.2
Git commit (client): d344625
OS/Arch (client): linux/arm
Server version: 1.3.3
Server API version: 1.15
Go version (server): go1.3.2
Git commit (server): d344625

Continue reading