Compare commits
7 Commits
v3.2.1
...
fd984c4a16
| Author | SHA1 | Date | |
|---|---|---|---|
| fd984c4a16 | |||
| c2a0ef0bd2 | |||
| dc64123fd9 | |||
| affe6e1487 | |||
| 0237f8bf70 | |||
| d4db72260a | |||
| e980198c08 |
109
README.md
109
README.md
@@ -1,3 +1,110 @@
|
|||||||
# profile
|
# profile
|
||||||
|
This project aims to create an advanced bash profile. It includes some aliases,
|
||||||
|
a customized prompt and several functions for different purposes. It's mostly
|
||||||
|
targeted to system administrator but might satisfy some regular users.
|
||||||
|
|
||||||
bash profile repository
|
## 1. Getting started
|
||||||
|
Download and extract (or use git clone) the profile archive into your home
|
||||||
|
directory. You will have to modify your ~/.bashrc and/or ~/.profile file to add
|
||||||
|
at the end (preferably):
|
||||||
|
```
|
||||||
|
source <installpath>/profile/profile.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
It's not recommended to load that profile in /etc/profile as the users' .bashrc
|
||||||
|
files might interfere with some aliases and functions defined in profile.
|
||||||
|
|
||||||
|
## 2. What's the purpose?
|
||||||
|
profile is giving access to numerous functions, aliases and to an advanced
|
||||||
|
prompt. Here is a non-exhaustive list of what we have:
|
||||||
|
- A bar style prompt with hour, execution time and exit code of the last
|
||||||
|
command;
|
||||||
|
- clean: erase after confirmation any backup file, possibly recursively;
|
||||||
|
- dpkgs: search for the given pattern in the installed packages name;
|
||||||
|
- expandlist: usefull in scripts, it expand any expression using wildcards into
|
||||||
|
the corresponding list of file and directories;
|
||||||
|
- genpwd: generate one or more random secure password;
|
||||||
|
- gpid: give the list of PID matching the given process name;
|
||||||
|
- help: display the list of available function and basic use;
|
||||||
|
- isipv4: tell if the given parameter is a valid IPv4 address;
|
||||||
|
- isipv6: tell if the given parameter is a valid IPv6 address;
|
||||||
|
- ku: kill all the processes owned by the given user name or ID;
|
||||||
|
- mcd: create a directory and immediately move into it;
|
||||||
|
- meteo: display weather forecast information;
|
||||||
|
- ppg: look for the given patern in the running processes;
|
||||||
|
- rain: console screensaver with rain effect;
|
||||||
|
- rmhost: remove the given host (name or IP) to the list of SSH known host;
|
||||||
|
- rmspc: in the current directory it replace all the spaces in filenames with a
|
||||||
|
underscore caracter (or any other given in option);
|
||||||
|
- setc: set locale on standard C;
|
||||||
|
- setfr: set locale on French;
|
||||||
|
- settrace: allow the debugging of any script by showing a backtrace in case of
|
||||||
|
error;
|
||||||
|
- setus: set locale on US English;
|
||||||
|
- showinfo: display basic informations about the host;
|
||||||
|
- ssr: root ssh login to the given host;
|
||||||
|
- taz: a universal command to compress files and directories, possibly several
|
||||||
|
at once;
|
||||||
|
- utaz: a utility that smartly uncompress many archives at once, creating a
|
||||||
|
directory only if needed;
|
||||||
|
- ver: show profile version.
|
||||||
|
|
||||||
|
## 3. Configuration
|
||||||
|
Some functions might have configurable default behaviour. You can create a
|
||||||
|
.profile.conf file to configure those default behaviour. You should have a look
|
||||||
|
at the doc/.profile.conf.example to see the list of available options.
|
||||||
|
|
||||||
|
## 4. Contact and more information
|
||||||
|
### 4.1. New users
|
||||||
|
This project is very new in terms of publication, and I have no idea of who will
|
||||||
|
use it, if any does. If you use (or plan to use) ```profile```, I'll be very
|
||||||
|
happy if you simply mail me to let me know, especially if you don't plan to
|
||||||
|
contribute. If you plan to contribute, I'll be twice happier for sure!
|
||||||
|
|
||||||
|
### 4.2. Bugs
|
||||||
|
**profile** bug tracker is hosted on its Gitea instance. Check the
|
||||||
|
https://git.geoffray-levasseur.org/fatalerrors/profile page. If you find a bug,
|
||||||
|
you can also submit a bug report to the maintainer mail address mentioned at
|
||||||
|
the end of that document. A bug report may contain the command line parameters
|
||||||
|
where the bug happens, OS details, the module that trigger it, if any, and the
|
||||||
|
log file containing the error. Cygwin users: please note that bash
|
||||||
|
implementation in Cygwin triggers regularly bugs on advanced code that triggers
|
||||||
|
nothing with Linux or BSD. Please do not send synthax error bug repports if you
|
||||||
|
didn't test the same code in the same conditions using a real Unix.
|
||||||
|
|
||||||
|
Please check the to-do list before sending any feature request, as it might
|
||||||
|
have already be requested.
|
||||||
|
|
||||||
|
### 4.3. How to contribute?
|
||||||
|
You are free to improve and contribute as you wish. If you have no idea what to
|
||||||
|
do or want some direction, you can check the [to-do list](./doc/todo.md),
|
||||||
|
containing desired future improvements. Make sure you always have the latest
|
||||||
|
development version before starting your work.
|
||||||
|
|
||||||
|
It's heavily recommended to use git to obtain the latest copy of profile tree.
|
||||||
|
Make sure your git configuration is correct in order to contribute. Please
|
||||||
|
contact me to obtain push authorizations, or, if you want to submit a patch, you
|
||||||
|
can send it by mail to the maintainer of init.sh.
|
||||||
|
|
||||||
|
Code written in Python or Perl might be accepted as long as it's not mobilizing
|
||||||
|
a lot of dependencies (forget big framework). Anything that need the
|
||||||
|
installation of packages not provided in minimal Debian or CentOS installation
|
||||||
|
will be probably rejected.
|
||||||
|
|
||||||
|
If you want to make a financial contribution, please contact me by mail.
|
||||||
|
|
||||||
|
### 4.4. License, website, and maintainer
|
||||||
|
Everything except configuration files is licensed under BSD-3 license. Please
|
||||||
|
check license file allong this one.
|
||||||
|
|
||||||
|
Please check [https://www.geoffray-levasseur.org/profile](https://www.geoffray-levasseur.org/profile).
|
||||||
|
Note that this website is still under construction and needs some more care.
|
||||||
|
|
||||||
|
You can mail author to fatalerrors \<at\> geoffray-levasseur \<dot\> org.
|
||||||
|
|
||||||
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Documentation (c) 2021-2022 Geoffray Levasseur.
|
||||||
|
|
||||||
|
This file is distributed under3-clause BSD license. The complete license
|
||||||
|
agreement can be obtained at: https://opensource.org/licenses/BSD-3-Clause
|
||||||
|
|||||||
@@ -7,6 +7,13 @@ Current version from Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
|
|||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
Version history:
|
Version history:
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
|
# 28/11/2022 v3.2.3
|
||||||
|
Made proper readme file, to improve
|
||||||
|
|
||||||
|
# 21/11/2022 v3.2.2
|
||||||
|
Fixed taz compression level analysis
|
||||||
|
Fixed typo in dpkgs
|
||||||
|
|
||||||
# 20/11/2022 v3.2.1
|
# 20/11/2022 v3.2.1
|
||||||
Fix some messages
|
Fix some messages
|
||||||
Make dpkgs rpm aware (more to come)
|
Make dpkgs rpm aware (more to come)
|
||||||
|
|||||||
@@ -258,7 +258,7 @@ taz ()
|
|||||||
echo " -p, --parallel Number of threads to use (if allowed by underlying utility)"
|
echo " -p, --parallel Number of threads to use (if allowed by underlying utility)"
|
||||||
echo " -v, --verbose Display progress where possible"
|
echo " -v, --verbose Display progress where possible"
|
||||||
echo " -q, --quiet Display less messages (only errors and warnings)"
|
echo " -q, --quiet Display less messages (only errors and warnings)"
|
||||||
echo " -1, .., -9 Compression level to use [1=fast/big, 9=slow/small]"
|
echo " -1, .., -9 Compression level to use [1=fast/biggest, 9=slow/smallest]"
|
||||||
echo
|
echo
|
||||||
echo "Supported archive format:"
|
echo "Supported archive format:"
|
||||||
echo " Param.| programs | Algo. | Description"
|
echo " Param.| programs | Algo. | Description"
|
||||||
@@ -291,15 +291,15 @@ taz ()
|
|||||||
|
|
||||||
"-q"|"--quiet")
|
"-q"|"--quiet")
|
||||||
QUIET=1
|
QUIET=1
|
||||||
|
;;
|
||||||
"-"[1..9])
|
|
||||||
local complevel=$(echo $opt | sed 's/-//')
|
|
||||||
;;
|
|
||||||
|
|
||||||
"-"*)
|
"-"*)
|
||||||
echo "Invalid option, use taz --help to display options list"
|
local complevel=$(echo $opt | sed 's/-//')
|
||||||
echo
|
if ! [[ $complevel =~ ^[1-9]+$ ]]; then
|
||||||
return 1
|
disp E "Invalid option, use taz --help to display options list"
|
||||||
|
echo
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
;;
|
;;
|
||||||
|
|
||||||
*)
|
*)
|
||||||
|
|||||||
48
profile.d/fun.sh
Normal file
48
profile.d/fun.sh
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
|
||||||
|
# Protected by the BSD3 license. Please read bellow for details.
|
||||||
|
#
|
||||||
|
# * Redistribution and use in source and binary forms,
|
||||||
|
# * with or without modification, are permitted provided
|
||||||
|
# * that the following conditions are met:
|
||||||
|
# *
|
||||||
|
# * Redistributions of source code must retain the above
|
||||||
|
# * copyright notice, this list of conditions and the
|
||||||
|
# * following disclaimer.
|
||||||
|
# *
|
||||||
|
# * Redistributions in binary form must reproduce the above
|
||||||
|
# * copyright notice, this list of conditions and the following
|
||||||
|
# * disclaimer in the documentation and/or other materials
|
||||||
|
# * provided with the distribution.
|
||||||
|
# *
|
||||||
|
# * Neither the name of the copyright holder nor the names
|
||||||
|
# * of any other contributors may be used to endorse or
|
||||||
|
# * promote products derived from this software without
|
||||||
|
# * specific prior written permission.
|
||||||
|
# *
|
||||||
|
# * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||||
|
# * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||||
|
# * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
|
# * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
# * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||||
|
# * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
# * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
# * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
# * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
# * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||||
|
# * OF SUCH DAMAGE.
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# Make non-IT peoples think you're busy doing something hard
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
busy()
|
||||||
|
{
|
||||||
|
if [[ -n $1 ]]; then
|
||||||
|
local pattern="$@"
|
||||||
|
else
|
||||||
|
local pattern="ca fe"
|
||||||
|
fi
|
||||||
|
cat /dev/urandom | hexdump -C | grep "$pattern"
|
||||||
|
unset pattern
|
||||||
|
}
|
||||||
@@ -36,7 +36,7 @@
|
|||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Look for a package within installed one
|
# Look for a package within installed one
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
dpkgs ()
|
pkgs ()
|
||||||
{
|
{
|
||||||
local count=0
|
local count=0
|
||||||
for opt in $@ ; do
|
for opt in $@ ; do
|
||||||
@@ -68,13 +68,12 @@ dpkgs ()
|
|||||||
disp E "Please specify a package name, without space, eventually partial." &&
|
disp E "Please specify a package name, without space, eventually partial." &&
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
if [[ $(command -v dpkg >/dev/null 2>&1) ]]; then
|
command -v dpkg >/dev/null 2>&1 && local cmd="dpkg -l"
|
||||||
dpkg -l | grep $pkg
|
command -v rpm >/dev/null 2>&1 && local cmd="rpm -qa"
|
||||||
elif [[ $(command -v dpkg >/dev/null 2>&1) ]]; then
|
if [[ -z $cmd ]]; then
|
||||||
rpm -qa | grep $pkg
|
|
||||||
else
|
|
||||||
disp E "No usable package manager seems unavialable."
|
disp E "No usable package manager seems unavialable."
|
||||||
return 2
|
return 2
|
||||||
fi
|
fi
|
||||||
|
$cmd | grep $pkg
|
||||||
}
|
}
|
||||||
export -f dpkgs
|
export -f pkgs
|
||||||
|
|||||||
0
profile.d/pwd.sh
Executable file → Normal file
0
profile.d/pwd.sh
Executable file → Normal file
56
profile.d/updates.sh
Normal file
56
profile.d/updates.sh
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
|
||||||
|
# Protected by the BSD3 license. Please read bellow for details.
|
||||||
|
#
|
||||||
|
# * Redistribution and use in source and binary forms,
|
||||||
|
# * with or without modification, are permitted provided
|
||||||
|
# * that the following conditions are met:
|
||||||
|
# *
|
||||||
|
# * Redistributions of source code must retain the above
|
||||||
|
# * copyright notice, this list of conditions and the
|
||||||
|
# * following disclaimer.
|
||||||
|
# *
|
||||||
|
# * Redistributions in binary form must reproduce the above
|
||||||
|
# * copyright notice, this list of conditions and the following
|
||||||
|
# * disclaimer in the documentation and/or other materials
|
||||||
|
# * provided with the distribution.
|
||||||
|
# *
|
||||||
|
# * Neither the name of the copyright holder nor the names
|
||||||
|
# * of any other contributors may be used to endorse or
|
||||||
|
# * promote products derived from this software without
|
||||||
|
# * specific prior written permission.
|
||||||
|
# *
|
||||||
|
# * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||||
|
# * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||||
|
# * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
|
# * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
# * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||||
|
# * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
# * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
# * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
# * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
# * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||||
|
# * OF SUCH DAMAGE.
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# Check for profile updates
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
check_updates()
|
||||||
|
{
|
||||||
|
disp I "Checking for updates..."
|
||||||
|
local vfile="/tmp/version"
|
||||||
|
wget "$UPDT_URL/version" -O $vfile 2&>1 /dev/null || {
|
||||||
|
disp E "Can\'t download information file, impossible to proceed!"
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
if [[ -s /tmp/version ]]; then
|
||||||
|
local lastver=$(cat /tmp/version)
|
||||||
|
if [[ $lastver != $PROFVERSION ]]; then
|
||||||
|
disp I "You have version $PROFVERSION installed. Version $lastver is available."
|
||||||
|
disp I "You should upgrade to last version when possible."
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
disp E "Impossible to read temporary file, impossible to proceed."
|
||||||
|
fi
|
||||||
|
}
|
||||||
28
profile.sh
28
profile.sh
@@ -35,10 +35,6 @@
|
|||||||
# * OF SUCH DAMAGE.
|
# * OF SUCH DAMAGE.
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
export PROFVERSION="3.2.1"
|
|
||||||
|
|
||||||
export DEFAULT_CITY="Toulouse"
|
|
||||||
|
|
||||||
if [[ ! $(echo $SHELL | grep bash) ]]; then
|
if [[ ! $(echo $SHELL | grep bash) ]]; then
|
||||||
echo "That environmet script is designed to be used with bash or zsh being the shell."
|
echo "That environmet script is designed to be used with bash or zsh being the shell."
|
||||||
echo "Please consider using bash or zsh instead, or patch me ;)!"
|
echo "Please consider using bash or zsh instead, or patch me ;)!"
|
||||||
@@ -83,6 +79,21 @@ pathappend ()
|
|||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
# Store script's path (realpath -s resolve symlinks if profile.sh is a symlink)
|
||||||
|
export MYPATH=$(dirname $(realpath -s $0))
|
||||||
|
if [[ ! -e $MYPATH/profile.sh ]]; then
|
||||||
|
disp W "Path detection failed, using pwd..."
|
||||||
|
MYPATH=$(pwd)
|
||||||
|
if [[ ! -e $MYPATH/profile.sh ]]; then
|
||||||
|
disp E "Impossible to determine installation path, pretty much nothing will work."
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ ! -s $MYPATH/version ]]; then
|
||||||
|
disp W "Impossible to determine running version of profile, your installation might be broken."
|
||||||
|
fi
|
||||||
|
export PROFVERSION=$(cat $MYPATH/version)
|
||||||
|
|
||||||
# Build PATH environment variable
|
# Build PATH environment variable
|
||||||
if [[ $EUID -eq 0 ]] ; then
|
if [[ $EUID -eq 0 ]] ; then
|
||||||
pathappend /sbin:/usr/sbin
|
pathappend /sbin:/usr/sbin
|
||||||
@@ -106,16 +117,21 @@ export CFLAGS="-O2 -pipe -march=native"
|
|||||||
export MAKEFLAGS='-j12'
|
export MAKEFLAGS='-j12'
|
||||||
export PKGSOURCES='/share/src/archives'
|
export PKGSOURCES='/share/src/archives'
|
||||||
|
|
||||||
|
# Default city for weather forcast
|
||||||
|
export DEFAULT_CITY="Toulouse"
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Default values could be altered after this line
|
# Default values could be altered after this line
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
# Load global configuration
|
||||||
|
[[ -f $MYPATH/etc/profile.conf ]] && . ~/.profile.conf
|
||||||
|
|
||||||
# Load personal configuration
|
# Load personal configuration
|
||||||
[[ -f ~/.profile.conf ]] && . ~/.profile.conf
|
[[ -f ~/.profile.conf ]] && . ~/.profile.conf
|
||||||
|
|
||||||
# Execute optionnal config script if any
|
# Load module scripts
|
||||||
for script in ~/profile.d/*.sh ; do
|
for script in $MYPATH/profile.d/*.sh ; do
|
||||||
if [ -r $script ] ; then
|
if [ -r $script ] ; then
|
||||||
. $script
|
. $script
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user