Function to change ownership of the www folder

Just another snippet of code that can be implemented somewhere:

set-perms.sh
#!/bin/bash

# Function to change ownership of the www folder
change_ownership() {
    sudo chown -R "$1":www-data /var/www
    echo "Ownership of the www folder has been set to $1:www-data."
}

# Loop until a valid username is provided
while true; do
    # Prompt the user to enter the desired username
    read -p "Enter the username for permissions: " username

    # Check if the username provided exists
    if id "$username" &>/dev/null; then
        change_ownership "$username"
        break  # Exit the loop if a valid username is provided
    else
        echo "Error: User $username does not exist."
    fi
done

echo "done!"

To make the script executable:

sudo chmod +x set-perms.sh

and run it with

sudo ./set-perms.sh

Loading

Static IP address in Linux (Debian)

You can give your Debian installation a static IP address by following these steps:

1. Determine your network interface name: Use the following command to determine the name of your network interface:

ip addr

This will display information about all of your network interfaces. Look for the interface that you want to configure with a fixed IP address. The interface name will be listed on the left-hand side of the output (e.g. eth0, enp0s3, etc.)

2. Edit the network configuration file: Use a text editor to edit the /etc/network/interfaces file. For example, you can use the nano editor by running the following command:

sudo nano /etc/network/interfaces

3. Configure the network interface: Add the following lines to the file, replacing the interface name and IP address with your own values:

auto <interface-name>
iface <interface-name> inet static
address <ip-address>
netmask <subnet-mask>
gateway <default-gateway>
dns-nameservers <dns-server-ip-address>

For example, if your network interface name is “eth0” and you want to set the IP address to “192.168.0.10”, the subnet mask to “255.255.255.0”, the default gateway to “192.168.0.1”, and the DNS server to “8.8.8.8”, the configuration would look like this:

auto eth0
iface eth0 inet static
address 192.168.0.10
netmask 255.255.255.0
gateway 192.168.0.1
dns-nameservers 8.8.8.8

4. Save and close the file: Press Ctrl+O to save the file, and then press Ctrl+X to close the editor.

5. Restart the networking service: Use the following command to restart the networking service and apply the changes:

sudo systemctl restart networking

After you’ve completed these steps, your Debian installation should have a fixed IP address. You can verify the configuration by using the “ip addr” command again and looking for the interface that you configured.

More info here: https://wiki.debian.org/NetworkConfiguration
Thanks to https://fosstodon.org/@HankB for the tips and better choice of words!

Loading

Permanently switching off the GUI in Debian Linux

* Disable the Display Manager: The Display Manager is the graphical login screen that appears when you start up Debian. You can disable it by stopping the service and preventing it from starting at boot time. Use the following command to stop the service:

sudo systemctl stop display-manager.service

And then disable the service from starting at boot time:

sudo systemctl disable display-manager.service

* Remove the GUI packages: You can remove the GUI packages from your Debian installation by using the following command:

sudo apt-get remove task-gnome-desktop

This will remove the GNOME desktop environment and all its associated packages. If you’re using a different desktop environment, replace “gnome” with the name of your desktop environment.

* Reboot your system: Once you’ve disabled the Display Manager and removed the GUI packages, you’ll need to reboot your system for the changes to take effect. Use the following command to reboot your system:

sudo reboot

After the reboot, your Debian installation should boot into a command-line interface without any GUI.

Keep in mind that disabling the GUI permanently may make some tasks more difficult or time-consuming to perform. It’s recommended to proceed with caution and ensure that you have a backup plan in case you need to re-enable the GUI later.


The following has been suggested by https://fosstodon.org/@HankB :

Or

systemctl set-default multi-user.target

sudo systemctl set-default graphical.target

Loading

Switching off the GUI in Debian

  • Disable the GUI on boot: sudo systemctl set-default multi-user.target
  • Enable the GUI on boot: sudo systemctl set-default graphical.target
  • Disable the GUI temporarily: sudo systemctl isolate multi-user.target
  • Enable the GUI temporarily: sudo systemctl isolate graphical.target

Starting a virtual terminal: Press Ctrl+Alt+F2
To return: Press Ctrl+Alt+F1 or Ctrl+Alt+F7

Loading

[MASTODON 4.2.10] How to update Mastodon to a new version

Updated on 26-08-2024. For the old version, click here.

Contents:
1. UPDATE
2. RUBY VERSION ISSUES
3. RUBY GEM ISSUES
4. CHARLOC_HOLMES GEM ISSUES

So a new release came out and it is important to get this update as soon as possible! This manual is a transcript of the way that I have updated my Mastodon instance. Please make sure you make proper backups and use your brain while updating things.

A guide to making a Mastodon backup can be found here.

Linux flavour: Debian
Update from: 4.2.xx

  1. Log into your server
  2. su - mastodon
  3. cd /home/mastodon/live
  4. git fetch --tags
  5. git checkout [type the most recent version here, starting with the letter v. For example; v4.2.5
    git checkout v4.2.10
  6. If you get a ruby version error, please see bottom of this article for a fix! bundle install
  7. yarn install
  8. RAILS_ENV=production bundle exec rails db:migrate
    
    #NOTE: You might get a ruby error which then suggests you to enter the command "bundle install". Do that and then run the RAILS command again.
  9. RAILS_ENV=production bundle exec rails assets:precompile
  10. exit

OPTIONAL:
After updating, you might get a notification to update the browserlist database. You can do that with the following command:

npx update-browserslist-db@latest

Okay, you can now choose to either reboot or restart the services.

REBOOT:

  1. This command may vary, depending on your Linux flavour.
    systemctl reboot

RESTART:

  1. This command may vary, depending on your Linux flavour.
    systemctl restart mastodon-sidekiq
    systemctl reload mastodon-web
    
    

    Optional:

    systemctl restart mastodon-streaming

RUBY VERSION ISSUES

My system was unable to find the required v3.2.3 of Ruby and I have fixed this by doing the following steps:

  1. Please make sure that your path is correct.
    git -C ~/.rbenv/plugins/ruby-build pull
  2. rbenv install 3.2.3
    
    

    *WAIT TILL DONE* (it may take a little while)

  3. To check all the installed versions type:
    rbenv versions
  4. To set v3.2.3 as the global version, type:
    rbenv global 3.2.3
  5. To double-check the active, installed version, type:
    rbenv versions
  6. Done!

This manual is a transcript of the way that I have updated my Mastodon instance. Please make sure you make proper backups and use your brain while updating things.

Sources: https://richstone.io/where-is-ruby-3-0-0-on-rbenv/

RUBY GEM ISSUES

After entering…

RAILS_ENV=production bundle exec rails db:migrate

…you might get a ruby gem error like:

Could not find rexml-3.3.5, strscan-3.1.0 in locally installed gems
Run `bundle install` to install missing gems.

Enter the command “bundle install” and after that run the RAILS command again.

CHARLOCK_HOLMES ISSUES

The charlock_holmes gem may fail to build on some systems with recent versions of gcc. If you run into such an issue, try

BUNDLE_BUILD__CHARLOCK_HOLMES="--with-cxxflags=-std=c++17" bundle install.

Loading

IMAPSYNC for Debian 8 installation

  1. apt-get update
  2. apt-get upgrade
  3. apt-install git libjson-webtoken-perl libauthen-ntlm-perl libcgi-pm-perl libcrypt-openssl-rsa-perl libdata-uniqid-perl libfile-copy-recursive-perl libio-socket-inet6-perl libio-socket-ssl-perl libio-tee-perl libhtml-parser-perl libjson-webtoken-perl libmail-imapclient-perl libparse-recdescent-perl libmodule-scandeps-perl libreadonly-perl libregexp-common-perl libsys-meminfo-perl libterm-readkey-perl libtest-mockobject-perl libtest-pod-perl libunicode-string-perl liburi-perl libwww-perl libtest-nowarnings-perl libtest-deep-perl libtest-warn-perl make cpanminus
  4. cd /home
  5. git clone https://github.com/imapsync/imapsync.git
  6. cd imapsync
  7. chmod +x imapsync
  8. Test it by typing
    ./imapsync
  9. You may need to install some extras by entering
    cpanm File::Tail
  10. cp imapsync /usr/bin/

Done!

Item 10 is to make sure you can use this command anywhere on the server. Have fun!

Loading