firewalld (Dynamic Firewall Manager) tool provides a dynamically managed firewall. The tool enables network/firewall zones to define the trust level of network connections and/or interfaces. It has support both for IPv4 and IPv6 firewall settings. Also, it supports Ethernet bridges and allow you to separate between runtime and permanent configuration options. Finally, it supports an interface for services or applications to add firewall rules directly.

Disable firewalld

To disable firewalld, execute the following command as root or using sudo:

systemctl disable firewalld;

Enable firewalld

To enable firewalld, execute the following command as root or using sudo:

systemctl enable firewalld;

Stop firewalld

To stop (or deactivate) firewalld,execute the following command as root or using sudo:

systemctl stop firewalld;

Start firewalld

To start (or activate) firewalld, execute the following command as root or using sudo:

systemctl start firewalld;

Status of firewalld

To check the status of firewalld, execute the following command as root or using sudo:

systemctl status firewalld;

CONCEPTS

systemd provides a dependency system between various entities called “units” of 12 different types. Units encapsulate various objects that are relevant for system boot-up and maintenance. The majority of units are configured in unit configuration files, whose syntax and basic set of options is described in systemd.unit(5), however some are created automatically from other configuration, dynamically from system state or programmatically at runtime. Units may be “active” (meaning started, bound, plugged in, …, depending on the unit type, see below), or “inactive” (meaning stopped, unbound, unplugged, …), as well as in the process of being activated or deactivated, i.e. between the two states (these states are called “activating”, “deactivating”). A special “failed” state is available as well, which is very similar to “inactive” and is entered when the service failed in some way (process returned error code on exit, or crashed, or an operation timed out). If this state is entered, the cause will be logged, for later reference. Note that the various unit types may have a number of additional substates, which are mapped to the five generalized unit states described here. — From man systemd

The above, in a nutshell:

enabled is a service that is configured to start when the system boots

disabled is a service that is configured to not start when the system boots

active is a service that is currently running

inactive is a service that is currently stopped and may be disabled, but it can be started and become active

firewalld (Dynamic Firewall Manager) tool provides a dynamically managed firewall. The tool enables network/firewall zones to define the trust level of network connections and/or interfaces. It has support both for IPv4 and IPv6 firewall settings. Also, it supports Ethernet bridges and allow you to separate between runtime and permanent configuration options. Finally, it supports an interface for services or applications to add firewall rules directly.

Disable firewalld

To disable firewalld, execute the following command as root or using sudo:

systemctl disable firewalld

Enable firewalld

To enable firewalld, execute the following command as root or using sudo:

systemctl enable firewalld

Stop firewalld

To stop (or deactivate) firewalld,execute the following command as root or using sudo:

systemctl stop firewalld

Start firewalld

To start (or activate) firewalld, execute the following command as root or using sudo:

systemctl start firewalld

Status of firewalld

To check the status of firewalld, execute the following command as root or using sudo:

systemctl status firewalld

CONCEPTS

systemd provides a dependency system between various entities called “units” of 12 different types. Units encapsulate various objects that are relevant for system boot-up and maintenance. The majority of units are configured in unit configuration files, whose syntax and basic set of options is described in systemd.unit(5), however some are created automatically from other configuration, dynamically from system state or programmatically at runtime. Units may be “active” (meaning started, bound, plugged in, …, depending on the unit type, see below), or “inactive” (meaning stopped, unbound, unplugged, …), as well as in the process of being activated or deactivated, i.e. between the two states (these states are called “activating”, “deactivating”). A special “failed” state is available as well, which is very similar to “inactive” and is entered when the service failed in some way (process returned error code on exit, or crashed, or an operation timed out). If this state is entered, the cause will be logged, for later reference. Note that the various unit types may have a number of additional substates, which are mapped to the five generalized unit states described here. — From man systemd

The above, in a nutshell:

enabled is a service that is configured to start when the system boots

disabled is a service that is configured to not start when the system boots

active is a service that is currently running

inactive is a service that is currently stopped and may be disabled, but it can be started and become active

Method 1 – Using date

The following example will calculate the execution time in seconds by subtracting the system date and time in seconds since 1970-01-01 00:00:00 UTC once right before the script goes to the computation part and once right after.

In order to get the system date and time in seconds since 1970-01-01 00:00:00 UTC we use the command date +%s.

#!/bin/bash
#Print the system date and time in seconds since 1970-01-01 00:00:00 UTC
startTime=$(date +%s);
#We pick a random number between 1 and 10.
#Then we delay the execution for that amount of seconds.
sleep $(( (RANDOM % 10) + 1 ));
endTime=$(date +%s);
#Subtract endTime from startTime to get the total execution time
totalTime=$(($endTime-$startTime));
echo "Process finished after $totalTime seconds";
exit 0;

Method 2 – Using bash internal SECONDS variable

The following example will calculate the execution time in seconds by reseting the bash internal variable SECONDS to 0, forcing the shell to continue counting from there.

#!/bin/bash
#This variable expands to the number of seconds since the shell was started.
#We set it to 0, forcing the shell to continue counting from there.
SECONDS=0;
#We pick a random number between 1 and 10.
#Then we delay the execution for that amount of seconds.
sleep $(( (RANDOM % 10) + 1 ));
echo "Process finished after $SECONDS seconds";
exit 0;

Method 3 – Using bash time

The following example uses the bash time command, which reports the time consumed by a pipeline’s execution.
When time command is executed without its complete path, then the bash built-in time command is executed, instead of the GNU time command. We will use the bash time command in this example and we will use it to run a whole block of commands.
Please note that time command will return the time in seconds as a float (i.e. there will be decimal places. e.g. 1 will be printed as 1.00).

#!/bin/bash
#The bash time command reports the time consumed by pipeline's execution
#When time command is executed without its complete path, then the bash built-in time command is executed, instead of the GNU time command.
#We will use the bash time command in this example and we will use it to run a whole block of commands.
#We change the output format of time to print elapsed real time in seconds.
TIMEFORMAT="%E";
#We pick a random number between 1 and 10.
#Then we delay the execution for that amount of seconds.
totalTime=`time ( sleep $(( (RANDOM % 10) + 1 )) ) 2>&1`;
#Please note that time command will return the time in seconds as a float (i.e. there will be decimal places. e.g. 1 will be printed as 1.00).
#This will happen as time has build-in more precision than the first two methods presented here.
echo "Process finished after $totalTime seconds";
totalTimeBlock=`time (
sleep $(( (RANDOM % 10) + 1 ));
sleep $(( (RANDOM % 10) + 1 ));
) 2>&1`;
echo "Block finished after $totalTimeBlock seconds";
exit 0;

Method 4 – Using GNU time

The GNU time command runs the specified program command with the given arguments.
When time command is executed without its complete path (in our case it was /usr/bin/time), then the bash built-in time command is executed, instead of the GNU time command. To make sure we use the GNU time command, we use which to get the full path of the time command.
Please note that time command will return the time in seconds as a float (i.e. there will be decimal places. e.g. 1 will be printed as 1.00).

#!/bin/bash
#The time command runs the specified program command with the given arguments.
#When time command is executed without its complete path (in our case it was /usr/bin/time), then the bash built-in time command is executed, instead of the GNU time command.
#To make sure we use the GNU time command, we use which to get the full path of the time command.
time=`which time`;
#We pick a random number between 1 and 10.
#Then we delay the execution for that amount of seconds.
#We change the output format of time to print elapsed real time in seconds.
totalTime="$( $time -f '%e' sleep $(( (RANDOM % 10) + 1 )) 2>&1 1>/dev/null )";
#Please note that time command will return the time in seconds as a float (i.e. there will be decimal places. e.g. 1 will be printed as 1.00).
#This will happen as time has build-in more precision than the first two methods presented here.
echo "Process finished after $totalTime seconds";
exit 0;

Notes

RANDOM internal variable

Each time RANDOM internal variable is referenced, a random integer between 0 and 32767 is generated.

By using the RANDOM variable in this command $(( (RANDOM % 10) + 1 )); we perform a modulo on the random value with the static value 10. This way we force the range of valid values to be between 0 and 9.
Later, we add 1 to that value to shift the range to be between 1 and 10.

First way to make terminator toggle its visibility using the F12 key (like guake)

Start terminator

Right click anywhere in the terminal area and click on the Preferences option

In the new window, click on the Keybindings tab and scroll down until you find the line that has the following information:
Name : hide_window
Action : Toggle window visibility

Click on the Keybinding column (3rd column), the value will change to New accelerator..., hit the key combination you want to be used to toggle the visibility of terminator. If you want the same behavior as guake, hit F12. You will see that the value in the Keybinding column will change to F12.

Hit the close button to close the settings window.

In the terminal try the key you just set (e.g F12) to see if it works. If it doesn’t work and in the case of F12 writes on the terminal a ~, close terminator and re-open it for the changes to get applied.

Second way to make terminator toggle its visibility using the F12 key (like guake)

Create the folder tree ~/.config/terminator (maybe it exists already). Please note that the . in front of config is purposely there, it is the way to hide a folder.

In the folder create a file named config (the full path would be ~/.config/terminator/config) and put the following as content:

We propose an alternative solution to making terminator act like guake that requires two additional packages: xdotool and wmctrl.

Our proposal will launch terminator if there is not instance running.

In Ubuntu you can install the needed packages from the official repositories using sudo apt-get install xdotool wmctrl.

Using a text editor, create in you home folder a file named nano ~/toggle_visibility.sh and copy there the contents of the following chunk of code. You can also use nano, from a terminal issue nano ~/toggle_visibility.sh, then paste the code and hit CTRL+X to exit. When prompted if you want to save press ‘Y’ and hit enter.

#!/bin/bash
#The purpose of this script is to allow the user to toggle the visibility of (almost) any window.
#Please note it will work on the first match, so if there are multiple instances of an application it would be a random window of them the one to be affected.
#Usually it will control the window with the smallest PID.
#Checking that all dependencies are met, since we cannot proceed without them.
declare -a DEPENDENCIES=("xdotool" "wmctrl");
declare -a MANAGERS=("dnf" "apt-get");
for DEPENDENCY in ${DEPENDENCIES[@]}; do
echo -n "Checking if $DEPENDENCY is available";
if hash $DEPENDENCY 2>/dev/null; then
echo "- OK, Found";
else
echo "- ERROR, Not Found in $PATH";
for MANAGER in ${MANAGERS[@]}; do
if hash $MANAGER 2>/dev/null; then
echo -n "$DEPENDENCY is missing, would you like to try and install it via $MANAGER now? [Y/N] (default is Y): ";
read ANSWER;
if [[ "$ANSWER" == "Y" || "$ANSWER" == "y" || "$ANSWER" == "" ]]; then
sudo "$MANAGER" install "$DEPENDENCY";
else
echo "Terminating";
exit -1;
fi
fi
done
fi
done
APPLICATION="$1";
FULL_COMMAND="$2";
#Checking if the application name provided by the user exists
if ! hash $APPLICATION 2>/dev/null; then
echo -e "$APPLICATION does not seem to be a valid executable\nTerminating";
exit -2;
fi
#Checking if the application is running.
PID=$(pgrep -u `whoami` -f "$FULL_COMMAND" | head -n 1);
#If the application is not running, we will try to launch it.
if [ -z $PID ]; then
echo "$FULL_COMMAND not running, launching it..";
$FULL_COMMAND;
else
#Since the application has a live instance, we can proceed with the rest of the code.
#We will get the PID of the application that is currently focused, if it is not the application we passed as parameter we will change the focus to that. In the other case, we will minimize the application.
echo -n "$FULL_COMMAND instance found - ";
FOCUSED=$(xdotool getactivewindow getwindowpid);
if [[ $PID == $FOCUSED ]]; then
echo "It was focused so we are minimizing it";
#We minimize the active window which we know in this case that it is the application we passed as parameter.
xdotool getactivewindow windowminimize;
else
echo "We are setting the focus on it";
#We set the focus to the application we passed as parameter. If it is minimized it will be raised as well.
wmctrl -x -R $APPLICATION;
fi
fi
exit 0

Afterwards, you need to make the script an executable so you should issue chmod +x ~/toggle_visibility.sh to do that.

Then, execute ~/toggle_visibility.sh in your terminal once. We need to do that in order to install any missing dependencies for the tool.

Finally, you need to create a custom shortcut that will call the script using the key combination you like at any point.

To complete the procedure:

Go to ‘System Settings’ either by clicking on the menu on the top right corner that looks like a light bulb or by issuing the following in a terminal unity-control-center to start the unity control center.

In the newly appeared window, click on the ‘keyboard’ icon that is in the category ‘Hardware’.

After that, click on the tab ‘Shortcuts’

and on the left list, click on custom shortcuts.

You will see a button with the + sign right next to the list, click that.

In the dialog box that will appear enter the following:
– In the name field enter anything you like. e.g ‘Toggle Terminator Visibility’
– In the command field enter /home/<USER>/toggle_visibility.sh terminator "^/usr/bin/python /usr/bin/terminator$" where <USER> enter your own username.
– Click apply.

You will see a new row with two columns with the name you just set in the first column. Click on the second column, where it should say ‘Disabled’ and the press the key combination you want for toggling terminator e.g F12

You are ready to go 🙂

Just try the key combination you just provided and terminator will appear in front of you. Pressing it once more it will hide it.

NOTE: Please keep in mind that the above script can be used for other applications as well. In step 7, we gave as parameter the name of the application to be used, if you change that you could use it with other applications like Firefox.

We used the find general command to get all folders that are in depth 1, in other words all folders that are in the specific folder where we started the search.
In our case we used the dot as the starting folder which means that it will run the find in the same folder as we were navigating in.
We passed as a parameter the -type d to instruct find to show only folders and ignore the files.
The \( ! -name . \) prevents executing the command in current directory by removing it from the result set.
With the results we executed some commands on each.

Specifically, we created a new bash session for each result that navigated in the folder, printed out the name of the matched folder and then print the Remote Origin URL using the command git config --get remote.origin.url

Issue in your terminal the following to change the mode of how the background is displayed

gsettings set org.gnome.desktop.background picture-options "scaled"

We used “scaled” which will center the image to and will resize it to fit the screen if needed.
You could use another option if you like. To get the full list of available options issue the following in your terminal.

We tried to toggle the visibility of the terminator window using the default keybinding which is (Shift+Ctrl+Alt+A) and failed. Changing the configuration in the ‘Terminator Preferences’ under Keybindings to a new key-bind also did not do any good. We could not get the hide_window keybinding to work and so we could not toggle the window visibility with the keyboard.

We propose this alternative solution that requires two additional packages: xdotool and wmctrl.

In Fedora you can install them using sudo dnf install xdotool wmctrl and in Ubuntu using sudo apt-get install xdotool wmctrl

After the installation is complete, you need to paste the following code in a file and make it an executable.

e.g From a terminal issue nano ~/toggle_visibility.sh, then paste the code and hit CTRL+X to exit. When prompted if you want to save press ‘Y’ and enter.

#!/bin/bash
#The purpose of this script is to allow the user to toggle the visibility of (almost) any window.
#Please note it will work on the first match, so if there are multiple instances of an application it would be a random window of them the one to be affected.
#Usually it will control the window with the smallest PID.
#Checking that all dependencies are met, since we cannot proceed without them.
declare -a DEPENDENCIES=("xdotool" "wmctrl");
declare -a MANAGERS=("dnf" "apt-get");
for DEPENDENCY in ${DEPENDENCIES[@]}; do
echo -n "Checking if $DEPENDENCY is available";
if hash $DEPENDENCY 2>/dev/null; then
echo "- OK, Found";
else
echo "- ERROR, Not Found in $PATH";
for MANAGER in ${MANAGERS[@]}; do
if hash $MANAGER 2>/dev/null; then
echo -n "$DEPENDENCY is missing, would you like to try and install it via $MANAGER now? [Y/N] (default is Y): ";
read ANSWER;
if [[ "$ANSWER" == "Y" || "$ANSWER" == "y" || "$ANSWER" == "" ]]; then
sudo "$MANAGER" install "$DEPENDENCY";
else
echo "Terminating";
exit -1;
fi
fi
done
fi
done
APPLICATION="$1";
#Checking if the application name provided by the user exists
if ! hash $APPLICATION 2>/dev/null; then
echo -e "$APPLICATION does not seem to be a valid executable\nTerminating";
exit -2;
fi
#Checking if the application is running. We are using pgrep as various application are python scripts and we will not be able to find them using pidof. pgrep will look through the currently running processes and list the process IDs of all the processes that are called $APPLICATION.
PID=$(pgrep --exact $APPLICATION | head -n 1);
#If the application is not running, we will try to launch it.
if [ -z $PID ]; then
echo "$APPLICATION not running, launching it..";
$APPLICATION;
else
#Since the application has a live instance, we can proceed with the rest of the code.
#We will get the PID of the application that is currently focused, if it is not the application we passed as parameter we will change the focus to that. In the other case, we will minimize the application.
echo -n "$APPLICATION instance found - ";
FOCUSED=$(xdotool getactivewindow getwindowpid);
if [[ $PID == $FOCUSED ]]; then
echo "It was focused so we are minimizing it";
#We minimize the active window which we know in this case that it is the application we passed as parameter.
xdotool getactivewindow windowminimize;
else
echo "We are setting the focus on it";
#We set the focus to the application we passed as parameter. If it is minimized it will be raised as well.
wmctrl -x -R $APPLICATION;
fi
fi
exit 0

Afterwards, you need to make the script an executable so you should issue chmod +x ~/toggle_visibility.sh to do that.

Then, execute ~/toggle_visibility.sh in your terminal once. We need to do that in order to install any missing dependencies for the tool.

Finally, you need to create a custom shortcut that will call the script using the key combination you like at any point.

For Fedora,

Issue the following in a terminal gnome-control-panel to start the gnome control panel.

In the newly appeared window, click on the ‘keyboard’ icon that is in the category ‘Hardware’.

After that, click on the tab ‘Shortcuts’

and on the left list, click on custom shortcuts.

You will see a button with the + sign, click that.

In the dialog box that will appear enter the following:
– In the name field enter anything you like. e.g ‘Toggle Terminator Visibility’
– In the command field enter ‘/home/<USER>/toggle_visibility.sh terminator’ where user enter your own username.
– Click apply.

You will see a new row with two columns with the name you just set in the first column. Click on the second column, where it should say ‘Disabled’ and the press the key combination you want for toggling terminator e.g F12

For Ubuntu, go to System Settings and follow the same procedure after step 2.

You are ready to go 🙂

Just try the key combination you just provided and terminator will appear in front of you. Pressing it once more it will hide it.

The above code will bring the JSON object, filter out everything except for the “ssh_url_to_repo” member of each project and then it will use it to clone the project by fixing up the URL to be used by git.

To get the above code working: the GitLab API requires that you use a token that is related to your account instead of using your credentials to make the call to the API.