Linux Setup: Difference between revisions

From bibbleWiki
Jump to navigation Jump to search
No edit summary
Line 2: Line 2:
Get list of package installd
Get list of package installd
  $ apt list --installed > install.list
  $ apt list --installed > install.list
Then translate it into apt understandable format:
Then translate it into apt understandable format:
  $ sed -r  's/ \[.*?\]//g' install.list | sed -r 's/(^.*?)\/.*?[ ](.*?)[ ](.*?)$/\1:\3=\2/g' > install.list.to.dl
  $ sed -r  's/ \[.*?\]//g' install.list | sed -r 's/(^.*?)\/.*?[ ](.*?)[ ](.*?)$/\1:\3=\2/g' > install.list.to.dl
Then download the current packages versions:
Then download the current packages versions:
  $ xargs apt download < install.list.to.dl
  $ xargs apt download < install.list.to.dl
You would need to create a Packages.gz file in order to add this folder as a source for apt. E.g.
You would need to create a Packages.gz file in order to add this folder as a source for apt. E.g.
  $ cd ~/deb_server/debs/
  $ cd ~/deb_server/debs/
  $ dpkg-scanpackages -m . /dev/null | gzip -9c >  Packages.gz   
  $ dpkg-scanpackages -m . /dev/null | gzip -9c >  Packages.gz   
EDIT: path for dpkg-scanpackages must be relative, otherwise this will break the download process later
EDIT: path for dpkg-scanpackages must be relative, otherwise this will break the download process later
(-m allows you to have multiple versions, if you want the most recent version, remove the -m)
(-m allows you to have multiple versions, if you want the most recent version, remove the -m)
Now you have to bring up a file server for example apache2 and configure it to index files.
Now you have to bring up a file server for example apache2 and configure it to index files.
  /etc/apache2/sites-enabled/000-debserver.conf
  /etc/apache2/sites-enabled/000-debserver.conf
Containing:
Containing:
  DocumentRoot /var/www
  DocumentRoot /var/www
   <Directory /var/www/>
   <Directory /var/www/>
Line 27: Line 19:
     Require all granted
     Require all granted
   </Directory>
   </Directory>
And finally you need to symlink the deb folder to /var/www. (Or configure the server to the current deb download location) e.g.
And finally you need to symlink the deb folder to /var/www. (Or configure the server to the current deb download location) e.g.
  $ ln -s ~/deb_server/debs/ /var/www/repo
  $ ln -s ~/deb_server/debs/ /var/www/repo
The last bit is to add the server machine as the only source for apt updates on each target machine.
The last bit is to add the server machine as the only source for apt updates on each target machine.
  $ deb [trusted=yes] http://deb_server_ip/repo /
  $ deb [trusted=yes] http://deb_server_ip/repo /
If you want to update the packages, you need to re-run apt download of the list, but without the version.
If you want to update the packages, you need to re-run apt download of the list, but without the version.
  $ sed -r  's/ \[.*?\]//g' install.list | sed -r 's/(^.*?)\/.*?[ ](.*?)[ ](.*?)$/\1:\3/g' > install.list.for.update
  $ sed -r  's/ \[.*?\]//g' install.list | sed -r 's/(^.*?)\/.*?[ ](.*?)[ ](.*?)$/\1:\3/g' > install.list.for.update
  $ apt update && xargs apt download < install.list.for.update
  $ apt update && xargs apt download < install.list.for.update


== Setting up Iot Edge on 19.04 ==
== Setting up Iot Edge on 19.04 ==

Revision as of 05:12, 7 September 2019

Setting up repo for current packages on ubuntu

Get list of package installd

$ apt list --installed > install.list

Then translate it into apt understandable format:

$ sed -r  's/ \[.*?\]//g' install.list | sed -r 's/(^.*?)\/.*?[ ](.*?)[ ](.*?)$/\1:\3=\2/g' > install.list.to.dl

Then download the current packages versions:

$ xargs apt download < install.list.to.dl

You would need to create a Packages.gz file in order to add this folder as a source for apt. E.g.

$ cd ~/deb_server/debs/
$ dpkg-scanpackages -m . /dev/null | gzip -9c >  Packages.gz  

EDIT: path for dpkg-scanpackages must be relative, otherwise this will break the download process later (-m allows you to have multiple versions, if you want the most recent version, remove the -m) Now you have to bring up a file server for example apache2 and configure it to index files.

/etc/apache2/sites-enabled/000-debserver.conf

Containing:

DocumentRoot /var/www
  <Directory /var/www/>
    Options +Indexes +FollowSymLinks
    Require all granted
  </Directory>

And finally you need to symlink the deb folder to /var/www. (Or configure the server to the current deb download location) e.g.

$ ln -s ~/deb_server/debs/ /var/www/repo

The last bit is to add the server machine as the only source for apt updates on each target machine.

$ deb [trusted=yes] http://deb_server_ip/repo /

If you want to update the packages, you need to re-run apt download of the list, but without the version.

$ sed -r  's/ \[.*?\]//g' install.list | sed -r 's/(^.*?)\/.*?[ ](.*?)[ ](.*?)$/\1:\3/g' > install.list.for.update
$ apt update && xargs apt download < install.list.for.update

Setting up Iot Edge on 19.04

Not yet released so here is how to do it

Install docker

wget https://packages.microsoft.com/ubuntu/18.04/multiarch/prod/pool/main/i/iotedge/iotedge_1.0.8-2_amd64.deb
wget https://packages.microsoft.com/ubuntu/18.04/multiarch/prod/pool/main/libi/libiothsm-std/libiothsm-std_1.0.8-1_amd64.deb
wget http://archive.ubuntu.com/ubuntu/pool/main/o/openssl1.0/libssl1.0.0_1.0.2n-1ubuntu5.3_amd64.deb

Fixing ubuntu 19.04 mouse

Install kernel 5.2.x

Cerificates

apt-get install software-properties-common python-software-properties
add-apt-repository ppa:certbot/certbot
apt-get update
apt-get install python-certbot-apache 
certbot -n  --agree-tos --standalone certonly -d imap.bibble.co.nz
certbot -n  --agree-tos --standalone certonly -d www.bibble.co.nz

Building r8168

This is not necessary as you can use the command

apt-get install r8168-dkms

Updating DNS

This script runs in crontab once every 15 minutes

#!/bin/bash
lynx -source -auth=user_xxx:pass_xxxx 'http://dynamic.zoneedit.com/auth/dynamic.html?host=bibble.co.nz'
lynx -source -auth=user_xxx:pass_xxxx 'http://dynamic.zoneedit.com/auth/dynamic.html?host=denise.bibble.co.nz'
lynx -source -auth=user_xxx:pass_xxxx 'http://dynamic.zoneedit.com/auth/dynamic.html?host=www.bibble.co.nz' 
lynx -source -auth=user_xxx:pass_xxxx 'http://dynamic.zoneedit.com/auth/dynamic.html?host=sync.bibble.co.nz'

Backup MySQL

I use the following script to back up the databases

#!/bin/sh

myBackupFolder="/home/iwiseman/backups"
myBackupLogFileName="$myBackupFolder/"backup_log_"$(date +'%Y_%m')".txt

DoBackup()
{
        myDatabaseName=$1

        myCurrentDateTime="$(date +'%d_%m_%Y_%H_%M_%S')"
        myBackupFileName="db_backup_${myDatabaseName}_${myCurrentDateTime}".gz
        myFullyQualifieldBackupFileName="$myBackupFolder/$myBackupFileName"

        echo "mysqldump of $myDatabaseName started at $(date +'%d-%m-%Y %H:%M:%S')" >> "$myBackupLogFileName"
        mysqldump --user=root --password=xxxx --default-character-set=utf8 --single-transaction $myDatabaseName  | gzip > "$myFullyQualifieldBackupFileName"
        echo "mysqldump of $myDatabaseName finished at $(date +'%d-%m-%Y %H:%M:%S')" >> "$myBackupLogFileName"
 
        chown iwiseman "$myFullyQualifieldBackupFileName"
        chown iwiseman "$myBackupLogFileName"
        echo "file permission changed" >> "$myBackupLogFileName"
 
        find "$myBackupFolder" -name db_backup_* -mtime +8 -exec rm {} \;
        echo "old files deleted" >> "$myBackupLogFileName"
 
        echo "operation finished at $(date +'%d-%m-%Y %H:%M:%S')" >> "$myBackupLogFileName"
        echo "*****************" >> "$myBackupLogFileName"
}


DoBackup mail
DoBackup wordpress424

exit 0

Fix Playstation

The works when enp1s0 is the interface of the second NIC and enp2s0 is the main NIC.

To fix the playstation create the following script

#!/bin/bash
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
iptables -A FORWARD -i enp1s0 -o enp2s0 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i enp2s0 -o enp1s0 -j ACCEPT

Put this into /etc/rc.local e.g

#!/bin/bash
/usr/local/bin/fix_playstation.sh