Mastodon

Saturday, 23 December 2017

Spotweb on Bionic Beaver

Wanted to get Spotweb running on a local machine to do some newsgroup indexing, lots of instructions out there for Raspberry Pis and older versions of Ubuntu with php 5. I've decided to go and install it on a virtual server running Bionic Beaver, it was a lot easier than I expected.

Start off with installing the OS and then updating it.


sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get dist-upgrade -y
sudo apt-get autoremove -y
sudo shutdown -r now

Then install the required apps:

sudo apt-get install mysql-server php-mysql php-curl php-gd php-cli nginx openssl php-fpm git zip mc php-mbstring php-xml -y


Change a couple of files:

sudo nano /etc/php/7.1/fpm/php.ini

Change these lines

date.timezone = Europe/Copenhagen
memory_limit = 512M


And do the same here:

sudo nano /etc/php5/cli/php.ini




Make the webserver config file:

sudo nano /etc/nginx/sites-available/spotweb

Copy and paste this into the file:

server {
listen 80;
server_name htpcguides.crabdance.com, 192.168.40.120;
root /var/www;
index index.html index.htm index.php;

location /spotweb {


        satisfy any;


        if ($uri !~ "api/"){

                rewrite /api/?$ /spotweb/index.php?page=newznabapi last;
        }
location ~ \.php$ {
                try_files $uri =404;
                include fastcgi_params;
                fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
                fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
}
}
}

Save it and then close nano


Activate the configuration

sudo -i

unlink /etc/nginx/sites-enabled/default

ln -s /etc/nginx/sites-available/spotweb /etc/nginx/sites-enabled/spotweb


Install Spotweb:


git clone https://github.com/spotweb/spotweb /var/www/spotweb

Sort out the permissions:


chown -R www-data:www-data /var/www/spotweb

Create the database, replace the word password with your password but leave the ' ' in place:
mysql -u root -p

CREATE USER spotwebuser@localhost IDENTIFIED BY 'password';
CREATE DATABASE spotwebdb;
GRANT ALL PRIVILEGES ON spotwebdb.* TO spotwebuser@localhost IDENTIFIED BY 'password';
FLUSH PRIVILEGES;


Go for a reboot


sudo shutdown -r now

And now finish the configuration off with your browser.


Go to http://ip.address/spotweb/install.php

Do an initial download and then setup a cron job to run:

php retrieve.php from the /var/www/spotweb directory.


Friday, 22 December 2017

Nextcloud install, the easy way.

Here's an easy way to setup a NextCloud server, a bit less customisable than installing it the manual way.

In the past, I've messed round with installing, SQL, Apache and so on, I thought I'd give the Ubuntu snap package a go.

I've run up Ubuntu 20.04 server, installed SSH onto it so I can manage it from command line and next it was time to install NextCloud.

sudo snap install nextcloud

That's it, it's done and installed, just a few more things to get it working properly and securely with ssl enabled.

Adjust the memory limits with:

sudo snap set nextcloud php.memory-limit=-1

Tell it which ports to listen to with:

sudo snap set nextcloud ports.http=80 ports.https=443

Restart Apache with:

systemctl restart snap.nextcloud.apache

Configure https and install lets encrypt with:

sudo nextcloud.enable-https lets-encrypt

Finish off the configuration by pointing your web browser at the dynamic domain you have set up for it.

https://domaine.name or https://ipaddress

The final configuration is done via web browser.

It really was that easy

Friday, 12 May 2017

Shell Script stuff in Linux

I've wanted to make up a simple script that runs an update on my desktop and then either shuts down, reboots or continues depending on what parameters I add to the end.

Something like;

update reboot

update shutdown

or just update to install the updates and do nothing else.

I managed this with good old DOS many years ago and started to look up how to do this with Linux, I have to say that the vast majority of instructions are based up using foo and bar and are not the easiest things in the world to understand, here's one of the easier examples:

 $ mytest foo bar quux
   There are 3 arguments to mytest: foo bar quux
   first argument: foo
   second argument: bar
   third argument: quux
   here they are again: foo bar quux

I really can't work out how that helps me but it gave me a starting point.

So in plain language here's what I want to do, I've created a script with:

sudo nano /bin/mtupdate

The main part of the script checks for updates and installs the updates:

sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get dist-upgrade -y
sudo apt-get autoremove -y

It then goes onto check what additional parameters have been passed and this is the bit that caused me heartache.

So if I run mtupdate shutdown it does the above and then this bit

# checking for shutdown parameter
if [ "$1" = "shutdown" ]; then
echo "Shutting Down in 10 seconds"
# gives you a chance to change your mind
echo "Press CTRl+C to abort"
sleep 10
echo "Shutting Down"
# shuts down
shutdown -h now
else
if

Then it became harder as I wanted to check for a reboot parameter, to get it all in I had to do the following;

# checks for reboot parameter
if [ "$1" = "reboot" ]; then
echo "Rebooting in 10 seconds"
echo "Press CTRl+C to abort"
sleep 10
echo "Rebooting"
shutdown -r now
else

# checks for shut down parameter
if [ "$1" = "shutdown" ]; then
echo "Shutting Down in 10 seconds"
echo "Press CTRl+C to abort"
sleep 10
echo "Shutting Down"
shutdown -h now

else
# no parameters
clear
echo .
echo.

echo "Updates Completed, please reboot as soon as you can"

fi fi

You have to have a fi at the end for every if in the list


The end product looks like this:

# mtupdate reboot or shutdown
echo "Running Update"
apt-get update
echo "Running Upgrade"
apt-get upgrade -y
echo "Running Dist Upgrade"
apt-get dist-upgrade -y
echo "Running Cleanup"
apt-get autoremove -y
apt-get install -fy

# checking for reboot parameter
if [ "$1" = "reboot" ]; then
echo "Rebooting in 10 seconds"
echo "Press CTRl+C to abort"
sleep 10
echo "Rebooting"
shutdown -r now
else

# checking for shutdown parameter
if [ "$1" = "shutdown" ]; then
echo "Shutting Down in 10 seconds"
echo "Press CTRl+C to abort"
sleep 10
echo "Shutting Down"
shutdown -h now

else
# no parameters entered
clear
echo .
echo .
echo "Updates Completed, please reboot as soon as you can"
fi fi

To finish it off I ran 

sudo chmod +x /bin/mtupdate 

To make it executable

My suggestion to the people that write help stuff is to use a proper example, don't use foo bar quux as this means bugger all to people like me.

My next bit of scripting is going to revolve around taking two parameters and running something based on them, such as

mtbackup source destination

Where mtbackup runs something like rsync or cp or mv

I'll come to that next time round