Compare commits
15 Commits
v3.2.2
...
bef205ae84
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bef205ae84 | ||
|
|
9e49e3e4d7 | ||
| 94e7e79c76 | |||
| 55e88bd018 | |||
|
|
18f1bc1543 | ||
|
|
0d7c7e9ab7 | ||
|
|
64fecf16fb | ||
| c2ca5f659c | |||
| 3248327e56 | |||
| fd984c4a16 | |||
| c2a0ef0bd2 | |||
| dc64123fd9 | |||
| affe6e1487 | |||
| 0237f8bf70 | |||
| d4db72260a |
109
README.md
109
README.md
@@ -1,3 +1,110 @@
|
||||
# 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
|
||||
|
||||
14
history.txt
14
history.txt
@@ -7,6 +7,20 @@ Current version from Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
|
||||
------------------------------------------------------------------------------
|
||||
Version history:
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
# 24/02/2022 v3.3.1
|
||||
Fixed version detection
|
||||
Added "busy" function
|
||||
Fixed use of library functions before it's loaded
|
||||
|
||||
# 28/11/2022 v3.3.0
|
||||
Initial version update support
|
||||
Changed versioning code
|
||||
Added installation path detection
|
||||
|
||||
# 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
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
# ------------------------------------------------------------------------------
|
||||
# Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
|
||||
# Protected by the BSD3 license. Please read bellow for details.
|
||||
@@ -38,45 +39,45 @@
|
||||
# ------------------------------------------------------------------------------
|
||||
utaz()
|
||||
{
|
||||
for opt in $@ ; do
|
||||
for opt in $@; do
|
||||
case $opt in
|
||||
"-h"|"--help")
|
||||
echo "utaz: uncompress all the given files and/or the ones found in the given"
|
||||
echo " directories creating an host directory where needed."
|
||||
echo
|
||||
echo "Usage: utaz [option] [directorie(s)|file(s)]"
|
||||
echo
|
||||
echo "Options:"
|
||||
echo " -h, --help Display that help screen"
|
||||
echo " -d, --delete If decompression succeeded, delete the source file"
|
||||
echo " -c, --create-dir Always create a host directory"
|
||||
echo " -n, --no-dir Never create a host directory"
|
||||
echo
|
||||
return 0
|
||||
;;
|
||||
"-h" | "--help")
|
||||
echo "utaz: uncompress all the given files and/or the ones found in the given"
|
||||
echo " directories creating an host directory where needed."
|
||||
echo
|
||||
echo "Usage: utaz [option] [directorie(s)|file(s)]"
|
||||
echo
|
||||
echo "Options:"
|
||||
echo " -h, --help Display that help screen"
|
||||
echo " -d, --delete If decompression succeeded, delete the source file"
|
||||
echo " -c, --create-dir Always create a host directory"
|
||||
echo " -n, --no-dir Never create a host directory"
|
||||
echo
|
||||
return 0
|
||||
;;
|
||||
|
||||
"-d"|"--delete")
|
||||
local willrm=1
|
||||
;;
|
||||
"-d" | "--delete")
|
||||
local willrm=1
|
||||
;;
|
||||
|
||||
"-c"|"--create-dir")
|
||||
local createdir=1
|
||||
;;
|
||||
"-c" | "--create-dir")
|
||||
local createdir=1
|
||||
;;
|
||||
|
||||
"-n"|"--no-dir")
|
||||
local nodir=1
|
||||
;;
|
||||
"-n" | "--no-dir")
|
||||
local nodir=1
|
||||
;;
|
||||
|
||||
"-"*)
|
||||
disp E "Invalid option, use \"utaz --help\" to display options list"
|
||||
echo
|
||||
return 1
|
||||
;;
|
||||
"-"*)
|
||||
disp E "Invalid option, use \"utaz --help\" to display options list"
|
||||
echo
|
||||
return 1
|
||||
;;
|
||||
|
||||
*)
|
||||
# The ${opt%/} writing is to remove trailing / if any
|
||||
local LIST="$LIST ${opt%/}"
|
||||
;;
|
||||
*)
|
||||
# The ${opt%/} writing is to remove trailing / if any
|
||||
local LIST="$LIST ${opt%/}"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
@@ -85,7 +86,7 @@ utaz()
|
||||
[[ ! $LIST ]] && local LIST="."
|
||||
|
||||
for zitem in $LIST; do
|
||||
[[ $(ls $zitem/*.zip 2> /dev/null | wc -l) -eq 0 ]] &&
|
||||
[[ $(ls $zitem/*.zip 2>/dev/null | wc -l) -eq 0 ]] &&
|
||||
disp W "$zitem contains no supported archive file, skipping." &&
|
||||
continue
|
||||
|
||||
@@ -98,20 +99,20 @@ utaz()
|
||||
disp E "The filesystem can't create directories, exit!" &&
|
||||
return 1
|
||||
|
||||
unzip -o $f -d $dir > /dev/null 2>&1
|
||||
unzip -o $f -d $dir >/dev/null 2>&1
|
||||
case $? in
|
||||
0)
|
||||
[[ $willrm ]] && rm -f $f && disp I "File $zitem/$f deleted."
|
||||
;;
|
||||
0)
|
||||
[[ $willrm ]] && rm -f $f && disp I "File $zitem/$f deleted."
|
||||
;;
|
||||
|
||||
1)
|
||||
disp W "Compression program returned a warning: deletion canceled."
|
||||
;;
|
||||
*)
|
||||
disp E "The zip file seems corrupted, failed."
|
||||
rm -rf $dir > /dev/null 2>&1
|
||||
continue
|
||||
;;
|
||||
1)
|
||||
disp W "Compression program returned a warning: deletion canceled."
|
||||
;;
|
||||
*)
|
||||
disp E "The zip file seems corrupted, failed."
|
||||
rm -rf $dir >/dev/null 2>&1
|
||||
continue
|
||||
;;
|
||||
esac
|
||||
|
||||
if [[ $createdir ]]; then
|
||||
@@ -136,7 +137,7 @@ export -f utaz
|
||||
# ------------------------------------------------------------------------------
|
||||
# Compress directories or files into one or more archive
|
||||
# ------------------------------------------------------------------------------
|
||||
taz ()
|
||||
taz()
|
||||
{
|
||||
_doxz()
|
||||
{
|
||||
@@ -151,7 +152,7 @@ taz ()
|
||||
disp W "xz format is not suited for long term archiving."
|
||||
disp I "See https://www.nongnu.org/lzip/xz_inadequate.html for details."
|
||||
|
||||
# Compresse to xz (lzma2) - Deprecated
|
||||
# Compresse to xz (lzma2) - Deprecated
|
||||
xz $verb --compress --keep -$3 -T $2 $1
|
||||
return $?
|
||||
}
|
||||
@@ -170,7 +171,7 @@ taz ()
|
||||
local procopt=""
|
||||
[[ $2 -gt 1 ]] &&
|
||||
disp W "lzip doesn't support multithreading, falling back to 1 thread." &&
|
||||
disp W "Consitder installing plzip to obtain multithreading abilities."
|
||||
disp W "Consider installing plzip to obtain multithreading abilities."
|
||||
}
|
||||
|
||||
[[ $4 ]] && local verb="-vv"
|
||||
@@ -243,68 +244,68 @@ taz ()
|
||||
return $?
|
||||
}
|
||||
|
||||
for opt in $@ ; do
|
||||
for opt in $@; do
|
||||
case $opt in
|
||||
"-h"|"--help")
|
||||
echo "taz: archive all files of a directory."
|
||||
"-h" | "--help")
|
||||
echo "taz: archive all files of a directory."
|
||||
echo
|
||||
echo "Usage: taz [option] [--parallel=<n>] [--format=<format>] [directory1 ... directoryN]"
|
||||
echo
|
||||
echo "Options:"
|
||||
echo " -h, --help Display that help screen"
|
||||
echo " -d, --delete Delete source file or directory after success"
|
||||
echo " -f, --format Chose archive format in the given list. If several format are"
|
||||
echo " given, the smalest is kept"
|
||||
echo " -p, --parallel Number of threads to use (if allowed by underlying utility)"
|
||||
echo " -v, --verbose Display progress where possible"
|
||||
echo " -q, --quiet Display less messages (only errors and warnings)"
|
||||
echo " -1, .., -9 Compression level to use [1=fast/biggest, 9=slow/smallest]"
|
||||
echo
|
||||
echo "Supported archive format:"
|
||||
echo " Param.| programs | Algo. | Description"
|
||||
echo " ------+---------------+-------+----------------------------------------"
|
||||
echo " lz | plzip, lzip | lzma | Safe efficient default format"
|
||||
echo " xz | xz | lzma2 | Unsafe, not for long term"
|
||||
echo " bz2 | pbzip2, bzip2 | bzip2 | Historical but less efficient than lz"
|
||||
echo " gz | pigz, gzip | lz77 | Historical, safe, fast"
|
||||
echo " lzo | lzop | lzo | Very fast but no multithread"
|
||||
echo " tar | tar | tar | No compression"
|
||||
echo
|
||||
return 0
|
||||
;;
|
||||
|
||||
"-d" | "--delete")
|
||||
local willrm=1
|
||||
;;
|
||||
|
||||
"-f"?* | "--format"?*)
|
||||
local compform=$(echo "$opt" | cut -f 2- -d '=')
|
||||
;;
|
||||
|
||||
"-p"?* | "--parallel"?*)
|
||||
local nproc=$(echo "$opt" | cut -f 2- -d '=')
|
||||
;;
|
||||
|
||||
"-v" | "--verbose")
|
||||
local verbose=1
|
||||
;;
|
||||
|
||||
"-q" | "--quiet")
|
||||
QUIET=1
|
||||
;;
|
||||
|
||||
"-"*)
|
||||
local complevel=$(echo $opt | sed 's/-//')
|
||||
if ! [[ $complevel =~ ^[1-9]+$ ]]; then
|
||||
disp E "Invalid option, use taz --help to display options list"
|
||||
echo
|
||||
echo "Usage: taz [option] [--parallel=<n>] [--format=<format>] [directory1 ... directoryN]"
|
||||
echo
|
||||
echo "Options:"
|
||||
echo " -h, --help Display that help screen"
|
||||
echo " -d, --delete Delete source file or directory after success"
|
||||
echo " -f, --format Chose archive format in the given list. If several format are"
|
||||
echo " given, the smalest is kept"
|
||||
echo " -p, --parallel Number of threads to use (if allowed by underlying utility)"
|
||||
echo " -v, --verbose Display progress where possible"
|
||||
echo " -q, --quiet Display less messages (only errors and warnings)"
|
||||
echo " -1, .., -9 Compression level to use [1=fast/biggest, 9=slow/smallest]"
|
||||
echo
|
||||
echo "Supported archive format:"
|
||||
echo " Param.| programs | Algo. | Description"
|
||||
echo " ------+---------------+-------+----------------------------------------"
|
||||
echo " lz | plzip, lzip | lzma | Safe efficient default format"
|
||||
echo " xz | xz | lzma2 | Unsafe, not for long term"
|
||||
echo " bz2 | pbzip2, bzip2 | bzip2 | Historical but less efficient than lz"
|
||||
echo " gz | pigz, gzip | lz77 | Historical, safe, fast"
|
||||
echo " lzo | lzop | lzo | Very fast but no multithread"
|
||||
echo " tar | tar | tar | No compression"
|
||||
echo
|
||||
return 0
|
||||
;;
|
||||
return 1
|
||||
fi
|
||||
;;
|
||||
|
||||
"-d"|"--delete")
|
||||
local willrm=1
|
||||
;;
|
||||
|
||||
"-f"?*|"--format"?*)
|
||||
local compform=$(echo "$opt" | cut -f 2- -d '=')
|
||||
;;
|
||||
|
||||
"-p"?*|"--parallel"?*)
|
||||
local nproc=$(echo "$opt" | cut -f 2- -d '=')
|
||||
;;
|
||||
|
||||
"-v"|"--verbose")
|
||||
local verbose=1
|
||||
;;
|
||||
|
||||
"-q"|"--quiet")
|
||||
QUIET=1
|
||||
;;
|
||||
|
||||
"-"*)
|
||||
local complevel=$(echo $opt | sed 's/-//')
|
||||
if ! [[ $complevel =~ ^[1-9]+$ ]]; then
|
||||
disp E "Invalid option, use taz --help to display options list"
|
||||
echo
|
||||
return 1
|
||||
fi
|
||||
;;
|
||||
|
||||
*)
|
||||
local LIST="$LIST ${opt%/}"
|
||||
;;
|
||||
*)
|
||||
local LIST="$LIST ${opt%/}"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
@@ -312,7 +313,7 @@ taz ()
|
||||
[[ ! $nproc ]] && nproc=1
|
||||
[[ ! $complevel ]] && complevel=6
|
||||
[[ $verbose -gt 1 && $QUIET -gt 1 ]] &&
|
||||
disp E "The --verbose and --quiet options can't be used together."
|
||||
disp E "The --verbose and --quiet options can't be used together."
|
||||
|
||||
for item in $LIST; do
|
||||
local donetar=0
|
||||
@@ -338,14 +339,14 @@ taz ()
|
||||
disp I "\t Compressing archive..."
|
||||
_do$compform $fname $nproc $complevel $verbose
|
||||
[[ ! $? -eq 0 ]] && case $? in
|
||||
127)
|
||||
disp E "Compression program unavailable, aborting."
|
||||
return 127
|
||||
;;
|
||||
*)
|
||||
disp E "Compression program returned an error, not deleting anything if asked, skipping to next item."
|
||||
continue
|
||||
;;
|
||||
127)
|
||||
disp E "Compression program unavailable, aborting."
|
||||
return 127
|
||||
;;
|
||||
*)
|
||||
disp E "Compression program returned an error, not deleting anything if asked, skipping to next item."
|
||||
continue
|
||||
;;
|
||||
esac
|
||||
|
||||
[[ $donetar -gt 0 ]] && rm $fname
|
||||
@@ -359,3 +360,6 @@ taz ()
|
||||
unset QUIET
|
||||
}
|
||||
export -f taz
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# EOF
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#!/bin/bash
|
||||
# ------------------------------------------------------------------------------
|
||||
# Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
|
||||
# Protected by the BSD3 license. Please read bellow for details.
|
||||
@@ -36,16 +37,16 @@
|
||||
# ------------------------------------------------------------------------------
|
||||
# Display a backtrace
|
||||
# ------------------------------------------------------------------------------
|
||||
function backtrace ()
|
||||
function backtrace()
|
||||
{
|
||||
echo "========= Call stack ========="
|
||||
typeset -i i=0
|
||||
|
||||
|
||||
local func=
|
||||
for func in "${FUNCNAME[@]}"; do
|
||||
if [[ $i -ne 0 ]]; then
|
||||
printf '%15s() %s:%d\n' \
|
||||
"$func" "${BASH_SOURCE[$i]}" "${BASH_LINENO[ (( $i - 1)) ]}"
|
||||
"$func" "${BASH_SOURCE[$i]}" "${BASH_LINENO[(($i - 1))]}"
|
||||
fi
|
||||
let i++ || true
|
||||
done
|
||||
@@ -56,52 +57,54 @@ function backtrace ()
|
||||
# ------------------------------------------------------------------------------
|
||||
# Function to be trapped for errors investigation
|
||||
# ------------------------------------------------------------------------------
|
||||
function error ()
|
||||
function error()
|
||||
{
|
||||
local errcode=$?
|
||||
backtrace
|
||||
return $errcode
|
||||
}
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Activate or deactivate error trapping to display backtrace
|
||||
# ------------------------------------------------------------------------------
|
||||
settrace ()
|
||||
settrace()
|
||||
{
|
||||
local status="off"
|
||||
[[ $(trap -p ERR) ]] && status="on"
|
||||
#trap -p ERR
|
||||
for opt in $@ ; do
|
||||
for opt in $@; do
|
||||
case $opt in
|
||||
"-h"|"--help")
|
||||
echo "Try to activate backtrace display for script debugging."
|
||||
echo
|
||||
echo "Options:"
|
||||
echo " --on Activate backtrace generation"
|
||||
echo " --off Deactivate backtrace generation"
|
||||
echo
|
||||
echo "That function active a trap event on error. If the script you want to"
|
||||
echo "debug overload the ERR bash trap, it will not work."
|
||||
echo
|
||||
;;
|
||||
"--on")
|
||||
if [[ $status == "on" ]]; then
|
||||
disp W "ERR signal trap is already set, replacing previous trap!"
|
||||
fi
|
||||
trap "error" ERR
|
||||
;;
|
||||
"--off")
|
||||
if [[ $status != "on" ]]; then
|
||||
disp W "ERR signal trap is already unset!"
|
||||
fi
|
||||
trap - ERR
|
||||
;;
|
||||
"--status")
|
||||
disp "ERR trap signal is ${status}."
|
||||
;;
|
||||
esac
|
||||
"-h" | "--help")
|
||||
echo "Try to activate backtrace display for script debugging."
|
||||
echo
|
||||
echo "Options:"
|
||||
echo " --on Activate backtrace generation"
|
||||
echo " --off Deactivate backtrace generation"
|
||||
echo
|
||||
echo "That function active a trap event on error. If the script you want to"
|
||||
echo "debug overload the ERR bash trap, it will not work."
|
||||
echo
|
||||
;;
|
||||
"--on")
|
||||
if [[ $status == "on" ]]; then
|
||||
disp W "ERR signal trap is already set, replacing previous trap!"
|
||||
fi
|
||||
trap "error" ERR
|
||||
;;
|
||||
"--off")
|
||||
if [[ $status != "on" ]]; then
|
||||
disp W "ERR signal trap is already unset!"
|
||||
fi
|
||||
trap - ERR
|
||||
;;
|
||||
"--status")
|
||||
disp "ERR trap signal is ${status}."
|
||||
;;
|
||||
esac
|
||||
done
|
||||
unset status
|
||||
}
|
||||
export -f settrace
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# EOF
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#!/bin/bash
|
||||
# ------------------------------------------------------------------------------
|
||||
# Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
|
||||
# Protected by the BSD3 license. Please read bellow for details.
|
||||
@@ -111,38 +112,40 @@ export On_IPurple='\e[0;105m'
|
||||
export On_ICyan='\e[0;106m'
|
||||
export On_IWhite='\e[0;107m'
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Display a message
|
||||
# ------------------------------------------------------------------------------
|
||||
disp()
|
||||
{
|
||||
case $1 in
|
||||
"I")
|
||||
local heads="[ ${IGreen}info${DEFAULTFG} ]"
|
||||
shift
|
||||
[[ -z $QUIET || $QUIET -ne 1 ]] && echo -e "${heads} $@"
|
||||
;;
|
||||
"W")
|
||||
local heads="[ ${IYellow}Warning${DEFAULTFG} ]"
|
||||
shift
|
||||
echo -e "${heads} $@" >&2
|
||||
;;
|
||||
"E")
|
||||
local heads="[ ${IRed}ERROR${DEFAULTFG} ]"
|
||||
shift
|
||||
echo -e "${heads} $@" >&2
|
||||
;;
|
||||
"D")
|
||||
local heads"[ ${ICyan}debug${DEFAULTFG} ]"
|
||||
shift
|
||||
[[ -n $DEBUG && $DEBUG -gt 1 ]] && echo -e "${heads} $@"
|
||||
;;
|
||||
"*")
|
||||
local heads=""
|
||||
[[ -z $QUIET || $QUIET -ne 1 ]] && echo -e "$@"
|
||||
;;
|
||||
"I")
|
||||
local heads="[ ${IGreen}info${DEFAULTFG} ]"
|
||||
shift
|
||||
[[ -z $QUIET || $QUIET -ne 1 ]] && echo -e "${heads} $@"
|
||||
;;
|
||||
"W")
|
||||
local heads="[ ${IYellow}Warning${DEFAULTFG} ]"
|
||||
shift
|
||||
echo -e "${heads} $@" >&2
|
||||
;;
|
||||
"E")
|
||||
local heads="[ ${IRed}ERROR${DEFAULTFG} ]"
|
||||
shift
|
||||
echo -e "${heads} $@" >&2
|
||||
;;
|
||||
"D")
|
||||
local heads"[ ${ICyan}debug${DEFAULTFG} ]"
|
||||
shift
|
||||
[[ -n $DEBUG && $DEBUG -gt 1 ]] && echo -e "${heads} $@"
|
||||
;;
|
||||
"*")
|
||||
local heads=""
|
||||
[[ -z $QUIET || $QUIET -ne 1 ]] && echo -e "$@"
|
||||
;;
|
||||
esac
|
||||
unset heads
|
||||
}
|
||||
export -f disp
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# EOF
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
# ------------------------------------------------------------------------------
|
||||
# Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
|
||||
# Protected by the BSD3 license. Please read bellow for details.
|
||||
@@ -47,49 +48,48 @@ expandlist()
|
||||
echo $result
|
||||
}
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Clean a directory or a tree from temporary or backup files
|
||||
# ------------------------------------------------------------------------------
|
||||
clean ()
|
||||
clean()
|
||||
{
|
||||
for opt in $@ ; do
|
||||
for opt in $@; do
|
||||
case $opt in
|
||||
"-r"|"--recurs")
|
||||
local recursive=1
|
||||
;;
|
||||
"-r" | "--recurs")
|
||||
local recursive=1
|
||||
;;
|
||||
|
||||
"-h"|"--help")
|
||||
echo "clean: erase backup files in the given directories."
|
||||
echo
|
||||
echo "Usage: clean [option] [directory1] [...[directoryX]]"
|
||||
echo
|
||||
echo "Options:"
|
||||
echo " -h, --help Display that help screen"
|
||||
echo " -r, --recurs Do a recursive cleaning"
|
||||
echo " -f, --force Do not ask for confirmation (use with care)"
|
||||
echo " -s, --shell Do nothing and display what will be executed"
|
||||
echo
|
||||
return 0
|
||||
;;
|
||||
"-h" | "--help")
|
||||
echo "clean: erase backup files in the given directories."
|
||||
echo
|
||||
echo "Usage: clean [option] [directory1] [...[directoryX]]"
|
||||
echo
|
||||
echo "Options:"
|
||||
echo " -h, --help Display that help screen"
|
||||
echo " -r, --recurs Do a recursive cleaning"
|
||||
echo " -f, --force Do not ask for confirmation (use with care)"
|
||||
echo " -s, --shell Do nothing and display what will be executed"
|
||||
echo
|
||||
return 0
|
||||
;;
|
||||
|
||||
"-s"|"--shell")
|
||||
local outshell=1
|
||||
;;
|
||||
"-s" | "--shell")
|
||||
local outshell=1
|
||||
;;
|
||||
|
||||
"-f"|"--force")
|
||||
local force=1
|
||||
;;
|
||||
"-f" | "--force")
|
||||
local force=1
|
||||
;;
|
||||
|
||||
"-"*)
|
||||
disp E "Invalid option, use \"clean --help\" to display usage."
|
||||
echo
|
||||
return 1
|
||||
;;
|
||||
"-"*)
|
||||
disp E "Invalid option, use \"clean --help\" to display usage."
|
||||
echo
|
||||
return 1
|
||||
;;
|
||||
|
||||
*)
|
||||
local dirlist="$dirlist $opt"
|
||||
;;
|
||||
*)
|
||||
local dirlist="$dirlist $opt"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
@@ -100,7 +100,7 @@ clean ()
|
||||
unset recursive force
|
||||
|
||||
for dir in $dirlist; do
|
||||
local dellist=$(find $dir $findopt -type f -name "*~" -o -name "#*#" \
|
||||
local dellist=$(find "$dir" $findopt -type f -name "*~" -o -name "#*#" \
|
||||
-o -name "*.bak" -o -name ".~*#")
|
||||
for f in $dellist; do
|
||||
if [[ ! $outshell ]]; then
|
||||
@@ -114,73 +114,71 @@ clean ()
|
||||
}
|
||||
export -f clean
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Create a directory then goes inside
|
||||
# ------------------------------------------------------------------------------
|
||||
mcd ()
|
||||
mcd()
|
||||
{
|
||||
if [[ ! $# -eq 1 ]] ; then
|
||||
if [[ ! $# -eq 1 ]]; then
|
||||
disp E "Create a directory then goes inside."
|
||||
disp E "Usage: mcd <directory>"
|
||||
return 1
|
||||
fi
|
||||
mkdir -pv $1 && cd $1
|
||||
mkdir -pv "$1" && cd "$1" || echo "Failed create or change directory."
|
||||
}
|
||||
export -f mcd
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Rename all files in current directory to replace spaces with _
|
||||
# ------------------------------------------------------------------------------
|
||||
rmspc ()
|
||||
rmspc()
|
||||
{
|
||||
local lst=""
|
||||
for opt in $@ ; do
|
||||
for opt in $@; do
|
||||
case $opt in
|
||||
"-h"|"--help")
|
||||
echo "rmspc: remove spaces from all filenames in current directories"
|
||||
echo
|
||||
echo "Usage: rmspc [option]"
|
||||
echo
|
||||
echo "Options:"
|
||||
echo " -h, --help Display that help screen"
|
||||
echo " -r, --recursive Treat subdirectories of the given directory"
|
||||
echo " -c, --subst-char Change the replacement character (default is underscore)"
|
||||
echo " -v, --verbose Display more details (recursive mode only)"
|
||||
echo " -s, --shell Do nothing and display commands that would be executed"
|
||||
echo
|
||||
echo "Note: if the --subst-char option is given without parameters, spaces will be"
|
||||
echo " replaced with nothing (concatenation)."
|
||||
echo
|
||||
return 0
|
||||
;;
|
||||
"-h" | "--help")
|
||||
echo "rmspc: remove spaces from all filenames in current directories"
|
||||
echo
|
||||
echo "Usage: rmspc [option]"
|
||||
echo
|
||||
echo "Options:"
|
||||
echo " -h, --help Display that help screen"
|
||||
echo " -r, --recursive Treat subdirectories of the given directory"
|
||||
echo " -c, --subst-char Change the replacement character (default is underscore)"
|
||||
echo " -v, --verbose Display more details (recursive mode only)"
|
||||
echo " -s, --shell Do nothing and display commands that would be executed"
|
||||
echo
|
||||
echo "Note: if the --subst-char option is given without parameters, spaces will be"
|
||||
echo " replaced with nothing (concatenation)."
|
||||
echo
|
||||
return 0
|
||||
;;
|
||||
|
||||
"-r"|"--recursive")
|
||||
local recurs=1
|
||||
;;
|
||||
"-r" | "--recursive")
|
||||
local recurs=1
|
||||
;;
|
||||
|
||||
"-c"?*|"--subst-char"?*)
|
||||
if [[ $(echo $opt | grep "=") ]]; then
|
||||
local substchar=$(echo "$opt" | cut -f 2- -d '=')
|
||||
else
|
||||
local substchar='none'
|
||||
fi
|
||||
;;
|
||||
"-c"?* | "--subst-char"?*)
|
||||
if [[ $(echo $opt | grep "=") ]]; then
|
||||
local substchar=$(echo "$opt" | cut -f 2- -d '=')
|
||||
else
|
||||
local substchar='none'
|
||||
fi
|
||||
;;
|
||||
|
||||
"-v"|"--verbose")
|
||||
local verb=1
|
||||
;;
|
||||
"-v" | "--verbose")
|
||||
local verb=1
|
||||
;;
|
||||
|
||||
"-s"|"--shell")
|
||||
local shell=1
|
||||
;;
|
||||
"-s" | "--shell")
|
||||
local shell=1
|
||||
;;
|
||||
|
||||
*)
|
||||
disp E "Invalid parameter, use \"rmspc --help\" to display options list"
|
||||
echo
|
||||
return 1
|
||||
;;
|
||||
*)
|
||||
disp E "Invalid parameter, use \"rmspc --help\" to display options list"
|
||||
echo
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
@@ -191,14 +189,14 @@ rmspc ()
|
||||
for f in *; do
|
||||
[[ $recurs ]] && [[ -d "$f" ]] && (
|
||||
[[ $verb ]] && disp I "Entering directory $(pwd)/$f ..."
|
||||
local lastdir=$f
|
||||
pushd "$f" > /dev/null
|
||||
local lastdir=$f
|
||||
pushd "$f" >/dev/null
|
||||
rmspc $@
|
||||
popd > /dev/null
|
||||
popd >/dev/null
|
||||
[[ $verb ]] && disp I "Leaving directory $(pwd)/$lastdir"
|
||||
unset lastdir
|
||||
unset lastdir
|
||||
)
|
||||
|
||||
|
||||
if [[ $(echo $f | grep " ") ]]; then
|
||||
local newf="${f// /${substchar}}"
|
||||
local command="mv $mvopt \"$f\" \"$newf\""
|
||||
@@ -209,6 +207,9 @@ rmspc ()
|
||||
fi
|
||||
fi
|
||||
done
|
||||
unset lst substchar verb shell newf command mvopt
|
||||
unset lst substchar verb shell newf command mvopt
|
||||
}
|
||||
export -f rmspc
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# EOF
|
||||
|
||||
52
profile.d/fun.sh
Normal file
52
profile.d/fun.sh
Normal file
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/env bash
|
||||
# ------------------------------------------------------------------------------
|
||||
# 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
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# EOF
|
||||
@@ -1,3 +1,4 @@
|
||||
#!/bin/bash
|
||||
# ------------------------------------------------------------------------------
|
||||
# Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
|
||||
# Protected by the BSD3 license. Please read bellow for details.
|
||||
@@ -66,3 +67,5 @@ EOF
|
||||
}
|
||||
export -f help
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# EOF
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#!/bin/bash
|
||||
# ------------------------------------------------------------------------------
|
||||
# Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
|
||||
# Protected by the BSD3 license. Please read bellow for details.
|
||||
@@ -36,17 +37,16 @@
|
||||
# ------------------------------------------------------------------------------
|
||||
# Show profile version
|
||||
# ------------------------------------------------------------------------------
|
||||
ver ()
|
||||
ver()
|
||||
{
|
||||
disp "Profile version $PROFVERSION."
|
||||
}
|
||||
export -f ver
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Display weather of the given city (or default one)
|
||||
# ------------------------------------------------------------------------------
|
||||
meteo ()
|
||||
meteo()
|
||||
{
|
||||
cities=$@
|
||||
[[ $# -eq 0 ]] && local cities=$DEFAULT_CITY
|
||||
@@ -57,34 +57,36 @@ meteo ()
|
||||
}
|
||||
export -f meteo
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Display system general information
|
||||
# ------------------------------------------------------------------------------
|
||||
showinfo()
|
||||
{
|
||||
echo -e "\n"
|
||||
if command -v figlet >/dev/null 2>&1; then
|
||||
if [[ -s /usr/share/figlet/ansi_shadow.flf ]]; then
|
||||
local figopt="-f ansi_shadow"
|
||||
fi
|
||||
figlet -k $(hostname) $figopt
|
||||
if command -v figlet >/dev/null 2>&1; then
|
||||
if [[ -s /usr/share/figlet/ansi_shadow.flf ]]; then
|
||||
local figopt="-f ansi_shadow"
|
||||
fi
|
||||
figlet -k $(hostname) $figopt
|
||||
else
|
||||
echo "$(hostname -f)"
|
||||
echo "$(hostname -f)"
|
||||
fi
|
||||
echo ""
|
||||
if command -v neofetch >/dev/null 2>&1; then
|
||||
neofetch
|
||||
neofetch
|
||||
else
|
||||
(
|
||||
if [[ -s /etc/os-release ]]; then
|
||||
. /etc/os-release
|
||||
echo "$NAME $VERSION"
|
||||
else
|
||||
cat /proc/version
|
||||
fi
|
||||
echo "Uptime: $(uptime)"
|
||||
)
|
||||
(
|
||||
if [[ -s /etc/os-release ]]; then
|
||||
. /etc/os-release
|
||||
echo "$NAME $VERSION"
|
||||
else
|
||||
cat /proc/version
|
||||
fi
|
||||
echo "Uptime: $(uptime)"
|
||||
)
|
||||
fi
|
||||
}
|
||||
export -f showinfo
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# EOF
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#!/bin/bash
|
||||
# ------------------------------------------------------------------------------
|
||||
# Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
|
||||
# Protected by the BSD3 license. Please read bellow for details.
|
||||
@@ -36,7 +37,7 @@
|
||||
# ------------------------------------------------------------------------------
|
||||
# Change locale to French
|
||||
# ------------------------------------------------------------------------------
|
||||
setfr ()
|
||||
setfr()
|
||||
{
|
||||
# Set fr locale definitions
|
||||
export LANG=fr_FR.UTF-8
|
||||
@@ -48,7 +49,7 @@ export -f setfr
|
||||
# ------------------------------------------------------------------------------
|
||||
# Change locale to C standard
|
||||
# ------------------------------------------------------------------------------
|
||||
setc ()
|
||||
setc()
|
||||
{
|
||||
# Locale definitions
|
||||
export LANG=C
|
||||
@@ -60,7 +61,7 @@ export -f setc
|
||||
# ------------------------------------------------------------------------------
|
||||
# Change locale to US (needed by Steam)
|
||||
# ------------------------------------------------------------------------------
|
||||
setus ()
|
||||
setus()
|
||||
{
|
||||
# Locale definitions
|
||||
export LANG=en_US.UTF-8
|
||||
@@ -68,3 +69,6 @@ setus ()
|
||||
export LC_ALL=en_US.UTF-8
|
||||
}
|
||||
export -f setus
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# EOF
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#!/bin/bash
|
||||
# ------------------------------------------------------------------------------
|
||||
# Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
|
||||
# Protected by the BSD3 license. Please read bellow for details.
|
||||
@@ -36,49 +37,51 @@
|
||||
# ------------------------------------------------------------------------------
|
||||
# Determine if parameter is a valid IPv4 address
|
||||
# ------------------------------------------------------------------------------
|
||||
isipv4 ()
|
||||
isipv4()
|
||||
{
|
||||
# Set up local variables
|
||||
local ip=$1
|
||||
local ip=$1
|
||||
|
||||
# Start with a regex format test
|
||||
if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
|
||||
local old_ifs=$IFS
|
||||
IFS="."
|
||||
ip=($ip)
|
||||
IFS=$old_ifs
|
||||
if [[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \
|
||||
&& ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]; then
|
||||
if [[ -t 1 ]]; then
|
||||
disp "The given IPv4 is valid."
|
||||
fi
|
||||
return 0
|
||||
fi
|
||||
local old_ifs=$IFS
|
||||
IFS="."
|
||||
ip=($ip)
|
||||
IFS=$old_ifs
|
||||
if [[ ${ip[0]} -le 255 && ${ip[1]} -le 255 &&
|
||||
${ip[2]} -le 255 && ${ip[3]} -le 255 ]]; then
|
||||
if [[ -t 1 ]]; then
|
||||
disp "The given IPv4 is valid."
|
||||
fi
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
if [[ -t 1 ]]; then
|
||||
disp "The given parameter is NOT a valid IPv4."
|
||||
disp "The given parameter is NOT a valid IPv4."
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
export -f isipv4
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Determine if parameter is a valid IPv4 address
|
||||
# ------------------------------------------------------------------------------
|
||||
isipv6 ()
|
||||
isipv6()
|
||||
{
|
||||
local ip="$1"
|
||||
local regex='^([0-9a-fA-F]{0,4}:){1,7}[0-9a-fA-F]{0,4}$'
|
||||
if [[ $ip =~ $regex ]]; then
|
||||
if [[ -t 1 ]]; then
|
||||
disp "The given IPv6 is valid."
|
||||
fi
|
||||
return 0
|
||||
if [[ -t 1 ]]; then
|
||||
disp "The given IPv6 is valid."
|
||||
fi
|
||||
return 0
|
||||
fi
|
||||
if [[ -t 1 ]]; then
|
||||
disp "The given parameter is not a valid IPv6."
|
||||
disp "The given parameter is not a valid IPv6."
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
export -f isipv6
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# EOF
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#!/bin/bash
|
||||
# ------------------------------------------------------------------------------
|
||||
# Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
|
||||
# Protected by the BSD3 license. Please read bellow for details.
|
||||
@@ -36,45 +37,47 @@
|
||||
# ------------------------------------------------------------------------------
|
||||
# Look for a package within installed one
|
||||
# ------------------------------------------------------------------------------
|
||||
dpkgs ()
|
||||
pkgs()
|
||||
{
|
||||
local count=0
|
||||
for opt in $@ ; do
|
||||
for opt in $@; do
|
||||
case $opt in
|
||||
"-h"|"--help")
|
||||
echo "dpkgs: look for an installed package by it's name."
|
||||
echo
|
||||
echo "Usage: dpkgs <string>"
|
||||
return 0
|
||||
;;
|
||||
"-h" | "--help")
|
||||
echo "dpkgs: look for an installed package by it's name."
|
||||
echo
|
||||
echo "Usage: dpkgs <string>"
|
||||
return 0
|
||||
;;
|
||||
|
||||
"-"*)
|
||||
disp E "Invalid option, use \"dpkgs --help\" to display usage."
|
||||
echo
|
||||
"-"*)
|
||||
disp E "Invalid option, use \"dpkgs --help\" to display usage."
|
||||
echo
|
||||
return 1
|
||||
;;
|
||||
|
||||
*)
|
||||
local pkg=$1 && shift
|
||||
count=$(($count + 1))
|
||||
[[ $count -gt 1 ]] &&
|
||||
disp E "Please specify a package name, without space, eventually partial." &&
|
||||
return 1
|
||||
;;
|
||||
|
||||
*)
|
||||
local pkg=$1 && shift
|
||||
count=$(( $count + 1 ))
|
||||
[[ $count -gt 1 ]] &&
|
||||
disp E "Please specify a package name, without space, eventually partial." &&
|
||||
return 1
|
||||
|
||||
;;
|
||||
;;
|
||||
esac
|
||||
done
|
||||
[[ $count -lt 1 ]] &&
|
||||
disp E "Please specify a package name, without space, eventually partial." &&
|
||||
return 1
|
||||
|
||||
if [[ $(command -v dpkg >/dev/null 2>&1) ]]; then
|
||||
dpkg -l | grep $pkg
|
||||
elif [[ $(command -v rpm >/dev/null 2>&1) ]]; then
|
||||
rpm -qa | grep $pkg
|
||||
else
|
||||
disp E "No usable package manager seems unavialable."
|
||||
return 2
|
||||
command -v dpkg >/dev/null 2>&1 && local cmd="dpkg -l"
|
||||
command -v rpm >/dev/null 2>&1 && local cmd="rpm -qa"
|
||||
if [[ -z $cmd ]]; then
|
||||
disp E "No usable package manager seems unavialable."
|
||||
return 2
|
||||
fi
|
||||
$cmd | grep $pkg
|
||||
}
|
||||
export -f dpkgs
|
||||
export -f pkgs
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# EOF
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#!/bin/bash
|
||||
# ------------------------------------------------------------------------------
|
||||
# Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
|
||||
# Protected by the BSD3 license. Please read bellow for details.
|
||||
@@ -36,17 +37,16 @@
|
||||
# ------------------------------------------------------------------------------
|
||||
# Search processes matching the given string
|
||||
# ------------------------------------------------------------------------------
|
||||
ppg ()
|
||||
ppg()
|
||||
{
|
||||
ps -edf | grep $@ | grep -v "grep $@"
|
||||
ps -edf | grep "$@" | grep -v "grep $@"
|
||||
}
|
||||
export -f ppg
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Get PID list of the given process name
|
||||
# ------------------------------------------------------------------------------
|
||||
gpid ()
|
||||
gpid()
|
||||
{
|
||||
[[ $UID -eq 0 ]] && local psopt="-A"
|
||||
[[ $# -eq 1 ]] && local single=1
|
||||
@@ -62,14 +62,33 @@ gpid ()
|
||||
}
|
||||
export -f gpid
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Kill all processes owned by the given users
|
||||
# ------------------------------------------------------------------------------
|
||||
ku ()
|
||||
ku()
|
||||
{
|
||||
for u in $@; do
|
||||
killall -u $u
|
||||
killall -u "$u"
|
||||
done
|
||||
}
|
||||
export -f ku
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Kill all children of a process then the process
|
||||
# ------------------------------------------------------------------------------
|
||||
kt()
|
||||
{
|
||||
[[ -z $1 ]] && echo -e "Usage:\n\tkt <pid> [kill_options]"
|
||||
|
||||
local parent_pid="$1" children_pids
|
||||
shift
|
||||
children_pids=$(pgrep -P "$parent_pid")
|
||||
|
||||
for pid in $children_pids; do
|
||||
kill_tree "$pid" "$@"
|
||||
done
|
||||
kill "$@" "$parent_pid"
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# EOF
|
||||
|
||||
@@ -76,7 +76,7 @@ function timer_stop
|
||||
# ------------------------------------------------------------------------------
|
||||
# Function triguered internaly by bash : defining prompt
|
||||
# ------------------------------------------------------------------------------
|
||||
set_prompt ()
|
||||
set_prompt()
|
||||
{
|
||||
Last_Command=$? # Must come first!
|
||||
Blue='\[\e[0;34m\]'
|
||||
@@ -123,3 +123,6 @@ set_prompt ()
|
||||
# the text color to the default.
|
||||
PS1+="$ICyan\\w \\\$$Default "
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# EOF
|
||||
|
||||
257
profile.d/pwd.sh
257
profile.d/pwd.sh
@@ -1,3 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
# ------------------------------------------------------------------------------
|
||||
# Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
|
||||
# Protected by the BSD3 license. Please read bellow for details.
|
||||
@@ -44,143 +45,145 @@ genpwd()
|
||||
local occurs=2 # Bug, if set to 1, seems to be ignored
|
||||
local symb=1 maj=1 min=1 numb=1
|
||||
local nbpwd=1
|
||||
|
||||
|
||||
for opt in $@; do
|
||||
case $opt in
|
||||
"-h"|"--help")
|
||||
echo "genpwd: generate one or more secure random password."
|
||||
echo
|
||||
echo "Usage: genpwd [options] [--extracars=<cars>] [--length=<n>] [nb_passwd]"
|
||||
echo
|
||||
echo "Options:"
|
||||
echo " -h, --help Display that help screen"
|
||||
echo " -s, --nosymbols Exclude symbols"
|
||||
echo " -n, --nonumbers Exclude numbers"
|
||||
echo " -u, --noup Exclude uppercase letters"
|
||||
echo " -l, --nolow Exclude lowercase letters"
|
||||
echo " -e=<c>, --extracars=<c>"
|
||||
echo " Add the given caracters to the possible caracter list"
|
||||
echo " -L=<n>, --length=<n>"
|
||||
echo " Set length of the password (default is $length)"
|
||||
echo " -o=<n>, --occurences=<n>"
|
||||
echo " Set the maximum occurences of a same caracter (default is $occurs)"
|
||||
echo
|
||||
echo "If the --extracars parameter is given, at least one of the given caracter will"
|
||||
echo "be used in the final password."
|
||||
echo
|
||||
echo "Please note that some caracters might be interpreted by Bash or Awk programs,"
|
||||
echo "and thus, cannot be used without provoquing errors. Those identified caracters"
|
||||
echo "are :"
|
||||
echo ' * ? \ $ { }'
|
||||
echo
|
||||
return 0
|
||||
;;
|
||||
"-s"|"--nosymbols")
|
||||
symb=0
|
||||
;;
|
||||
"-n"|"--nonumbers")
|
||||
numb=0
|
||||
;;
|
||||
"-u"|"--noup")
|
||||
maj=0
|
||||
;;
|
||||
"-l"|"--nolow")
|
||||
min=0
|
||||
;;
|
||||
"-e"?*|"--extracars"?*)
|
||||
local extcar=$(echo "$opt" | cut -f 2- -d '=')
|
||||
;;
|
||||
"-L"?*|"--length"?*)
|
||||
local length=$(echo "$opt" | cut -f 2- -d '=')
|
||||
if ! [[ $length =~ ^[0-9]+$ ]]; then
|
||||
disp E "The --length parameter requires a number."
|
||||
return 1
|
||||
fi
|
||||
;;
|
||||
"-o"?*|"--occurences"?*)
|
||||
local occurs=$(echo "$opt" | cut -f 2- -d '=')
|
||||
if ! [[ $occurs =~ ^[1-9]+$ ]]; then
|
||||
disp E "The --occurs parameter requires a number from 1 to 9."
|
||||
return 1
|
||||
fi
|
||||
;;
|
||||
"-*")
|
||||
disp E "Unknow parameter ${opt}."
|
||||
return 1
|
||||
;;
|
||||
*)
|
||||
if ! [[ $opt =~ ^[1-9]+$ ]]; then
|
||||
disp E "Unknow parameter ${opt}."
|
||||
return 1
|
||||
else
|
||||
local nbpwd=$opt
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
case $opt in
|
||||
"-h" | "--help")
|
||||
echo "genpwd: generate one or more secure random password."
|
||||
echo
|
||||
echo "Usage: genpwd [options] [--extracars=<cars>] [--length=<n>] [nb_passwd]"
|
||||
echo
|
||||
echo "Options:"
|
||||
echo " -h, --help Display that help screen"
|
||||
echo " -s, --nosymbols Exclude symbols"
|
||||
echo " -n, --nonumbers Exclude numbers"
|
||||
echo " -u, --noup Exclude uppercase letters"
|
||||
echo " -l, --nolow Exclude lowercase letters"
|
||||
echo " -e=<c>, --extracars=<c>"
|
||||
echo " Add the given caracters to the possible caracter list"
|
||||
echo " -L=<n>, --length=<n>"
|
||||
echo " Set length of the password (default is $length)"
|
||||
echo " -o=<n>, --occurences=<n>"
|
||||
echo " Set the maximum occurences of a same caracter (default is $occurs)"
|
||||
echo
|
||||
echo "If the --extracars parameter is given, at least one of the given caracter will"
|
||||
echo "be used in the final password."
|
||||
echo
|
||||
echo "Please note that some caracters might be interpreted by Bash or Awk programs,"
|
||||
echo "and thus, cannot be used without provoquing errors. Those identified caracters"
|
||||
echo "are :"
|
||||
echo ' * ? \ $ { }'
|
||||
echo
|
||||
return 0
|
||||
;;
|
||||
"-s" | "--nosymbols")
|
||||
symb=0
|
||||
;;
|
||||
"-n" | "--nonumbers")
|
||||
numb=0
|
||||
;;
|
||||
"-u" | "--noup")
|
||||
maj=0
|
||||
;;
|
||||
"-l" | "--nolow")
|
||||
min=0
|
||||
;;
|
||||
"-e"?* | "--extracars"?*)
|
||||
local extcar=$(echo "$opt" | cut -f 2- -d '=')
|
||||
;;
|
||||
"-L"?* | "--length"?*)
|
||||
local length=$(echo "$opt" | cut -f 2- -d '=')
|
||||
if ! [[ $length =~ ^[0-9]+$ ]]; then
|
||||
disp E "The --length parameter requires a number."
|
||||
return 1
|
||||
fi
|
||||
;;
|
||||
"-o"?* | "--occurences"?*)
|
||||
local occurs=$(echo "$opt" | cut -f 2- -d '=')
|
||||
if ! [[ $occurs =~ ^[1-9]+$ ]]; then
|
||||
disp E "The --occurs parameter requires a number from 1 to 9."
|
||||
return 1
|
||||
fi
|
||||
;;
|
||||
"-*")
|
||||
disp E "Unknow parameter ${opt}."
|
||||
return 1
|
||||
;;
|
||||
*)
|
||||
if ! [[ $opt =~ ^[1-9]+$ ]]; then
|
||||
disp E "Unknow parameter ${opt}."
|
||||
return 1
|
||||
else
|
||||
local nbpwd=$opt
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Function selecting a random caracter from the list in parameter
|
||||
pickcar()
|
||||
{
|
||||
# When a character is picked we check if it's not appearing already twice
|
||||
# elsewhere, we choose an other char, to compensate weak bash randomizer
|
||||
while [[ -z $char ]]; do
|
||||
local char=$(echo ${1:RANDOM%${#1}:1} $RANDOM)
|
||||
if [[ $(awk -F"$char" '{print NF-1}' <<< "$picked") -gt $occurs ]]; then
|
||||
unset char
|
||||
fi
|
||||
done
|
||||
picked+="$char"
|
||||
echo "$char"
|
||||
pickcar() {
|
||||
# When a character is picked we check if it's not appearing already twice
|
||||
# elsewhere, we choose an other char, to compensate weak bash randomizer
|
||||
while [[ -z $char ]]; do
|
||||
local char="${1:RANDOM%${#1}:1} $RANDOM"
|
||||
if [[ $(awk -F"$char" '{print NF-1}' <<<"$picked") -gt $occurs ]]; then
|
||||
unset char
|
||||
fi
|
||||
done
|
||||
picked+="$char"
|
||||
echo "$char"
|
||||
}
|
||||
|
||||
disp I "Generating $nbpwd passwords, please wait..."
|
||||
for n in $( seq 1 $nbpwd ); do
|
||||
{
|
||||
local carset='' # store final caracter set to use
|
||||
local picked='' # store already used caracter
|
||||
local rlength=0 # store already assigned length of caracters
|
||||
for n in $(seq 1 $nbpwd); do
|
||||
{
|
||||
local carset='' # store final caracter set to use
|
||||
local picked='' # store already used caracter
|
||||
local rlength=0 # store already assigned length of caracters
|
||||
|
||||
# ?, *, $ and \ impossible to use to my knowledge as it would be interpreted
|
||||
if [[ $symb == 1 ]]; then
|
||||
pickcar '!.@#&%/^-_'
|
||||
carset+='!.@#&%/^-_'
|
||||
(( rlength++ ))
|
||||
fi
|
||||
if [[ $numb == 1 ]]; then
|
||||
pickcar '0123456789'
|
||||
carset+='0123456789'
|
||||
(( rlength++ ))
|
||||
fi
|
||||
if [[ $maj == 1 ]]; then
|
||||
pickcar 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
||||
carset+='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
||||
(( rlength++ ))
|
||||
fi
|
||||
if [[ $min == 1 ]]; then
|
||||
pickcar 'abcdefghijklmnopqrstuvwxyz'
|
||||
carset+='abcdefghijklmnopqrstuvwxyz'
|
||||
(( rlength++ ))
|
||||
fi
|
||||
if [[ -n $extcar ]]; then
|
||||
pickcar "$extcar"
|
||||
carset+=$extcar
|
||||
(( rlength++ ))
|
||||
fi
|
||||
# ?, *, $ and \ impossible to use to my knowledge as it would be interpreted
|
||||
if [[ $symb == 1 ]]; then
|
||||
pickcar '!.@#&%/^-_'
|
||||
carset+='!.@#&%/^-_'
|
||||
((rlength++))
|
||||
fi
|
||||
if [[ $numb == 1 ]]; then
|
||||
pickcar '0123456789'
|
||||
carset+='0123456789'
|
||||
((rlength++))
|
||||
fi
|
||||
if [[ $maj == 1 ]]; then
|
||||
pickcar 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
||||
carset+='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
||||
((rlength++))
|
||||
fi
|
||||
if [[ $min == 1 ]]; then
|
||||
pickcar 'abcdefghijklmnopqrstuvwxyz'
|
||||
carset+='abcdefghijklmnopqrstuvwxyz'
|
||||
((rlength++))
|
||||
fi
|
||||
if [[ -n $extcar ]]; then
|
||||
pickcar "$extcar"
|
||||
carset+=$extcar
|
||||
((rlength++))
|
||||
fi
|
||||
|
||||
# Check if we have enough car to have something viable
|
||||
if [[ ${#carset} -lt $length ]]; then
|
||||
disp E 'Not enought caracters are authorised for the password length.'
|
||||
disp E 'Please allow more caracter (preferably) or reduce password lentgh.'
|
||||
return 1
|
||||
fi
|
||||
# Check if we have enough car to have something viable
|
||||
if [[ ${#carset} -lt $length ]]; then
|
||||
disp E 'Not enought caracters are authorised for the password length.'
|
||||
disp E 'Please allow more caracter (preferably) or reduce password lentgh.'
|
||||
return 1
|
||||
fi
|
||||
|
||||
for i in $( seq 1 $(( $length - $rlength )) ); do
|
||||
pickcar "$carset"
|
||||
done
|
||||
} | sort -R | awk '{printf "%s", $1}'
|
||||
unset picked carset rlength
|
||||
echo
|
||||
for i in $(seq 1 $(($length - $rlength))); do
|
||||
pickcar "$carset"
|
||||
done
|
||||
} | sort -R | awk '{printf "%s", $1}'
|
||||
unset picked carset rlength
|
||||
echo
|
||||
done
|
||||
}
|
||||
export -f genpwd
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# EOF
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
# ------------------------------------------------------------------------------
|
||||
# Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
|
||||
# Protected by the BSD3 license. Please read bellow for details.
|
||||
@@ -43,7 +44,7 @@ rain()
|
||||
local rain_colors=("\e[37m" "\e[37;1m")
|
||||
# More from 256 color mode
|
||||
for i in {244..255}; do
|
||||
rain_colors=( "${rain_colors[@]}" "\e[38;5;${i}m" )
|
||||
rain_colors=("${rain_colors[@]}" "\e[38;5;${i}m")
|
||||
done
|
||||
local rain_tab=${#rain_cars[@]}
|
||||
local rain_color_tab=${#rain_colors[@]}
|
||||
@@ -54,18 +55,17 @@ rain()
|
||||
local X=0 Y=0 drop_length=0 rain_drop=0
|
||||
local max_rain_width=0 new_rain_odd=0 falling_odd=0
|
||||
|
||||
|
||||
sigwinch() {
|
||||
term_width=$(tput cols)
|
||||
term_height=$(tput lines)
|
||||
#step_duration=0.025
|
||||
(( max_rain_width = term_width * term_height / 4 ))
|
||||
(( max_rain_height = term_height < 10 ? 1 : term_height / 10 ))
|
||||
((max_rain_width = term_width * term_height / 4))
|
||||
((max_rain_height = term_height < 10 ? 1 : term_height / 10))
|
||||
# In percentage
|
||||
(( new_rain_odd = term_height > 50 ? 100 : term_height * 2 ))
|
||||
(( new_rain_odd = new_rain_odd * 75 / 100 ))
|
||||
(( falling_odd = term_height > 25 ? 100 : term_height * 4 ))
|
||||
(( falling_odd = falling_odd * 90 / 100 ))
|
||||
((new_rain_odd = term_height > 50 ? 100 : term_height * 2))
|
||||
((new_rain_odd = new_rain_odd * 75 / 100))
|
||||
((falling_odd = term_height > 25 ? 100 : term_height * 4))
|
||||
((falling_odd = falling_odd * 90 / 100))
|
||||
}
|
||||
|
||||
do_exit() {
|
||||
@@ -80,19 +80,19 @@ rain()
|
||||
Y=${rains[idx + 1]}
|
||||
drop_length=${rains[idx + 4]}
|
||||
for ((y = Y; y < Y + drop_length; y++)); do
|
||||
(( y < 1 || y > term_height )) && continue
|
||||
((y < 1 || y > term_height)) && continue
|
||||
echo -ne "\e[${y};${X}H "
|
||||
done
|
||||
done
|
||||
|
||||
for ((idx = 0; idx < num_rains * num_rain_metadata; idx += num_rain_metadata)); do
|
||||
if (( 100 * RANDOM / 32768 < falling_odd )); then
|
||||
if ((100 * RANDOM / 32768 < falling_odd)); then
|
||||
# Falling
|
||||
if (( ++rains[idx + 1] > term_height )); then
|
||||
if ((++rains[idx + 1] > term_height)); then
|
||||
# Out of screen, bye sweet <3
|
||||
rains=("${rains[@]:0:idx}"
|
||||
"${rains[@]:idx+num_rain_metadata:num_rains*num_rain_metadata}")
|
||||
(( num_rains-- ))
|
||||
((num_rains--))
|
||||
continue
|
||||
fi
|
||||
fi
|
||||
@@ -102,7 +102,7 @@ rain()
|
||||
drop_color=${rains[idx + 3]}
|
||||
drop_length=${rains[idx + 4]}
|
||||
for ((y = Y; y < Y + drop_length; y++)); do
|
||||
(( y < 1 || y > term_height )) && continue
|
||||
((y < 1 || y > term_height)) && continue
|
||||
echo -ne "\e[${y};${X}H${drop_color}${rain_drop}"
|
||||
done
|
||||
done
|
||||
@@ -118,24 +118,24 @@ rain()
|
||||
local rains=()
|
||||
local num_rains=0
|
||||
sigwinch
|
||||
while (( exit_st <= 0 )); do
|
||||
if (( $exit_st <=0 )); then
|
||||
while ((exit_st <= 0)); do
|
||||
if (($exit_st <= 0)); then
|
||||
read -n 1 -t $step_duration ch
|
||||
case "$ch" in
|
||||
q|Q)
|
||||
do_exit
|
||||
q | Q)
|
||||
do_exit
|
||||
;;
|
||||
esac
|
||||
|
||||
if (( num_rains < max_rain_width )) && (( 100 * RANDOM / 32768 < new_rain_odd )); then
|
||||
if ((num_rains < max_rain_width)) && ((100 * RANDOM / 32768 < new_rain_odd)); then
|
||||
# Need new |, 1-based
|
||||
rain_drop="${rain_cars[rain_tab * RANDOM / 32768]}"
|
||||
drop_color="${rain_colors[rain_color_tab * RANDOM / 32768]}"
|
||||
drop_length=$(( max_rain_height * RANDOM / 32768 + 1 ))
|
||||
X=$(( term_width * RANDOM / 32768 + 1 ))
|
||||
Y=$(( 1 - drop_length ))
|
||||
rains=( "${rains[@]}" "$X" "$Y" "$rain_drop" "$drop_color" "$drop_length" )
|
||||
(( num_rains++ ))
|
||||
drop_length=$((max_rain_height * RANDOM / 32768 + 1))
|
||||
X=$((term_width * RANDOM / 32768 + 1))
|
||||
Y=$((1 - drop_length))
|
||||
rains=("${rains[@]}" "$X" "$Y" "$rain_drop" "$drop_color" "$drop_length")
|
||||
((num_rains++))
|
||||
fi
|
||||
|
||||
# Let rain fall!
|
||||
@@ -152,3 +152,6 @@ rain()
|
||||
trap - WINCH
|
||||
}
|
||||
export -f rain
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# EOF
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
# ------------------------------------------------------------------------------
|
||||
# Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
|
||||
# Protected by the BSD3 license. Please read bellow for details.
|
||||
@@ -36,61 +37,60 @@
|
||||
# ------------------------------------------------------------------------------
|
||||
# Remove host from know_host (name and IP) for the active user
|
||||
# ------------------------------------------------------------------------------
|
||||
rmhost ()
|
||||
rmhost()
|
||||
{
|
||||
if [[ "$#" -lt 1 ]]; then
|
||||
disp E "Incorrect number of parameters."
|
||||
disp E "Usage: rmhost <hostname|ip> [hostname2|ip2 [...]]"
|
||||
return 1
|
||||
fi
|
||||
|
||||
|
||||
while [[ $1 ]]; do
|
||||
local hst=$1 && shift
|
||||
isipv4 $hst > /dev/null
|
||||
local v4=$?
|
||||
isipv6 $hst > /dev/null
|
||||
local v6=$?
|
||||
|
||||
if [[ $v4 -eq 0 || $v6 -eq 0 ]]; then
|
||||
local ip=$hst
|
||||
unset hst
|
||||
fi
|
||||
unset v4 v6
|
||||
|
||||
if [[ ! $ip && $hst ]]; then
|
||||
ip=$(host $hst | grep "has address" | awk '{print $NF}')
|
||||
[[ ! $? ]] &&
|
||||
disp E "Impossible to extract IP from hostname." &&
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [[ $hst ]]; then
|
||||
disp I "Removing host $hst from ssh known_host..."
|
||||
ssh-keygen -R $hst > /dev/null
|
||||
fi
|
||||
if [[ $ip ]]; then
|
||||
disp I "Removing IP $ip from ssh known_host..."
|
||||
ssh-keygen -R $ip > /dev/null
|
||||
fi
|
||||
unset hst ip
|
||||
local hst=$1 && shift
|
||||
isipv4 $hst >/dev/null
|
||||
local v4=$?
|
||||
isipv6 $hst >/dev/null
|
||||
local v6=$?
|
||||
|
||||
if [[ $v4 -eq 0 || $v6 -eq 0 ]]; then
|
||||
local ip=$hst
|
||||
unset hst
|
||||
fi
|
||||
unset v4 v6
|
||||
|
||||
if [[ ! $ip && $hst ]]; then
|
||||
ip=$(host $hst | grep "has address" | awk '{print $NF}')
|
||||
[[ ! $? ]] &&
|
||||
disp E "Impossible to extract IP from hostname." &&
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [[ $hst ]]; then
|
||||
disp I "Removing host $hst from ssh known_host..."
|
||||
ssh-keygen -R $hst >/dev/null
|
||||
fi
|
||||
if [[ $ip ]]; then
|
||||
disp I "Removing IP $ip from ssh known_host..."
|
||||
ssh-keygen -R $ip >/dev/null
|
||||
fi
|
||||
unset hst ip
|
||||
done
|
||||
}
|
||||
export -f rmhost
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Login root via SSH on the given machine
|
||||
# ------------------------------------------------------------------------------
|
||||
ssr ()
|
||||
ssr()
|
||||
{
|
||||
for opt in $@ ; do
|
||||
for opt in $@; do
|
||||
case $opt in
|
||||
"-h"|"--help")
|
||||
echo "ssr: do a root user ssh login."
|
||||
echo
|
||||
echo "Usage: ssr <server [ssh options]>"
|
||||
return 0
|
||||
;;
|
||||
"-h" | "--help")
|
||||
echo "ssr: do a root user ssh login."
|
||||
echo
|
||||
echo "Usage: ssr <server [ssh options]>"
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
@@ -103,3 +103,6 @@ ssr ()
|
||||
ssh -Y root@$srv $@
|
||||
}
|
||||
export -f ssr
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# EOF
|
||||
|
||||
102
profile.d/updates.sh
Normal file
102
profile.d/updates.sh
Normal file
@@ -0,0 +1,102 @@
|
||||
#!/usr/bin/env bash
|
||||
# ------------------------------------------------------------------------------
|
||||
# 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.
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
export UPDT_URL="https://git.geoffray-levasseur.org/fatalerrors/profile/raw/branch/master"
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Check for profile updates
|
||||
# ------------------------------------------------------------------------------
|
||||
check_updates()
|
||||
{
|
||||
if [[ $1 == "-q" ]]; then
|
||||
# Quiet mode is mostly used internally when profile_upgrade is called
|
||||
quiet=1
|
||||
fi
|
||||
disp I "Checking for updates..."
|
||||
local vfile="/tmp/version"
|
||||
wget "$UPDT_URL/version" -O $vfile >/dev/null 2>&1 || {
|
||||
disp E "Can't download version file, impossible to proceed!"
|
||||
return 5
|
||||
}
|
||||
|
||||
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."
|
||||
[[ $quiet ]] && disp I "You should upgrade to last version when possible."
|
||||
result=0
|
||||
else
|
||||
disp I "Your version is up-to-date."
|
||||
result=1
|
||||
fi
|
||||
rm -f $vfile
|
||||
else
|
||||
disp E "Impossible to read temporary file, impossible to proceed."
|
||||
fi
|
||||
unset lastver vfile
|
||||
return $result
|
||||
}
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Apply update to profile
|
||||
# ------------------------------------------------------------------------------
|
||||
profile_upgrade()
|
||||
{
|
||||
if [[ $(check_updates -q) -eq 0 ]]; then
|
||||
if [[ -s $MYPATH/profile.sh ]]; then
|
||||
disp E "Installation path detection failed, cannot upgrade automatically."
|
||||
return 1
|
||||
fi
|
||||
if [[ -d $MYPATH/.git ]]; then
|
||||
disp I "Git installation detected, applying git pull."
|
||||
local curdir=$(pwd)
|
||||
cd $MYPATH
|
||||
git pull
|
||||
if [[ $? -ne 0 ]]; then
|
||||
disp E "Git pull failed, upgrade not applyed."
|
||||
else
|
||||
disp I "Successfully upgraded using git."
|
||||
disp I "You should now logout and login again to enjoy new profile."
|
||||
cd $curdir
|
||||
fi
|
||||
else
|
||||
disp I "Applying traditionnal upgrade..."
|
||||
# TODO
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# EOF
|
||||
53
profile.sh
53
profile.sh
@@ -35,11 +35,7 @@
|
||||
# * OF SUCH DAMAGE.
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
export PROFVERSION="3.2.2"
|
||||
|
||||
export DEFAULT_CITY="Toulouse"
|
||||
|
||||
if [[ ! $(echo $SHELL | grep bash) ]]; then
|
||||
if [[ ! $SHELL =~ bash|zsh ]]; then
|
||||
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 ;)!"
|
||||
return 1
|
||||
@@ -48,49 +44,71 @@ fi
|
||||
# ------------------------------------------------------------------------------
|
||||
# path* : private functions for PATH variable management
|
||||
# ------------------------------------------------------------------------------
|
||||
pathremove ()
|
||||
pathremove()
|
||||
{
|
||||
local ifs=':'
|
||||
local newpath
|
||||
local dir
|
||||
local pathvar=${2:-PATH}
|
||||
for dir in ${!pathvar} ; do
|
||||
if [ "$dir" != "$1" ] ; then
|
||||
for dir in ${!pathvar}; do
|
||||
if [ "$dir" != "$1" ]; then
|
||||
newpath=${newpath:+$newpath:}$dir
|
||||
fi
|
||||
done
|
||||
export $pathvar="$newpath"
|
||||
}
|
||||
|
||||
pathprepend ()
|
||||
pathprepend()
|
||||
{
|
||||
pathremove $1 $2
|
||||
local pathvar=${2:-PATH}
|
||||
export $pathvar="$1${!pathvar:+:${!pathvar}}"
|
||||
}
|
||||
|
||||
pathappend ()
|
||||
pathappend()
|
||||
{
|
||||
pathremove $1 $2
|
||||
local pathvar=${2:-PATH}
|
||||
export $pathvar="${!pathvar:+${!pathvar}:}$1"
|
||||
}
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# ------------------------------------------------------------------------------
|
||||
# ********************************** MAIN PROGRAM ******************************
|
||||
# ------------------------------------------------------------------------------
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
# Store script's path (realpath -s resolve symlinks if profile.sh is a symlink)
|
||||
if [[ -z $PROFILE_PATH ]]; then
|
||||
export MYPATH=$(dirname $(realpath -s $0))
|
||||
else
|
||||
export MYPATH=$PROFILE_PATH
|
||||
fi
|
||||
if [[ ! -e $MYPATH/profile.sh ]]; then
|
||||
echo "[ Warning ] Path detection failed, trying to use pwd..."
|
||||
MYPATH=$(pwd)
|
||||
if [[ ! -e $MYPATH/profile.sh ]]; then
|
||||
echo "[ Error ] Impossible to determine installation path, pretty much nothing will work."
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ ! -s $MYPATH/version ]]; then
|
||||
echo "[ Warning ] Impossible to determine running version of profile, your installation might be broken."
|
||||
fi
|
||||
export PROFVERSION=$(cat $MYPATH/version)
|
||||
|
||||
# Build PATH environment variable
|
||||
if [[ $EUID -eq 0 ]] ; then
|
||||
if [[ $EUID -eq 0 ]]; then
|
||||
pathappend /sbin:/usr/sbin
|
||||
fi
|
||||
[[ -d /share/services/gestparc ]] && pathappend /share/services/gestparc
|
||||
[[ -d ~/bin ]] && pathappend ~/bin
|
||||
[[ -d ~/.local/bin ]] && pathappend ~/.local/bin
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Default values are set here and will be overloaded with config file if any
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
# Set bash history
|
||||
export HISTSIZE=50000
|
||||
export HISTIGNORE="&:[bf]g:exit"
|
||||
@@ -106,17 +124,22 @@ export CFLAGS="-O2 -pipe -march=native"
|
||||
export MAKEFLAGS='-j12'
|
||||
export PKGSOURCES='/share/src/archives'
|
||||
|
||||
# Default city for weather forcast
|
||||
export DEFAULT_CITY="Toulouse"
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Default values could be altered after this line
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
# Load global configuration
|
||||
[[ -f $MYPATH/etc/profile.conf ]] && . $MYPATH/etc/profile.conf
|
||||
|
||||
# Load personal configuration
|
||||
[[ -f ~/.profile.conf ]] && . ~/.profile.conf
|
||||
|
||||
# Execute optionnal config script if any
|
||||
for script in ~/profile.d/*.sh ; do
|
||||
if [ -r $script ] ; then
|
||||
# Load module scripts
|
||||
for script in $MYPATH/profile.d/*.sh; do
|
||||
if [[ -r $script ]]; then
|
||||
. $script
|
||||
fi
|
||||
done
|
||||
|
||||
Reference in New Issue
Block a user