Compare commits
37 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6a2d9b0fee | ||
|
|
9b2c764181 | ||
|
|
3d5a5e7718 | ||
|
|
47e89b3b09 | ||
|
|
f0f80e2924 | ||
|
|
b08e457146 | ||
|
|
56e34bc346 | ||
|
|
e9e9993dfc | ||
|
|
ff4c6702b7 | ||
|
|
87dea45295 | ||
|
|
0abf481cf6 | ||
|
|
a75299f7b4 | ||
|
|
eeb87c5bfc | ||
|
|
4879b418db | ||
|
|
f944271488 | ||
|
|
4be2e5ea87 | ||
|
|
9d528a6491 | ||
|
|
bef205ae84 | ||
|
|
9e49e3e4d7 | ||
| 94e7e79c76 | |||
| 55e88bd018 | |||
|
|
18f1bc1543 | ||
|
|
0d7c7e9ab7 | ||
|
|
64fecf16fb | ||
| c2ca5f659c | |||
| 3248327e56 | |||
| fd984c4a16 | |||
| c2a0ef0bd2 | |||
| dc64123fd9 | |||
| affe6e1487 | |||
| 0237f8bf70 | |||
| d4db72260a | |||
| e980198c08 | |||
| 21c12865f5 | |||
| 5b9d7a983e | |||
| d7e6d81126 | |||
| 4a975db1c0 |
30
LICENSE
30
LICENSE
@@ -1,11 +1,29 @@
|
|||||||
Copyright (c) <year> <owner>.
|
Copyright 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
This is distributed with BSD-3-Clause license with the following terms and
|
||||||
|
condition:
|
||||||
|
|
||||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
2. 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.
|
1. Redistributions of source code must retain the above copyright notice, this
|
||||||
|
list of conditions and the following disclaimer.
|
||||||
|
|
||||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
2. 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.
|
||||||
|
|
||||||
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 HOLDER 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, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
3. Neither the name of the copyright holder nor the names of its 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 HOLDER 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, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|||||||
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
|
||||||
|
|||||||
136
history.txt
Normal file
136
history.txt
Normal file
@@ -0,0 +1,136 @@
|
|||||||
|
------------------------------------------------------------------------------
|
||||||
|
Initial version from Beyond Linux From Scratch by
|
||||||
|
* James Robertson <jameswrobertson@earthlink.net>
|
||||||
|
* Dagmar d'Surreal <rivyqntzne@pbzpnfg.arg>
|
||||||
|
------------------------------------------------------------------------------
|
||||||
|
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
|
||||||
|
|
||||||
|
# 20/11/2022 v3.2.1
|
||||||
|
Fix some messages
|
||||||
|
Make dpkgs rpm aware (more to come)
|
||||||
|
Removed version history from main script and revert declaration order
|
||||||
|
Added required license information in all files
|
||||||
|
Completed LICENSE file
|
||||||
|
|
||||||
|
# 18/11/2022 v3.2.0
|
||||||
|
Created disp command for display and make use of it
|
||||||
|
|
||||||
|
# 10/11/2022 v3.1.1
|
||||||
|
genpwd: test if password is doable
|
||||||
|
|
||||||
|
# 08/11/2022 v3.1.0
|
||||||
|
Added password generator
|
||||||
|
|
||||||
|
# 07/11/2022 v3.0.1
|
||||||
|
Added concatenation to rmspc
|
||||||
|
Added ku
|
||||||
|
Error managed in meteo
|
||||||
|
|
||||||
|
# 27/08/2022 v3.0.0
|
||||||
|
Splitted everything in several files
|
||||||
|
Added rain screensaver
|
||||||
|
|
||||||
|
# 29/07/2022 v2.8.2
|
||||||
|
Added warning for non bash or zsh users
|
||||||
|
|
||||||
|
# 19/07/2022 v2.8.1
|
||||||
|
Few cleanups, fixes and optimizations
|
||||||
|
|
||||||
|
# 24/06/2022 v2.8.0
|
||||||
|
Added backtrace, error and settrace
|
||||||
|
[bugfix] corrected showinfo
|
||||||
|
|
||||||
|
# 22/06/2022 v2.7.1
|
||||||
|
[bugfix] few minor corrections
|
||||||
|
Added help command
|
||||||
|
|
||||||
|
# 21/06/2022 v2.7.0
|
||||||
|
Added isipv4 and isipv6 and use it in rmhost as an improvement
|
||||||
|
Removed konsole save and restore not working
|
||||||
|
|
||||||
|
# 18/10/2021 v2.6.3
|
||||||
|
Changed PS1 for status bar style version
|
||||||
|
Few minor improvements
|
||||||
|
|
||||||
|
# 26/02/2021 v2.6.2
|
||||||
|
[bugfix] taz: corrected bug with trailing slash on directories
|
||||||
|
|
||||||
|
# 25/12/2020 v2.6.1
|
||||||
|
Add check on rmhost
|
||||||
|
Improvements rmspc
|
||||||
|
Created expendlist
|
||||||
|
|
||||||
|
# 24/10/2020 v2.6.0
|
||||||
|
Added session save and restore for Konsole
|
||||||
|
|
||||||
|
# 11/09/2020 v2.5.3
|
||||||
|
Few more aliases, improved code consistancy and typo,
|
||||||
|
Improved utaz, removed showdiskmap, removed remaining French,
|
||||||
|
Added license information for future publication
|
||||||
|
|
||||||
|
# 06/03/2020 v2.5.2
|
||||||
|
Few aliases sorted out
|
||||||
|
|
||||||
|
# 05/03/2020 v2.5.1
|
||||||
|
Language consistancy fix
|
||||||
|
Added pigz support in taz
|
||||||
|
|
||||||
|
# 03/03/2020 v2.5.0
|
||||||
|
Added command taz and rmspc
|
||||||
|
Renamed auzip => utaz and improved it
|
||||||
|
|
||||||
|
# 02/03/2020 v2.4.0
|
||||||
|
Added command auzip
|
||||||
|
|
||||||
|
# 31/01/2020 v2.3.2
|
||||||
|
Figlet: changed default font to ansi_shadow
|
||||||
|
|
||||||
|
# 16/01/2020 v2.3.1
|
||||||
|
[bugfix] non-interactive were blocked with some functions
|
||||||
|
|
||||||
|
# 08/01/2020 v2.3.0
|
||||||
|
Added use of figlet and neofetch as a motd replace
|
||||||
|
|
||||||
|
# 16/12/2019 v2.2.0
|
||||||
|
Added showinfo
|
||||||
|
Primary write of showdiskmap
|
||||||
|
|
||||||
|
# 24/09/2019 v2.1.2
|
||||||
|
[bugfix] bug in profile version display
|
||||||
|
|
||||||
|
# 23/09/2019 v2.1.1
|
||||||
|
[bugfix] dpkgs
|
||||||
|
|
||||||
|
# 16/09/2018 v2.1.0
|
||||||
|
Added rmhost, setc, setfr
|
||||||
|
More locales management
|
||||||
|
|
||||||
|
# 04/02/2017 v2.0.1
|
||||||
|
clean improvements (--shell)
|
||||||
|
|
||||||
|
# 24/10/2015 v2.0.0
|
||||||
|
Added advanced functionnalities (clean, srr, etc.)
|
||||||
|
|
||||||
|
# 16/02/2013 v1.0.0
|
||||||
|
Initial version
|
||||||
|
|
||||||
@@ -1,99 +1,138 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Smartly uncompress archives (zip only)
|
# 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.
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# Smartly uncompress archives (zip only for now)
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
utaz()
|
utaz()
|
||||||
{
|
{
|
||||||
for opt in $@ ; do
|
for opt in $@; do
|
||||||
case $opt in
|
case $opt in
|
||||||
"-h"|"--help")
|
"-h" | "--help")
|
||||||
echo "utaz: uncompress all the given files and/or the ones found in the given"
|
echo "utaz: uncompress all the given files and/or the ones found in the given"
|
||||||
echo " directories creating an host directory where needed."
|
echo " directories creating an host directory where needed."
|
||||||
echo
|
echo
|
||||||
echo "Usage: utaz [option] [directorie(s)|file(s)]"
|
echo "Usage: utaz [option] [directorie(s)|file(s)]"
|
||||||
echo
|
echo
|
||||||
echo "Options:"
|
echo "Options:"
|
||||||
echo " -h, --help Display that help screen"
|
echo " -h, --help Display that help screen"
|
||||||
echo " -d, --delete If decompression succeeded, delete the source file"
|
echo " -d, --delete If decompression succeeded, delete the source file"
|
||||||
echo " -c, --create-dir Always create a host directory"
|
echo " -c, --create-dir Always create a host directory"
|
||||||
echo " -n, --no-dir Never create a host directory"
|
echo " -n, --no-dir Never create a host directory"
|
||||||
echo
|
echo
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
|
|
||||||
"-d"|"--delete")
|
"-d" | "--delete")
|
||||||
local willrm=1
|
local willrm=1
|
||||||
;;
|
;;
|
||||||
|
|
||||||
"-c"|"--create-dir")
|
"-c" | "--create-dir")
|
||||||
local createdir=1
|
local createdir=1
|
||||||
;;
|
;;
|
||||||
|
|
||||||
"-n"|"--no-dir")
|
"-n" | "--no-dir")
|
||||||
local nodir=1
|
local nodir=1
|
||||||
;;
|
;;
|
||||||
|
|
||||||
"-"*)
|
"-"*)
|
||||||
echo "Invalid option, use \"utaz --help\" to display options list"
|
disp E "Invalid option, use \"utaz --help\" to display options list"
|
||||||
echo
|
echo
|
||||||
return 1
|
return 1
|
||||||
;;
|
;;
|
||||||
|
|
||||||
*)
|
*)
|
||||||
# The ${opt%/} writing is to remove trailing / if any
|
# The ${opt%/} writing is to remove trailing / if any
|
||||||
local LIST="$LIST ${opt%/}"
|
local LIST="$LIST ${opt%/}"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
[[ $createdir && $nodir ]] && echo "*** Error: --create-dir and --no-dir options are mutually exclusive."
|
[[ $createdir && $nodir ]] && \
|
||||||
|
disp E "The --create-dir and --no-dir options are mutually exclusive."
|
||||||
|
|
||||||
[[ ! $LIST ]] && local LIST="."
|
[[ ! $LIST ]] && local LIST="."
|
||||||
|
|
||||||
for zitem in $LIST; do
|
for zitem in $LIST; do
|
||||||
[[ $(ls $zitem/*.zip 2> /dev/null | wc -l) -eq 0 ]] &&
|
shopt -s nullglob
|
||||||
echo "$zitem contains no supported archive file, skipping." &&
|
local zips=("$zitem"/*.zip)
|
||||||
|
shopt -u nullglob
|
||||||
|
[[ ${#zips[@]} -eq 0 ]] && \
|
||||||
|
disp W "$zitem contains no supported archive file, skipping." && \
|
||||||
continue
|
continue
|
||||||
|
|
||||||
for f in $zitem/*.zip; do
|
for f in "$zitem"/*.zip; do
|
||||||
echo -n "Processing archive $zitem/$f... "
|
disp I "Processing archive $f... "
|
||||||
local dir=${f::-4}
|
local dir=${f::-4}
|
||||||
|
|
||||||
mkdir -p $dir
|
mkdir -p "$dir"
|
||||||
[[ $? -gt 0 ]] &&
|
[[ $? -gt 0 ]] &&
|
||||||
echo "[ filesystem can't create directories, exit ]" &&
|
disp E "The filesystem can't create directories, exit!" &&
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
unzip -o $f -d $dir > /dev/null 2>&1
|
unzip -o "$f" -d "$dir" >/dev/null 2>&1
|
||||||
case $? in
|
case $? in
|
||||||
0)
|
0)
|
||||||
[[ $willrm ]] && rm -f $f && echo -n "Deleted ! "
|
[[ $willrm ]] && rm -f "$f" && disp I "File $zitem/$f deleted."
|
||||||
;;
|
;;
|
||||||
|
|
||||||
1)
|
1)
|
||||||
echo "No deletion on warnings "
|
disp W "Compression program returned a warning: deletion canceled."
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "[ zip file corrupted, failed ]"
|
disp E "The zip file seems corrupted, failed."
|
||||||
rm -rf $dir > /dev/null 2>&1
|
rm -rf "$dir" >/dev/null 2>&1
|
||||||
continue
|
continue
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
if [[ $createdir ]]; then
|
if [[ $createdir ]]; then
|
||||||
echo -n "[ subdir created, "
|
disp I "Archive extracted successfully in subdirectory."
|
||||||
elif [[ $nodir ]]; then
|
elif [[ $nodir ]]; then
|
||||||
mv ./$dir/* ./ && rmdir $dir
|
mv "./$dir/"* ./ && rmdir "$dir"
|
||||||
echo -n "[ No subdir, "
|
disp I "Archive extracted successfully, no subdirectory needed."
|
||||||
else
|
else
|
||||||
subdirs=$(find $dir -maxdepth 1 | wc -l)
|
subdirs=$(find $dir -maxdepth 1 | wc -l)
|
||||||
if [[ $subdirs -eq 2 ]]; then
|
if [[ $subdirs -eq 2 ]]; then
|
||||||
mv ./$dir/* ./ && rmdir $dir
|
mv ./$dir/* ./ && rmdir $dir
|
||||||
echo -n "[ No subdir, "
|
disp I "Archive extracted successfully, no subdirectory needed."
|
||||||
else
|
else
|
||||||
echo -n "[ subdir created, "
|
disp I "Archive extracted successfully in subdirectory."
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
echo " OK ]"
|
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
@@ -102,22 +141,22 @@ export -f utaz
|
|||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Compress directories or files into one or more archive
|
# Compress directories or files into one or more archive
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
taz ()
|
taz()
|
||||||
{
|
{
|
||||||
_doxz()
|
_doxz()
|
||||||
{
|
{
|
||||||
command -v xz >/dev/null 2>&1 || {
|
command -v xz >/dev/null 2>&1 || {
|
||||||
echo -e >&2 "\t*** The program 'xz' is not installed, aborting."
|
disp E "The program 'xz' is not installed, aborting."
|
||||||
return 127
|
return 127
|
||||||
}
|
}
|
||||||
|
|
||||||
[[ $4 ]] && local verb='-v'
|
[[ $4 ]] && local verb='-v'
|
||||||
|
|
||||||
# Display a warning for this format
|
# Display a warning for this format
|
||||||
echo -e "\t! Warning: xz format is not suited for long term archiving."
|
disp W "xz format is not suited for long term archiving."
|
||||||
echo -e "\t See https://www.nongnu.org/lzip/xz_inadequate.html for details."
|
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
|
xz $verb --compress --keep -$3 -T $2 $1
|
||||||
return $?
|
return $?
|
||||||
}
|
}
|
||||||
@@ -129,14 +168,14 @@ taz ()
|
|||||||
|
|
||||||
command -v plzip >/dev/null 2>&1 || {
|
command -v plzip >/dev/null 2>&1 || {
|
||||||
command -v lzip >/dev/null 2>&1 || {
|
command -v lzip >/dev/null 2>&1 || {
|
||||||
echo -e >&2 "\t*** Program 'plzip' or 'lzip' are not installed, aborting."
|
disp E "Program 'plzip' or 'lzip' are not installed, aborting."
|
||||||
return 127
|
return 127
|
||||||
}
|
}
|
||||||
local command=lzip
|
command=lzip
|
||||||
local procopt=""
|
local procopt=""
|
||||||
[[ $2 -gt 1 ]] &&
|
[[ $2 -gt 1 ]] &&
|
||||||
echo -e "\t! Warning: lzip doesn't support multithreading, falling back to 1 thread." &&
|
disp W "lzip doesn't support multithreading, falling back to 1 thread." &&
|
||||||
echo -e "\t* Consitder installing plzip to obtain multithreading abilities."
|
disp W "Consider installing plzip to obtain multithreading abilities."
|
||||||
}
|
}
|
||||||
|
|
||||||
[[ $4 ]] && local verb="-vv"
|
[[ $4 ]] && local verb="-vv"
|
||||||
@@ -153,14 +192,14 @@ taz ()
|
|||||||
|
|
||||||
command -v pigz >/dev/null 2>&1 || {
|
command -v pigz >/dev/null 2>&1 || {
|
||||||
command -v gzip >/dev/null 2>&1 || {
|
command -v gzip >/dev/null 2>&1 || {
|
||||||
echo -e >&2 "\t*** Programs 'pigz' or 'gzip' are not installed, aborting."
|
disp E "Programs 'pigz' or 'gzip' are not installed, aborting."
|
||||||
return 127
|
return 127
|
||||||
}
|
}
|
||||||
local command="gzip --compress"
|
local command="gzip --compress"
|
||||||
local procopt=""
|
local procopt=""
|
||||||
[[ $2 -gt 1 ]] &&
|
[[ $2 -gt 1 ]] &&
|
||||||
echo -e "\t! Warning: gzip doesn't support multithreading, falling back to 1 thread." &&
|
disp W "gzip doesn't support multithreading, falling back to 1 thread." &&
|
||||||
echo -e "\t* Consitder installing pigz to obtain multithreading abilities."
|
disp W "Consider installing pigz to obtain multithreading abilities."
|
||||||
}
|
}
|
||||||
|
|
||||||
[[ $4 ]] && local verb="--verbose"
|
[[ $4 ]] && local verb="--verbose"
|
||||||
@@ -177,14 +216,14 @@ taz ()
|
|||||||
|
|
||||||
command -v pbzip2 >/dev/null 2>&1 || {
|
command -v pbzip2 >/dev/null 2>&1 || {
|
||||||
command -v bzip2 >/dev/null 2>&1 || {
|
command -v bzip2 >/dev/null 2>&1 || {
|
||||||
echo -e >&2 "\t*** The program 'pbzip2' or 'bzip2' are not installed, aborting."
|
disp E "The program 'pbzip2' or 'bzip2' are not installed, aborting."
|
||||||
return 127
|
return 127
|
||||||
}
|
}
|
||||||
local command=bzip2
|
local command=bzip2
|
||||||
local procopt=""
|
local procopt=""
|
||||||
[[ $2 -gt 1 ]] &&
|
[[ $2 -gt 1 ]] &&
|
||||||
echo -e "\t! Warning: bzip2 doesn't support multithreading, falling back to 1 thread." &&
|
disp W "bzip2 doesn't support multithreading, falling back to 1 thread." &&
|
||||||
echo -e "\t* Consitder installing pbzip2 to obtain multithreading abilities."
|
disp W "Consider installing pbzip2 to obtain multithreading abilities."
|
||||||
}
|
}
|
||||||
|
|
||||||
[[ $4 ]] && local verb="-v"
|
[[ $4 ]] && local verb="-v"
|
||||||
@@ -197,98 +236,103 @@ taz ()
|
|||||||
_dolzo()
|
_dolzo()
|
||||||
{
|
{
|
||||||
command -v lzop >/dev/null 2>&1 || {
|
command -v lzop >/dev/null 2>&1 || {
|
||||||
echo -e >&2 "\t*** The program 'lzop' is not installed, aborting."
|
disp E "The program 'lzop' is not installed, aborting."
|
||||||
return 127
|
return 127
|
||||||
}
|
}
|
||||||
|
|
||||||
[[ $4 ]] && local verb='-v'
|
[[ $4 ]] && local verb='-v'
|
||||||
[[ $2 -gt 1 ]] && echo -e "\t! Warning: lzop doesn't support multithreading, falling back to 1 thread."
|
[[ $2 -gt 1 ]] && disp W "lzop doesn't support multithreading, falling back to 1 thread."
|
||||||
|
|
||||||
# Compresse au format lzo
|
# Compresse au format lzo
|
||||||
lzop --keep -$3 $1
|
lzop --keep -$3 $1
|
||||||
return $?
|
return $?
|
||||||
}
|
}
|
||||||
|
|
||||||
for opt in $@ ; do
|
for opt in $@; do
|
||||||
case $opt in
|
case $opt in
|
||||||
"-h"|"--help")
|
"-h" | "--help")
|
||||||
echo "taz: archive all files of a directory."
|
echo "taz: archive all files of a directory."
|
||||||
echo
|
echo
|
||||||
echo "Usage: taz [option] [--parallel=<n>] [--format=<format>] [directory1 ... directoryN]"
|
echo "Usage: taz [option] [--parallel=<n>] [--format=<format>] [directory1 ... directoryN]"
|
||||||
echo
|
echo
|
||||||
echo "Options:"
|
echo "Options:"
|
||||||
echo " -h, --help Display that help screen"
|
echo " -h, --help Display that help screen"
|
||||||
echo " -d, --delete Delete source file or directory after success"
|
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 " -f, --format Chose archive format in the given list. If several format are"
|
||||||
echo " given, the smalest is kept"
|
echo " given, the smalest is kept"
|
||||||
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 " -1, .., -9 Compression level to use [1=fast/big, 9=slow/small]"
|
echo " -q, --quiet Display less messages (only errors and warnings)"
|
||||||
echo
|
echo " -1, .., -9 Compression level to use [1=fast/biggest, 9=slow/smallest]"
|
||||||
echo "Supported archive format:"
|
echo
|
||||||
echo " Param.| programs | Algo. | Description"
|
echo "Supported archive format:"
|
||||||
echo " ------+---------------+-------+----------------------------------------"
|
echo " Param.| programs | Algo. | Description"
|
||||||
echo " lz | plzip, lzip | lzma | Safe efficient default format"
|
echo " ------+---------------+-------+----------------------------------------"
|
||||||
echo " xz | xz | lzma2 | Unsafe, not for long term"
|
echo " lz | plzip, lzip | lzma | Safe efficient default format"
|
||||||
echo " bz2 | pbzip2, bzip2 | bzip2 | Historical but less efficient than lz"
|
echo " xz | xz | lzma2 | Unsafe, not for long term"
|
||||||
echo " gz | pigz, gzip | lz77 | Historical, safe, fast"
|
echo " bz2 | pbzip2, bzip2 | bzip2 | Historical but less efficient than lz"
|
||||||
echo " lzo | lzop | lzo | Very fast but no multithread"
|
echo " gz | pigz, gzip | lz77 | Historical, safe, fast"
|
||||||
echo " tar | tar | tar | No compression"
|
echo " lzo | lzop | lzo | Very fast but no multithread"
|
||||||
echo
|
echo " tar | tar | tar | No compression"
|
||||||
return 0
|
echo
|
||||||
;;
|
return 0
|
||||||
|
;;
|
||||||
|
|
||||||
"-d"|"--delete")
|
"-d" | "--delete")
|
||||||
local willrm=1
|
local willrm=1
|
||||||
;;
|
;;
|
||||||
|
|
||||||
"-f"?*|"--format"?*)
|
"-f"?* | "--format"?*)
|
||||||
local compform=$(echo "$opt" | cut -f 2- -d '=')
|
local compform=$(echo "$opt" | cut -f 2- -d '=')
|
||||||
;;
|
;;
|
||||||
|
|
||||||
"-p"?*|"--parallel"?*)
|
"-p"?* | "--parallel"?*)
|
||||||
local nproc=$(echo "$opt" | cut -f 2- -d '=')
|
local nproc=$(echo "$opt" | cut -f 2- -d '=')
|
||||||
;;
|
;;
|
||||||
|
|
||||||
"-v"|"--verbose")
|
"-v" | "--verbose")
|
||||||
local verbose=1
|
local verbose=1
|
||||||
;;
|
;;
|
||||||
|
|
||||||
"-"[1..9])
|
"-q" | "--quiet")
|
||||||
local complevel=$(echo $opt | sed 's/-//')
|
local quiet=1
|
||||||
;;
|
;;
|
||||||
|
|
||||||
"-"*)
|
"-"*)
|
||||||
echo "Invalid option, use taz --help to display options list"
|
local complevel=$(echo $opt | sed 's/-//')
|
||||||
|
if ! [[ $complevel =~ ^[1-9]+$ ]]; then
|
||||||
|
disp E "Invalid option, use taz --help to display options list"
|
||||||
echo
|
echo
|
||||||
return 1
|
return 1
|
||||||
;;
|
fi
|
||||||
|
;;
|
||||||
|
|
||||||
*)
|
*)
|
||||||
local LIST="$LIST ${opt%/}"
|
local LIST="$LIST ${opt%/}"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
[[ ! $compform ]] && compform=lz # safe and efficient (unless data are already compressed)
|
[[ ! $compform ]] && compform=lz # safe and efficient (unless data are already compressed)
|
||||||
[[ ! $nproc ]] && nproc=1
|
[[ ! $nproc ]] && nproc=1
|
||||||
[[ ! $complevel ]] && complevel=6
|
[[ ! $complevel ]] && complevel=6
|
||||||
|
[[ $verbose -gt 1 && $quiet -gt 1 ]] &&
|
||||||
|
disp E "The --verbose and --quiet options can't be used together."
|
||||||
|
|
||||||
for item in $LIST; do
|
for item in $LIST; do
|
||||||
local donetar=0
|
local donetar=0
|
||||||
echo "--- Processing $item..."
|
disp I "Processing $item..."
|
||||||
|
|
||||||
if [[ -d $item ]]; then
|
if [[ -d "$item" ]]; then
|
||||||
echo -ne "\t* Creating $item.tar... "
|
disp I "\t Creating $item.tar... "
|
||||||
|
|
||||||
tar -cf $item{.tar,}
|
tar -cf "$item.tar" "$item"
|
||||||
if [[ ! $? -eq 0 ]]; then
|
if [[ ! $? -eq 0 ]]; then
|
||||||
echo "[ failed, skipping ]"
|
disp E "tar file creation failed, skipping to next item."
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local donetar=1
|
local donetar=1
|
||||||
echo "[ OK ]"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local fname=$item
|
local fname=$item
|
||||||
@@ -296,29 +340,30 @@ taz ()
|
|||||||
|
|
||||||
# Skip compression part if tar is asked
|
# Skip compression part if tar is asked
|
||||||
if [[ $compform != "tar" ]]; then
|
if [[ $compform != "tar" ]]; then
|
||||||
echo -e "\t* Compressing archive..."
|
disp I "\t Compressing archive..."
|
||||||
_do$compform $fname $nproc $complevel $verbose
|
_do$compform "$fname" "$nproc" "$complevel" "$verbose"
|
||||||
[[ ! $? -eq 0 ]] && case $? in
|
[[ ! $? -eq 0 ]] && case $? in
|
||||||
127)
|
127)
|
||||||
echo -e "\t*** Compression program unavailable, aborting."
|
disp E "Compression program unavailable, aborting."
|
||||||
return 127
|
return 127
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo -e "\t*** Compression program returned an error, not deleting anything if asked, skipping to next item."
|
disp E "Compression program returned an error, not deleting anything if asked, skipping to next item."
|
||||||
continue
|
continue
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
[[ $donetar -gt 0 ]] && rm $fname
|
[[ $donetar -gt 0 ]] && rm "$fname"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $willrm ]]; then
|
if [[ $willrm ]]; then
|
||||||
echo -en "\t* Deleting original source as asked... "
|
disp I "\t Deleting original source as asked... "
|
||||||
rm -r $item && echo '[ OK ]' || echo '[ failed ]'
|
rm -r "$item"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "--- Done"
|
|
||||||
done
|
done
|
||||||
|
unset quiet
|
||||||
}
|
}
|
||||||
export -f taz
|
export -f taz
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# EOF
|
||||||
|
|||||||
@@ -1,16 +1,52 @@
|
|||||||
|
#!/bin/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.
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Display a backtrace
|
# Display a backtrace
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
function backtrace ()
|
function backtrace()
|
||||||
{
|
{
|
||||||
echo "========= Call stack ========="
|
echo "========= Call stack ========="
|
||||||
typeset -i i=0
|
typeset -i i=0
|
||||||
|
|
||||||
local func=
|
local func=
|
||||||
for func in "${FUNCNAME[@]}"; do
|
for func in "${FUNCNAME[@]}"; do
|
||||||
if [[ $i -ne 0 ]]; then
|
if [[ $i -ne 0 ]]; then
|
||||||
printf '%15s() %s:%d\n' \
|
printf '%15s() %s:%d\n' \
|
||||||
"$func" "${BASH_SOURCE[$i]}" "${BASH_LINENO[ (( $i - 1)) ]}"
|
"$func" "${BASH_SOURCE[$i]}" "${BASH_LINENO[(($i - 1))]}"
|
||||||
fi
|
fi
|
||||||
let i++ || true
|
let i++ || true
|
||||||
done
|
done
|
||||||
@@ -21,52 +57,54 @@ function backtrace ()
|
|||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Function to be trapped for errors investigation
|
# Function to be trapped for errors investigation
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
function error ()
|
function error()
|
||||||
{
|
{
|
||||||
local errcode=$?
|
local errcode=$?
|
||||||
backtrace
|
backtrace
|
||||||
return $errcode
|
return $errcode
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Activate or deactivate error trapping to display backtrace
|
# Activate or deactivate error trapping to display backtrace
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
settrace ()
|
settrace()
|
||||||
{
|
{
|
||||||
local status="off"
|
local status="off"
|
||||||
[[ $(trap -p ERR) ]] && status="on"
|
[[ $(trap -p ERR) ]] && status="on"
|
||||||
#trap -p ERR
|
#trap -p ERR
|
||||||
for opt in $@ ; do
|
for opt in $@; do
|
||||||
case $opt in
|
case $opt in
|
||||||
"-h"|"--help")
|
"-h" | "--help")
|
||||||
echo "Try to activate backtrace display for script debugging."
|
echo "Try to activate backtrace display for script debugging."
|
||||||
echo
|
echo
|
||||||
echo "Options:"
|
echo "Options:"
|
||||||
echo " --on Activate backtrace generation"
|
echo " --on Activate backtrace generation"
|
||||||
echo " --off Deactivate backtrace generation"
|
echo " --off Deactivate backtrace generation"
|
||||||
echo
|
echo
|
||||||
echo "That function active a trap event on error. If the script you want to"
|
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 "debug overload the ERR bash trap, it will not work."
|
||||||
echo
|
echo
|
||||||
;;
|
;;
|
||||||
"--on")
|
"--on")
|
||||||
if [[ $status == "on" ]]; then
|
if [[ $status == "on" ]]; then
|
||||||
echo "Warning: ERR signal trap is already set, replacing previous trap!"
|
disp W "ERR signal trap is already set, replacing previous trap!"
|
||||||
fi
|
fi
|
||||||
trap "error" ERR
|
trap "error" ERR
|
||||||
;;
|
;;
|
||||||
"--off")
|
"--off")
|
||||||
if [[ $status != "on" ]]; then
|
if [[ $status != "on" ]]; then
|
||||||
echo "Warning: ERR signal trap is already unset!"
|
disp W "ERR signal trap is already unset!"
|
||||||
fi
|
fi
|
||||||
trap - ERR
|
trap - ERR
|
||||||
;;
|
;;
|
||||||
"--status")
|
"--status")
|
||||||
echo "ERR trap signal is ${status}."
|
disp "ERR trap signal is ${status}."
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
unset status
|
unset status
|
||||||
}
|
}
|
||||||
export -f settrace
|
export -f settrace
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# EOF
|
||||||
|
|||||||
152
profile.d/disp.sh
Normal file
152
profile.d/disp.sh
Normal file
@@ -0,0 +1,152 @@
|
|||||||
|
#!/bin/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.
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# Color definitions
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# Standard 16 colors display declaration
|
||||||
|
export DEFAULTFG="\e[0;39m"
|
||||||
|
export DEFAULTBG="\e[0;49m"
|
||||||
|
export DEFAULTCOL=${DEFAULTBG}${DEFAULTFG}
|
||||||
|
export RESETCOL=$'\e[0m'
|
||||||
|
|
||||||
|
# Regular Colors
|
||||||
|
export Black='\e[0;30m'
|
||||||
|
export Red='\e[0;31m'
|
||||||
|
export Green='\e[0;32m'
|
||||||
|
export Yellow='\e[0;33m'
|
||||||
|
export Blue='\e[0;34m'
|
||||||
|
export Purple='\e[0;35m'
|
||||||
|
export Cyan='\e[0;36m'
|
||||||
|
export White='\e[0;37m'
|
||||||
|
|
||||||
|
# Bold
|
||||||
|
export BBlack='\e[1;30m'
|
||||||
|
export BRed='\e[1;31m'
|
||||||
|
export BGreen='\e[1;32m'
|
||||||
|
export BYellow='\e[1;33m'
|
||||||
|
export BBlue='\e[1;34m'
|
||||||
|
export BPurple='\e[1;35m'
|
||||||
|
export BCyan='\e[1;36m'
|
||||||
|
export BWhite='\e[1;37m'
|
||||||
|
|
||||||
|
# Underline
|
||||||
|
export UBlack='\e[4;30m'
|
||||||
|
export URed='\e[4;31m'
|
||||||
|
export UGreen='\e[4;32m'
|
||||||
|
export UYellow='\e[4;33m'
|
||||||
|
export UBlue='\e[4;34m'
|
||||||
|
export UPurple='\e[4;35m'
|
||||||
|
export UCyan='\e[4;36m'
|
||||||
|
export UWhite='\e[4;37m'
|
||||||
|
|
||||||
|
# Background
|
||||||
|
export On_Black='\e[40m'
|
||||||
|
export On_Red='\e[41m'
|
||||||
|
export On_Green='\e[42m'
|
||||||
|
export On_Yellow='\e[43m'
|
||||||
|
export On_Blue='\e[44m'
|
||||||
|
export On_Purple='\e[45m'
|
||||||
|
export On_Cyan='\e[46m'
|
||||||
|
export On_White='\e[47m'
|
||||||
|
|
||||||
|
# High Intensity
|
||||||
|
export IBlack='\e[0;90m'
|
||||||
|
export IRed='\e[0;91m'
|
||||||
|
export IGreen='\e[0;92m'
|
||||||
|
export IYellow='\e[0;93m'
|
||||||
|
export IBlue='\e[0;94m'
|
||||||
|
export IPurple='\e[0;95m'
|
||||||
|
export ICyan='\e[0;96m'
|
||||||
|
export IWhite='\e[0;97m'
|
||||||
|
|
||||||
|
# Bold High Intensity
|
||||||
|
export BIBlack='\e[1;90m'
|
||||||
|
export BIRed='\e[1;91m'
|
||||||
|
export BIGreen='\e[1;92m'
|
||||||
|
export BIYellow='\e[1;93m'
|
||||||
|
export BIBlue='\e[1;94m'
|
||||||
|
export BIPurple='\e[1;95m'
|
||||||
|
export BICyan='\e[1;96m'
|
||||||
|
export BIWhite='\e[1;97m'
|
||||||
|
|
||||||
|
# High Intensity backgrounds
|
||||||
|
export On_IBlack='\e[0;100m'
|
||||||
|
export On_IRed='\e[0;101m'
|
||||||
|
export On_IGreen='\e[0;102m'
|
||||||
|
export On_IYellow='\e[0;103m'
|
||||||
|
export On_IBlue='\e[0;104m'
|
||||||
|
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 ]] && \
|
||||||
|
printf "%b\n" "${heads} $*${RESETCOL}"
|
||||||
|
;;
|
||||||
|
"W")
|
||||||
|
local heads="[ ${IYellow}Warning${DEFAULTFG} ]"
|
||||||
|
shift
|
||||||
|
printf "%b\n" "${heads} $*${RESETCOL}" >&2
|
||||||
|
;;
|
||||||
|
"E")
|
||||||
|
local heads="[ ${IRed}ERROR${DEFAULTFG} ]"
|
||||||
|
shift
|
||||||
|
printf "%b\n" "${heads} $*${RESETCOL}" >&2
|
||||||
|
;;
|
||||||
|
"D")
|
||||||
|
local heads="[ ${ICyan}debug${DEFAULTFG} ]"
|
||||||
|
shift
|
||||||
|
[[ -n $DEBUG && $DEBUG -gt 1 ]] && \
|
||||||
|
printf "%b\n" "${heads} $*${RESETCOL}"
|
||||||
|
;;
|
||||||
|
* )
|
||||||
|
[[ -z $QUIET || $QUIET -ne 1 ]] && \
|
||||||
|
printf "%b\n" "$*"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
export -f disp
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# EOF
|
||||||
@@ -1,3 +1,39 @@
|
|||||||
|
#!/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.
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# expandlist : treat wildcards in a file/directory list
|
# expandlist : treat wildcards in a file/directory list
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
@@ -12,49 +48,48 @@ expandlist()
|
|||||||
echo $result
|
echo $result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Clean a directory or a tree from temporary or backup files
|
# Clean a directory or a tree from temporary or backup files
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
clean ()
|
clean()
|
||||||
{
|
{
|
||||||
for opt in $@ ; do
|
for opt in $@; do
|
||||||
case $opt in
|
case $opt in
|
||||||
"-r"|"--recurs")
|
"-r" | "--recurs")
|
||||||
local recursive=1
|
local recursive=1
|
||||||
;;
|
;;
|
||||||
|
|
||||||
"-h"|"--help")
|
"-h" | "--help")
|
||||||
echo "clean: erase backup files in the given directories."
|
echo "clean: erase backup files in the given directories."
|
||||||
echo
|
echo
|
||||||
echo "Usage: clean [option] [directory1] [...[directoryX]]"
|
echo "Usage: clean [option] [directory1] [...[directoryX]]"
|
||||||
echo
|
echo
|
||||||
echo "Options:"
|
echo "Options:"
|
||||||
echo " -h, --help Display that help screen"
|
echo " -h, --help Display that help screen"
|
||||||
echo " -r, --recurs Do a recursive cleaning"
|
echo " -r, --recurs Do a recursive cleaning"
|
||||||
echo " -f, --force Do not ask for confirmation (use with care)"
|
echo " -f, --force Do not ask for confirmation (use with care)"
|
||||||
echo " -s, --shell Do nothing and display what will be executed"
|
echo " -s, --shell Do nothing and display what will be executed"
|
||||||
echo
|
echo
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
|
|
||||||
"-s"|"--shell")
|
"-s" | "--shell")
|
||||||
local outshell=1
|
local outshell=1
|
||||||
;;
|
;;
|
||||||
|
|
||||||
"-f"|"--force")
|
"-f" | "--force")
|
||||||
local force=1
|
local force=1
|
||||||
;;
|
;;
|
||||||
|
|
||||||
"-"*)
|
"-"*)
|
||||||
echo "Invalid option, use \"clean --help\" to display usage."
|
disp E "Invalid option, use \"clean --help\" to display usage."
|
||||||
echo
|
echo
|
||||||
return 1
|
return 1
|
||||||
;;
|
;;
|
||||||
|
|
||||||
*)
|
*)
|
||||||
local dirlist="$dirlist $opt"
|
local dirlist="$dirlist $opt"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
@@ -65,7 +100,7 @@ clean ()
|
|||||||
unset recursive force
|
unset recursive force
|
||||||
|
|
||||||
for dir in $dirlist; do
|
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 ".~*#")
|
-o -name "*.bak" -o -name ".~*#")
|
||||||
for f in $dellist; do
|
for f in $dellist; do
|
||||||
if [[ ! $outshell ]]; then
|
if [[ ! $outshell ]]; then
|
||||||
@@ -79,73 +114,71 @@ clean ()
|
|||||||
}
|
}
|
||||||
export -f clean
|
export -f clean
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Create a directory then goes inside
|
# Create a directory then goes inside
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
mcd ()
|
mcd()
|
||||||
{
|
{
|
||||||
if [[ ! $# -eq 1 ]] ; then
|
if [[ ! $# -eq 1 ]]; then
|
||||||
echo "Create a directory then goes inside."
|
disp E "Create a directory then goes inside."
|
||||||
echo "Usage: mcd <directory>"
|
disp E "Usage: mcd <directory>"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
mkdir -pv $1 && cd $1
|
mkdir -pv "$1" && cd "$1" || echo "Failed create or change directory."
|
||||||
}
|
}
|
||||||
export -f mcd
|
export -f mcd
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Rename all files in current directory to replace spaces with _
|
# Rename all files in current directory to replace spaces with _
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
rmspc ()
|
rmspc()
|
||||||
{
|
{
|
||||||
local lst=""
|
local lst=""
|
||||||
for opt in $@ ; do
|
for opt in $@; do
|
||||||
case $opt in
|
case $opt in
|
||||||
"-h"|"--help")
|
"-h" | "--help")
|
||||||
echo "rmspc: remove spaces from all filenames in current directories"
|
echo "rmspc: remove spaces from all filenames in current directories"
|
||||||
echo
|
echo
|
||||||
echo "Usage: rmspc [option]"
|
echo "Usage: rmspc [option]"
|
||||||
echo
|
echo
|
||||||
echo "Options:"
|
echo "Options:"
|
||||||
echo " -h, --help Display that help screen"
|
echo " -h, --help Display that help screen"
|
||||||
echo " -r, --recursive Treat subdirectories of the given directory"
|
echo " -r, --recursive Treat subdirectories of the given directory"
|
||||||
echo " -c, --subst-char Change the replacement character (default is underscore)"
|
echo " -c, --subst-char Change the replacement character (default is underscore)"
|
||||||
echo " -v, --verbose Display what is being done"
|
echo " -v, --verbose Display more details (recursive mode only)"
|
||||||
echo " -s, --shell Do nothing and display commands that would be executed"
|
echo " -s, --shell Do nothing and display commands that would be executed"
|
||||||
echo
|
echo
|
||||||
echo "Note: if the --subst-char option is given without parameters, spaces will be"
|
echo "Note: if the --subst-char option is given without parameters, spaces will be"
|
||||||
echo " replaced with nothing (concatenation)."
|
echo " replaced with nothing (concatenation)."
|
||||||
echo
|
echo
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
|
|
||||||
"-r"|"--recursive")
|
"-r" | "--recursive")
|
||||||
local recurs=1
|
local recurs=1
|
||||||
;;
|
;;
|
||||||
|
|
||||||
"-c"?*|"--subst-char"?*)
|
"-c"?* | "--subst-char"?*)
|
||||||
if [[ $(echo $opt | grep "=") ]]; then
|
if [[ $(echo $opt | grep "=") ]]; then
|
||||||
local substchar=$(echo "$opt" | cut -f 2- -d '=')
|
local substchar=$(echo "$opt" | cut -f 2- -d '=')
|
||||||
else
|
else
|
||||||
local substchar='none'
|
local substchar='none'
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
|
|
||||||
"-v"|"--verbose")
|
"-v" | "--verbose")
|
||||||
local verb=1
|
local verb=1
|
||||||
;;
|
;;
|
||||||
|
|
||||||
"-s"|"--shell")
|
"-s" | "--shell")
|
||||||
local shell=1
|
local shell=1
|
||||||
;;
|
;;
|
||||||
|
|
||||||
*)
|
*)
|
||||||
echo "Invalid parameter, use \"rmspc --help\" to display options list"
|
disp E "Invalid parameter, use \"rmspc --help\" to display options list"
|
||||||
echo
|
echo
|
||||||
return 1
|
return 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
@@ -155,15 +188,15 @@ rmspc ()
|
|||||||
|
|
||||||
for f in *; do
|
for f in *; do
|
||||||
[[ $recurs ]] && [[ -d "$f" ]] && (
|
[[ $recurs ]] && [[ -d "$f" ]] && (
|
||||||
[[ $verb ]] && echo "-- Entering directory $(pwd)/$f ..."
|
[[ $verb ]] && disp I "Entering directory $(pwd)/$f ..."
|
||||||
local lastdir=$f
|
local lastdir=$f
|
||||||
pushd "$f" > /dev/null
|
pushd "$f" >/dev/null
|
||||||
rmspc $@
|
rmspc $@
|
||||||
popd > /dev/null
|
popd >/dev/null
|
||||||
[[ $verb ]] && echo "-- Leaving directory $(pwd)/$lastdir"
|
[[ $verb ]] && disp I "Leaving directory $(pwd)/$lastdir"
|
||||||
unset lastdir
|
unset lastdir
|
||||||
)
|
)
|
||||||
|
|
||||||
if [[ $(echo $f | grep " ") ]]; then
|
if [[ $(echo $f | grep " ") ]]; then
|
||||||
local newf="${f// /${substchar}}"
|
local newf="${f// /${substchar}}"
|
||||||
local command="mv $mvopt \"$f\" \"$newf\""
|
local command="mv $mvopt \"$f\" \"$newf\""
|
||||||
@@ -174,6 +207,137 @@ rmspc ()
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
unset lst substchar verb shell newf command mvopt
|
unset lst substchar verb shell newf command mvopt
|
||||||
}
|
}
|
||||||
export -f rmspc
|
export -f rmspc
|
||||||
|
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# display stats about a file structure
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
file_stats()
|
||||||
|
{
|
||||||
|
local human=0 details=0 only_avg=0 only_med=0 only_count=0 only_total=0
|
||||||
|
local path="." show_all=1 ext_filter="" ext_list="" min_size="" max_size=""
|
||||||
|
local OPTIND opt
|
||||||
|
|
||||||
|
# Analyse options
|
||||||
|
while [[ "$1" =~ ^- ]]; do
|
||||||
|
case "$1" in
|
||||||
|
-H) human=1 ;;
|
||||||
|
-d) details=1 ;;
|
||||||
|
-m) only_avg=1; show_all=0 ;;
|
||||||
|
-M) only_med=1; show_all=0 ;;
|
||||||
|
-c) only_count=1; show_all=0 ;;
|
||||||
|
-t) only_total=1; show_all=0 ;;
|
||||||
|
-a) human=1; details=1 ;;
|
||||||
|
-x) ext_filter="${2#.}"; shift ;;
|
||||||
|
-X) ext_list="${2}"; shift ;;
|
||||||
|
--min) min_size="$2"; shift ;;
|
||||||
|
--max) max_size="$2"; shift ;;
|
||||||
|
--) shift; break ;;
|
||||||
|
-*) echo "Usage: file_stats [-h] [-d] [-mMctaxX --min N --max N] [path]"; return 1 ;;
|
||||||
|
esac
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
|
||||||
|
[ -n "$1" ] && path="$1"
|
||||||
|
|
||||||
|
# Prepare find filters
|
||||||
|
local find_cmd=(find "$path" -type f)
|
||||||
|
|
||||||
|
# Extension simple
|
||||||
|
if [[ -n "$ext_filter" ]]; then
|
||||||
|
find_cmd+=(-iname "*.$ext_filter")
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Extension liste
|
||||||
|
if [[ -n "$ext_list" ]]; then
|
||||||
|
IFS=',' read -ra exts <<< "$ext_list"
|
||||||
|
find_cmd+=('(')
|
||||||
|
for i in "${!exts[@]}"; do
|
||||||
|
[[ $i -ne 0 ]] && find_cmd+=(-o)
|
||||||
|
find_cmd+=(-iname "*.${exts[$i]}")
|
||||||
|
done
|
||||||
|
find_cmd+=(')')
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Taille min/max (à évaluer en octets)
|
||||||
|
if [[ -n "$min_size" ]]; then
|
||||||
|
find_cmd+=(-size +"$(numfmt --from=iec "$min_size")"c)
|
||||||
|
fi
|
||||||
|
if [[ -n "$max_size" ]]; then
|
||||||
|
find_cmd+=(-size -"$(( $(numfmt --from=iec "$max_size") + 1 ))"c)
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Exécution
|
||||||
|
"${find_cmd[@]}" -printf "%s\n" 2>/dev/null | sort -n | awk -v human="$human" -v details="$details" -v only_avg="$only_avg" -v only_med="$only_med" -v only_count="$only_count" -v only_total="$only_total" -v show_all="$show_all" -v path="$path" '
|
||||||
|
function human_readable(x) {
|
||||||
|
split("B KiB MiB GiB TiB", units)
|
||||||
|
for (i=1; x>=1024 && i<5; i++) x /= 1024
|
||||||
|
return sprintf("%.2f %s", x, units[i])
|
||||||
|
}
|
||||||
|
{
|
||||||
|
sizes[NR] = $1
|
||||||
|
total += $1
|
||||||
|
if (min == "" || $1 < min) min = $1
|
||||||
|
if (max == "" || $1 > max) max = $1
|
||||||
|
if ($1 == 0) bucket[0]++
|
||||||
|
else {
|
||||||
|
b = int(log($1)/log(1024))
|
||||||
|
bucket[b]++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
END {
|
||||||
|
count = NR
|
||||||
|
if (count == 0) {
|
||||||
|
print "Aucun fichier trouvé."; exit
|
||||||
|
}
|
||||||
|
|
||||||
|
moyenne = total / count
|
||||||
|
if (count % 2 == 1)
|
||||||
|
mediane = sizes[(count + 1) / 2]
|
||||||
|
else
|
||||||
|
mediane = (sizes[count / 2] + sizes[count / 2 + 1]) / 2
|
||||||
|
|
||||||
|
function out(label, val) {
|
||||||
|
if (human) val = human_readable(val)
|
||||||
|
printf "%-20s : %s\n", label, val
|
||||||
|
}
|
||||||
|
|
||||||
|
if (only_avg) out("Taille moyenne", moyenne)
|
||||||
|
else if (only_med) out("Taille médiane", mediane)
|
||||||
|
else if (only_count) printf "Nombre de fichiers : %d\n", count
|
||||||
|
else if (only_total) out("Taille totale", total)
|
||||||
|
else {
|
||||||
|
if (show_all || human || details) {
|
||||||
|
printf "Statistiques sur \"%s\"\n", path
|
||||||
|
printf "-------------------------\n"
|
||||||
|
}
|
||||||
|
out("Nombre de fichiers", count)
|
||||||
|
out("Taille totale", total)
|
||||||
|
out("Taille moyenne", moyenne)
|
||||||
|
out("Taille médiane", mediane)
|
||||||
|
out("Taille minimale", min)
|
||||||
|
out("Taille maximale", max)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (details) {
|
||||||
|
print "\nHistogramme des tailles :"
|
||||||
|
for (i = 0; i in bucket; i++) {
|
||||||
|
low = 2^i
|
||||||
|
high = 2^(i+1)
|
||||||
|
if (i == 0)
|
||||||
|
label = sprintf("%4s – %4s", "0", "1K")
|
||||||
|
else
|
||||||
|
label = sprintf("%4s – %4s", human_readable(low), human_readable(high))
|
||||||
|
printf "%-20s : %5d fichiers\n", label, bucket[i]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}'
|
||||||
|
}
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# EOF
|
||||||
|
|||||||
70
profile.d/fun.sh
Normal file
70
profile.d/fun.sh
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
#!/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()
|
||||||
|
{
|
||||||
|
local pattern="ca fe"
|
||||||
|
for arg in "$@"; do
|
||||||
|
case "$arg" in
|
||||||
|
--delay=*)
|
||||||
|
delay_ms="${arg#*=}"
|
||||||
|
if ! [[ $delay_ms =~ ^[0-9]+$ ]]; then
|
||||||
|
disp E "Invalid delay value, must be an integer (milliseconds)."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
pattern="$arg"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
# Convert milliseconds to seconds for 'sleep'
|
||||||
|
local delay_s=$(awk "BEGIN { printf \"%.3f\", $delay_ms / 1000 }")
|
||||||
|
|
||||||
|
cat /dev/urandom | hexdump -C | grep --line-buffered "$pattern" | \
|
||||||
|
while read -r line; do
|
||||||
|
echo $line
|
||||||
|
[[ $delay_ms -gt 0 ]] && sleep "$delay_s"
|
||||||
|
done
|
||||||
|
unset pattern
|
||||||
|
}
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# EOF
|
||||||
@@ -1,3 +1,39 @@
|
|||||||
|
#!/bin/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.
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Display list of commands and general informations
|
# Display list of commands and general informations
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
@@ -31,3 +67,5 @@ EOF
|
|||||||
}
|
}
|
||||||
export -f help
|
export -f help
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# EOF
|
||||||
|
|||||||
@@ -1,55 +1,104 @@
|
|||||||
|
#!/bin/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.
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Show profile version
|
# Show profile version
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
ver ()
|
ver()
|
||||||
{
|
{
|
||||||
echo "Profile version $PROFVERSION."
|
[[ -z $PROFVERSION ]] && \
|
||||||
|
disp W "No version defined. Profile is probably badly installed." && \
|
||||||
|
return 1
|
||||||
|
disp "Profile version $PROFVERSION."
|
||||||
}
|
}
|
||||||
export -f ver
|
export -f ver
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Display weather of the given city (or default one)
|
# Display weather of the given city (or default one)
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
meteo ()
|
meteo()
|
||||||
{
|
{
|
||||||
cities=$@
|
local encoded cities=("$@")
|
||||||
[[ $# -eq 0 ]] && local cities=$DEFAULT_CITY
|
[[ $# -eq 0 ]] && cities=("$DEFAULT_CITY")
|
||||||
|
|
||||||
for city in $cities; do
|
for city in "${cities[@]}"; do
|
||||||
curl https://wttr.in/$city || echo "Failed fetching datas for $city."
|
encoded=$(urlencode "$city")
|
||||||
|
curl -s "https://wttr.in/$encoded" || \
|
||||||
|
disp E "Failed fetching datas for $city."
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
export -f meteo
|
export -f meteo
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Display system general information
|
# Display system general information
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
showinfo()
|
showinfo()
|
||||||
{
|
{
|
||||||
echo -e "\n"
|
echo -e "\n"
|
||||||
if command -v figlet >/dev/null 2>&1; then
|
if command -v figlet >/dev/null 2>&1; then
|
||||||
if [[ -s /usr/share/figlet/ansi_shadow.flf ]]; then
|
if [[ -s /usr/share/figlet/ansi_shadow.flf ]]; then
|
||||||
local figopt="-f ansi_shadow"
|
local figopt="-f ansi_shadow"
|
||||||
fi
|
fi
|
||||||
figlet -k $(hostname) $figopt
|
if [[ -n $figopt ]]; then
|
||||||
|
figlet -k $figopt $(hostname)
|
||||||
|
else
|
||||||
|
figlet $(hostname)
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
echo "$(hostname -f)"
|
hostname -f
|
||||||
fi
|
fi
|
||||||
echo ""
|
echo ""
|
||||||
if command -v neofetch >/dev/null 2>&1; then
|
if command -v neofetch >/dev/null 2>&1; then
|
||||||
neofetch
|
neofetch
|
||||||
|
elif command -v fastfetch >/dev/null 2>&1; then
|
||||||
|
fastfetch
|
||||||
else
|
else
|
||||||
(
|
(
|
||||||
if [[ -s /etc/os-release ]]; then
|
if [[ -s /etc/os-release ]]; then
|
||||||
. /etc/os-release
|
# shellcheck disable=SC1091
|
||||||
echo "$NAME $VERSION"
|
. /etc/os-release
|
||||||
else
|
echo "$NAME $VERSION"
|
||||||
cat /proc/version
|
else
|
||||||
fi
|
cat /proc/version
|
||||||
echo "Uptime: $(uptime)"
|
fi
|
||||||
)
|
echo "Uptime: $(uptime -p)"
|
||||||
|
)
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
export -f showinfo
|
export -f showinfo
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# EOF
|
||||||
|
|||||||
@@ -1,35 +1,102 @@
|
|||||||
|
#!/bin/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.
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
locale_check() {
|
||||||
|
locale -a | grep -qx "$1" || {
|
||||||
|
disp W "Locale '$1' is not installed on this system."
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# Change locale to the given one in parameter
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
setlocale()
|
||||||
|
{
|
||||||
|
local loc=$1
|
||||||
|
[[ -z $loc ]] && disp E "No locale specified." && return 1
|
||||||
|
|
||||||
|
locale_check "$loc" || return 1
|
||||||
|
|
||||||
|
export LANG=$loc
|
||||||
|
export LC_MESSAGES=$loc
|
||||||
|
export LC_TIME=$loc
|
||||||
|
export LC_NUMERIC=$loc
|
||||||
|
export LC_MONETARY=$loc
|
||||||
|
export LC_COLLATE=$loc
|
||||||
|
export LC_CTYPE=$loc
|
||||||
|
|
||||||
|
disp I "Locale set to $loc."
|
||||||
|
}
|
||||||
|
export -f setlocale
|
||||||
|
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# Special case : change locale to C standard
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
setc()
|
||||||
|
{
|
||||||
|
# Locale definitions
|
||||||
|
export LC_ALL=C
|
||||||
|
disp I "Locale changed to standard C (POSIX)."
|
||||||
|
}
|
||||||
|
export -f setc
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Change locale to French
|
# Change locale to French
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
setfr ()
|
setfr()
|
||||||
{
|
{
|
||||||
# Set fr locale definitions
|
# Set fr locale definitions
|
||||||
export LANG=fr_FR.UTF-8
|
setlocale "fr_FR.UTF-8"
|
||||||
export LC_MESSAGES=fr_FR.UTF-8
|
|
||||||
export LC_ALL=fr_FR.UTF-8
|
|
||||||
}
|
}
|
||||||
export -f setfr
|
export -f setfr
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
|
||||||
# Change locale to C standard
|
|
||||||
# ------------------------------------------------------------------------------
|
|
||||||
setc ()
|
|
||||||
{
|
|
||||||
# Locale definitions
|
|
||||||
export LANG=C
|
|
||||||
export LC_MESSAGES=C
|
|
||||||
export LC_ALL=C
|
|
||||||
}
|
|
||||||
export -f setc
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Change locale to US (needed by Steam)
|
# Change locale to US (needed by Steam)
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
setus ()
|
setus()
|
||||||
{
|
{
|
||||||
# Locale definitions
|
setlocale "en_US.UTF-8"
|
||||||
export LANG=en_US.UTF-8
|
|
||||||
export LC_MESSAGES=en_US.UTF-8
|
|
||||||
export LC_ALL=en_US.UTF-8
|
|
||||||
}
|
}
|
||||||
export -f setus
|
export -f setus
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# EOF
|
||||||
|
|||||||
100
profile.d/net.sh
100
profile.d/net.sh
@@ -1,49 +1,107 @@
|
|||||||
|
#!/bin/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.
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Determine if parameter is a valid IPv4 address
|
# Determine if parameter is a valid IPv4 address
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
isipv4 ()
|
isipv4()
|
||||||
{
|
{
|
||||||
# Set up local variables
|
# Set up local variables
|
||||||
local ip=$1
|
local ip=$1
|
||||||
|
[[ -z $ip ]] && return 1
|
||||||
|
|
||||||
# Start with a regex format test
|
# 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
|
if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
|
||||||
local old_ifs=$IFS
|
local old_ifs=$IFS
|
||||||
IFS="."
|
IFS="."
|
||||||
ip=($ip)
|
ip=($ip)
|
||||||
IFS=$old_ifs
|
IFS=$old_ifs
|
||||||
if [[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \
|
if [[ ${ip[0]} -le 255 && ${ip[1]} -le 255 &&
|
||||||
&& ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]; then
|
${ip[2]} -le 255 && ${ip[3]} -le 255 ]]; then
|
||||||
if [[ -t 1 ]]; then
|
if [[ -t 1 ]]; then
|
||||||
echo "The given IPv4 is valid."
|
disp "The given IPv4 is valid."
|
||||||
fi
|
fi
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
if [[ -t 1 ]]; then
|
if [[ -t 1 ]]; then
|
||||||
echo "The given parameter is NOT a valid IPv4."
|
disp "The given parameter is NOT a valid IPv4."
|
||||||
fi
|
fi
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
export -f isipv4
|
export -f isipv4
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Determine if parameter is a valid IPv4 address
|
# Determine if parameter is a valid IPv4 address
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
isipv6 ()
|
isipv6()
|
||||||
{
|
{
|
||||||
local ip="$1"
|
local ip="$1"
|
||||||
local regex='^([0-9a-fA-F]{0,4}:){1,7}[0-9a-fA-F]{0,4}$'
|
local regex='^([0-9a-fA-F]{0,4}:){1,7}[0-9a-fA-F]{0,4}$'
|
||||||
if [[ $ip =~ $regex ]]; then
|
if [[ $ip =~ $regex ]]; then
|
||||||
if [[ -t 1 ]]; then
|
if [[ -t 1 ]]; then
|
||||||
echo "The given IPv6 is valid."
|
disp "The given IPv6 is valid."
|
||||||
fi
|
fi
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
if [[ -t 1 ]]; then
|
if [[ -t 1 ]]; then
|
||||||
echo "The given parameter is not a valid IPv6."
|
disp "The given parameter is not a valid IPv6."
|
||||||
fi
|
fi
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
export -f isipv6
|
export -f isipv6
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# Encode a string so it can be used as a URL parameter
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
urlencode() {
|
||||||
|
local LANG=C
|
||||||
|
local str="$*"
|
||||||
|
local length="${#str}"
|
||||||
|
for (( i = 0; i < length; i++ )); do
|
||||||
|
local c="${str:i:1}"
|
||||||
|
case "$c" in
|
||||||
|
[a-zA-Z0-9.~_-]) printf "$c" ;;
|
||||||
|
' ') printf '+' ;;
|
||||||
|
*) printf '%%%02X' "'$c" #| cut -d' ' -f2 ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
}
|
||||||
|
export -f urlencode
|
||||||
|
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# EOF
|
||||||
|
|||||||
@@ -1,42 +1,83 @@
|
|||||||
|
#!/bin/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.
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# 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
|
||||||
case $opt in
|
case $opt in
|
||||||
"-h"|"--help")
|
"-h" | "--help")
|
||||||
echo "dpkgs: look for an installed package by it's name."
|
echo "dpkgs: look for an installed package by it's name."
|
||||||
echo
|
echo
|
||||||
echo "Usage: dpkgs <string>"
|
echo "Usage: dpkgs <string>"
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
|
|
||||||
"-"*)
|
"-"*)
|
||||||
echo "Invalid option, use \"dpkgs --help\" to display usage."
|
disp E "Invalid option, use \"dpkgs --help\" to display usage."
|
||||||
echo
|
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
|
return 1
|
||||||
;;
|
|
||||||
|
|
||||||
*)
|
;;
|
||||||
local pkg=$1 && shift
|
|
||||||
count=$(( $count + 1 ))
|
|
||||||
[[ $count -gt 1 ]] &&
|
|
||||||
echo "*** Error: Please specify a package name, without space, eventually partial." &&
|
|
||||||
return 1
|
|
||||||
|
|
||||||
;;
|
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
[[ $count -lt 1 ]] &&
|
[[ $count -lt 1 ]] &&
|
||||||
echo "*** Error: Please specify a package name, without space, eventually partial." &&
|
disp E "Please specify a package name, without space, eventually partial." &&
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
[[ -x /usr/sbin/dpkg ]] &&
|
command -v dpkg >/dev/null 2>&1 && local cmd="dpkg -l"
|
||||||
echo "*** Error: dpkg command seems unavialable." &&
|
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
|
return 2
|
||||||
|
fi
|
||||||
dpkg -l | grep $pkg
|
$cmd | grep $pkg
|
||||||
}
|
}
|
||||||
export -f dpkgs
|
export -f pkgs
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# EOF
|
||||||
|
|||||||
@@ -1,17 +1,52 @@
|
|||||||
|
#!/bin/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.
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Search processes matching the given string
|
# Search processes matching the given string
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
ppg ()
|
ppg()
|
||||||
{
|
{
|
||||||
ps -edf | grep $@ | grep -v "grep $@"
|
ps -edf | grep "$@" | grep -v "grep $@"
|
||||||
}
|
}
|
||||||
export -f ppg
|
export -f ppg
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Get PID list of the given process name
|
# Get PID list of the given process name
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
gpid ()
|
gpid()
|
||||||
{
|
{
|
||||||
[[ $UID -eq 0 ]] && local psopt="-A"
|
[[ $UID -eq 0 ]] && local psopt="-A"
|
||||||
[[ $# -eq 1 ]] && local single=1
|
[[ $# -eq 1 ]] && local single=1
|
||||||
@@ -27,14 +62,33 @@ gpid ()
|
|||||||
}
|
}
|
||||||
export -f gpid
|
export -f gpid
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Kill all processes owned by the given users
|
# Kill all processes owned by the given users
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
ku ()
|
ku()
|
||||||
{
|
{
|
||||||
for u in $@; do
|
for u in $@; do
|
||||||
killall -u $u
|
killall -u "$u"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
export -f ku
|
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"
|
||||||
|
shift
|
||||||
|
children_pids=$(pgrep -P "$parent_pid")
|
||||||
|
|
||||||
|
for pid in $children_pids; do
|
||||||
|
kt "$pid" "$@"
|
||||||
|
done
|
||||||
|
kill "$@" "$parent_pid"
|
||||||
|
}
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# EOF
|
||||||
|
|||||||
@@ -1,9 +1,44 @@
|
|||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# 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.
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# timer_* functions : internal timing function for prompt
|
# timer_* functions : internal timing function for prompt
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
function timer_now
|
function timer_now
|
||||||
{
|
{
|
||||||
date +%s%N
|
date +%s%N 2>/dev/null || date +%s
|
||||||
}
|
}
|
||||||
|
|
||||||
function timer_start
|
function timer_start
|
||||||
@@ -41,21 +76,21 @@ function timer_stop
|
|||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Function triguered internaly by bash : defining prompt
|
# Function triguered internaly by bash : defining prompt
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
set_prompt ()
|
set_prompt()
|
||||||
{
|
{
|
||||||
Last_Command=$? # Must come first!
|
local Last_Command=$? # Must come first!
|
||||||
Blue='\[\e[0;34m\]'
|
local Blue='\[\e[0;34m\]'
|
||||||
White='\[\e[01;37m\]'
|
local White='\[\e[01;37m\]'
|
||||||
Yellow='\[\e[01;93m\]'
|
local Yellow='\[\e[01;93m\]'
|
||||||
Red='\[\e[01;31m\]'
|
local Red='\[\e[01;31m\]'
|
||||||
Green='\[\e[01;32m\]'
|
local Green='\[\e[01;32m\]'
|
||||||
OnGrey='\[\e[47m\]'
|
local OnGrey='\[\e[47m\]'
|
||||||
OnRed='\[\e[41m\]'
|
local OnRed='\[\e[41m\]'
|
||||||
OnBlue='\[\e[44m\]'
|
local OnBlue='\[\e[44m\]'
|
||||||
ICyan='\[\e[0;96m\]'
|
local ICyan='\[\e[0;96m\]'
|
||||||
Default='\[\e[00m\]'
|
local Default='\[\e[00m\]'
|
||||||
FancyX='\342\234\227'
|
local FancyX='\342\234\227'
|
||||||
Checkmark='\342\234\223'
|
local Checkmark='\342\234\223'
|
||||||
|
|
||||||
# Begin with time
|
# Begin with time
|
||||||
PS1="\[\e[s$Blue$OnGrey [ \t ] $OnBlue"
|
PS1="\[\e[s$Blue$OnGrey [ \t ] $OnBlue"
|
||||||
@@ -88,3 +123,6 @@ set_prompt ()
|
|||||||
# the text color to the default.
|
# the text color to the default.
|
||||||
PS1+="$ICyan\\w \\\$$Default "
|
PS1+="$ICyan\\w \\\$$Default "
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# EOF
|
||||||
|
|||||||
295
profile.d/pwd.sh
Executable file → Normal file
295
profile.d/pwd.sh
Executable file → Normal file
@@ -1,3 +1,39 @@
|
|||||||
|
#!/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.
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# genpwd : generate a password with different criteria
|
# genpwd : generate a password with different criteria
|
||||||
# default 16 car with up and low car, symbol and number
|
# default 16 car with up and low car, symbol and number
|
||||||
@@ -9,143 +45,146 @@ genpwd()
|
|||||||
local occurs=2 # Bug, if set to 1, seems to be ignored
|
local occurs=2 # Bug, if set to 1, seems to be ignored
|
||||||
local symb=1 maj=1 min=1 numb=1
|
local symb=1 maj=1 min=1 numb=1
|
||||||
local nbpwd=1
|
local nbpwd=1
|
||||||
|
local extcar
|
||||||
|
|
||||||
for opt in $@; do
|
for opt in $@; do
|
||||||
case $opt in
|
case $opt in
|
||||||
"-h"|"--help")
|
"-h" | "--help")
|
||||||
echo "genpwd: generate a secure random password."
|
echo "genpwd: generate one or more secure random password."
|
||||||
echo
|
echo
|
||||||
echo "Usage: genpwd [options] [--extracars=<cars>] [--length=<n>] [nb_passwd]"
|
echo "Usage: genpwd [options] [--extracars=<cars>] [--length=<n>] [nb_passwd]"
|
||||||
echo
|
echo
|
||||||
echo "Options:"
|
echo "Options:"
|
||||||
echo " -h, --help Display that help screen"
|
echo " -h, --help Display that help screen"
|
||||||
echo " -s, --nosymbols Exclude symbols"
|
echo " -s, --nosymbols Exclude symbols"
|
||||||
echo " -n, --nonumbers Exclude numbers"
|
echo " -n, --nonumbers Exclude numbers"
|
||||||
echo " -u, --noup Exclude uppercase letters"
|
echo " -u, --noup Exclude uppercase letters"
|
||||||
echo " -l, --nolow Exclude lowercase letters"
|
echo " -l, --nolow Exclude lowercase letters"
|
||||||
echo " -e=<c>, --extracars=<c>"
|
echo " -e=<c>, --extracars=<c>"
|
||||||
echo " Add the given caracters to the possible caracter list"
|
echo " Add the given caracters to the possible caracter list"
|
||||||
echo " -L=<n>, --length=<n>"
|
echo " -L=<n>, --length=<n>"
|
||||||
echo " Set length of the password (default is $length)"
|
echo " Set length of the password (default is $length)"
|
||||||
echo " -o=<n>, --occurences=<n>"
|
echo " -o=<n>, --occurences=<n>"
|
||||||
echo " Set the maximum occurences of a same caracter (default is $occurs)"
|
echo " Set the maximum occurences of a same caracter (default is $occurs)"
|
||||||
echo
|
echo
|
||||||
echo "If the --extracars parameter is given, at least one of the given caracter will"
|
echo "If the --extracars parameter is given, at least one of the given caracter will"
|
||||||
echo "be used in the final password."
|
echo "be used in the final password."
|
||||||
echo
|
echo
|
||||||
echo "Please note that some caracters might be interpreted by Bash or Awk programs,"
|
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 "and thus, cannot be used without provoquing errors. Those identified caracters"
|
||||||
echo "are :"
|
echo "are :"
|
||||||
echo ' * ? \ $ { }'
|
echo ' * ? \ $ { }'
|
||||||
echo
|
echo
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
"-s"|"--nosymbols")
|
"-s" | "--nosymbols")
|
||||||
symb=0
|
symb=0
|
||||||
;;
|
;;
|
||||||
"-n"|"--nonumbers")
|
"-n" | "--nonumbers")
|
||||||
numb=0
|
numb=0
|
||||||
;;
|
;;
|
||||||
"-u"|"--noup")
|
"-u" | "--noup")
|
||||||
maj=0
|
maj=0
|
||||||
;;
|
;;
|
||||||
"-l"|"--nolow")
|
"-l" | "--nolow")
|
||||||
min=0
|
min=0
|
||||||
;;
|
;;
|
||||||
"-e"?*|"--extracars"?*)
|
"-e"?* | "--extracars"?*)
|
||||||
local extcar=$(echo "$opt" | cut -f 2- -d '=')
|
extcar=$(echo "$opt" | cut -f 2- -d '=')
|
||||||
;;
|
;;
|
||||||
"-L"?*|"--length"?*)
|
"-L"?* | "--length"?*)
|
||||||
local length=$(echo "$opt" | cut -f 2- -d '=')
|
local length=$(echo "$opt" | cut -f 2- -d '=')
|
||||||
if ! [[ $length =~ ^[0-9]+$ ]]; then
|
if ! [[ $length =~ ^[0-9]+$ ]]; then
|
||||||
echo "The --length parameter requires a number."
|
disp E "The --length parameter requires a number."
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
"-o"?*|"--occurences"?*)
|
"-o"?* | "--occurences"?*)
|
||||||
local occurs=$(echo "$opt" | cut -f 2- -d '=')
|
local occurs=$(echo "$opt" | cut -f 2- -d '=')
|
||||||
if ! [[ $occurs =~ ^[1-9]+$ ]]; then
|
if ! [[ $occurs =~ ^[1-9]+$ ]]; then
|
||||||
echo "The --occurs parameter requires a number from 1 to 9."
|
disp E "The --occurs parameter requires a number from 1 to 9."
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
"-*")
|
"-*")
|
||||||
echo "Unknow parameter ${opt}."
|
disp E "Unknow parameter ${opt}."
|
||||||
return 1
|
return 1
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
if ! [[ $opt =~ ^[1-9]+$ ]]; then
|
if ! [[ $opt =~ ^[1-9]+$ ]]; then
|
||||||
echo "Unknow parameter ${opt}."
|
disp E "Unknow parameter ${opt}."
|
||||||
return 1
|
return 1
|
||||||
else
|
else
|
||||||
local nbpwd=$opt
|
nbpwd=$opt
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
# Function selecting a random caracter from the list in parameter
|
# Function selecting a random caracter from the list in parameter
|
||||||
pickcar()
|
pickcar() {
|
||||||
{
|
# When a character is picked we check if it's not appearing already twice
|
||||||
# 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
|
||||||
# elsewhere, we choose an other char, to compensate weak bash randomizer
|
while [[ -z $char ]]; do
|
||||||
while [[ -z $char ]]; do
|
local char="${1:RANDOM%${#1}:1} $RANDOM"
|
||||||
local char=$(echo ${1:RANDOM%${#1}:1} $RANDOM)
|
if [[ $(awk -F"$char" '{print NF-1}' <<<"$picked") -gt $occurs ]]; then
|
||||||
if [[ $(awk -F"$char" '{print NF-1}' <<< "$picked") -gt $occurs ]]; then
|
unset char
|
||||||
unset char
|
fi
|
||||||
fi
|
done
|
||||||
done
|
picked+="$char"
|
||||||
picked+="$char"
|
echo "$char"
|
||||||
echo "$char"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
echo "Generating $nbpwd passwords, please wait..."
|
disp I "Generating $nbpwd passwords, please wait..."
|
||||||
for n in $( seq 1 $nbpwd ); do
|
for n in $(seq 1 $nbpwd); do
|
||||||
{
|
{
|
||||||
local carset='' # store final caracter set to use
|
local carset='' # store final caracter set to use
|
||||||
local picked='' # store already used caracter
|
local picked='' # store already used caracter
|
||||||
local rlength=0 # store already assigned length of caracters
|
local rlength=0 # store already assigned length of caracters
|
||||||
|
|
||||||
# ?, *, $ and \ impossible to use to my knowledge as it would be interpreted
|
# ?, *, $ and \ impossible to use to my knowledge as it would be interpreted
|
||||||
if [[ $symb == 1 ]]; then
|
if [[ $symb == 1 ]]; then
|
||||||
pickcar '!.@#&%/^-_'
|
pickcar '!.@#&%/^-_'
|
||||||
carset+='!.@#&%/^-_'
|
carset+='!.@#&%/^-_'
|
||||||
(( rlength++ ))
|
((rlength++))
|
||||||
fi
|
fi
|
||||||
if [[ $numb == 1 ]]; then
|
if [[ $numb == 1 ]]; then
|
||||||
pickcar '0123456789'
|
pickcar '0123456789'
|
||||||
carset+='0123456789'
|
carset+='0123456789'
|
||||||
(( rlength++ ))
|
((rlength++))
|
||||||
fi
|
fi
|
||||||
if [[ $maj == 1 ]]; then
|
if [[ $maj == 1 ]]; then
|
||||||
pickcar 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
pickcar 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
||||||
carset+='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
carset+='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
||||||
(( rlength++ ))
|
((rlength++))
|
||||||
fi
|
fi
|
||||||
if [[ $min == 1 ]]; then
|
if [[ $min == 1 ]]; then
|
||||||
pickcar 'abcdefghijklmnopqrstuvwxyz'
|
pickcar 'abcdefghijklmnopqrstuvwxyz'
|
||||||
carset+='abcdefghijklmnopqrstuvwxyz'
|
carset+='abcdefghijklmnopqrstuvwxyz'
|
||||||
(( rlength++ ))
|
((rlength++))
|
||||||
fi
|
fi
|
||||||
if [[ -n $extcar ]]; then
|
if [[ -n $extcar ]]; then
|
||||||
pickcar "$extcar"
|
pickcar "$extcar"
|
||||||
carset+=$extcar
|
carset+=$extcar
|
||||||
(( rlength++ ))
|
((rlength++))
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if we have enough car to have something viable
|
# Check if we have enough car to have something viable
|
||||||
if [[ ${#carset} -lt $length ]]; then
|
if [[ ${#carset} -lt $length ]]; then
|
||||||
echo 'Error: not enought caracters are authorised for the password length.'
|
disp E 'Not enought caracters are authorised for the password length.'
|
||||||
echo 'Please allow more caracter (preferably) or reduce password lentgh.'
|
disp E 'Please allow more caracter (preferably) or reduce password lentgh.'
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
for i in $( seq 1 $(( $length - $rlength )) ); do
|
for i in $(seq 1 $(($length - $rlength))); do
|
||||||
pickcar "$carset"
|
pickcar "$carset"
|
||||||
done
|
done
|
||||||
} | sort -R | awk '{printf "%s", $1}'
|
} | sort -R | awk '{printf "%s", $1}'
|
||||||
unset picked carset rlength
|
unset picked carset rlength
|
||||||
echo
|
echo
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
export -f genpwd
|
export -f genpwd
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# EOF
|
||||||
|
|||||||
@@ -1,3 +1,39 @@
|
|||||||
|
#!/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.
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Let the rain fall
|
# Let the rain fall
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
@@ -8,7 +44,7 @@ rain()
|
|||||||
local rain_colors=("\e[37m" "\e[37;1m")
|
local rain_colors=("\e[37m" "\e[37;1m")
|
||||||
# More from 256 color mode
|
# More from 256 color mode
|
||||||
for i in {244..255}; do
|
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
|
done
|
||||||
local rain_tab=${#rain_cars[@]}
|
local rain_tab=${#rain_cars[@]}
|
||||||
local rain_color_tab=${#rain_colors[@]}
|
local rain_color_tab=${#rain_colors[@]}
|
||||||
@@ -19,18 +55,17 @@ rain()
|
|||||||
local X=0 Y=0 drop_length=0 rain_drop=0
|
local X=0 Y=0 drop_length=0 rain_drop=0
|
||||||
local max_rain_width=0 new_rain_odd=0 falling_odd=0
|
local max_rain_width=0 new_rain_odd=0 falling_odd=0
|
||||||
|
|
||||||
|
|
||||||
sigwinch() {
|
sigwinch() {
|
||||||
term_width=$(tput cols)
|
term_width=$(tput cols)
|
||||||
term_height=$(tput lines)
|
term_height=$(tput lines)
|
||||||
#step_duration=0.025
|
#step_duration=0.025
|
||||||
(( max_rain_width = term_width * term_height / 4 ))
|
((max_rain_width = term_width * term_height / 4))
|
||||||
(( max_rain_height = term_height < 10 ? 1 : term_height / 10 ))
|
((max_rain_height = term_height < 10 ? 1 : term_height / 10))
|
||||||
# In percentage
|
# In percentage
|
||||||
(( new_rain_odd = term_height > 50 ? 100 : term_height * 2 ))
|
((new_rain_odd = term_height > 50 ? 100 : term_height * 2))
|
||||||
(( new_rain_odd = new_rain_odd * 75 / 100 ))
|
((new_rain_odd = new_rain_odd * 75 / 100))
|
||||||
(( falling_odd = term_height > 25 ? 100 : term_height * 4 ))
|
((falling_odd = term_height > 25 ? 100 : term_height * 4))
|
||||||
(( falling_odd = falling_odd * 90 / 100 ))
|
((falling_odd = falling_odd * 90 / 100))
|
||||||
}
|
}
|
||||||
|
|
||||||
do_exit() {
|
do_exit() {
|
||||||
@@ -45,19 +80,19 @@ rain()
|
|||||||
Y=${rains[idx + 1]}
|
Y=${rains[idx + 1]}
|
||||||
drop_length=${rains[idx + 4]}
|
drop_length=${rains[idx + 4]}
|
||||||
for ((y = Y; y < Y + drop_length; y++)); do
|
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 "
|
echo -ne "\e[${y};${X}H "
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
|
|
||||||
for ((idx = 0; idx < num_rains * num_rain_metadata; idx += num_rain_metadata)); do
|
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
|
# Falling
|
||||||
if (( ++rains[idx + 1] > term_height )); then
|
if ((++rains[idx + 1] > term_height)); then
|
||||||
# Out of screen, bye sweet <3
|
# Out of screen, bye sweet <3
|
||||||
rains=("${rains[@]:0:idx}"
|
rains=("${rains[@]:0:idx}"
|
||||||
"${rains[@]:idx+num_rain_metadata:num_rains*num_rain_metadata}")
|
"${rains[@]:idx+num_rain_metadata:num_rains*num_rain_metadata}")
|
||||||
(( num_rains-- ))
|
((num_rains--))
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@@ -67,7 +102,7 @@ rain()
|
|||||||
drop_color=${rains[idx + 3]}
|
drop_color=${rains[idx + 3]}
|
||||||
drop_length=${rains[idx + 4]}
|
drop_length=${rains[idx + 4]}
|
||||||
for ((y = Y; y < Y + drop_length; y++)); do
|
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}"
|
echo -ne "\e[${y};${X}H${drop_color}${rain_drop}"
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
@@ -83,24 +118,24 @@ rain()
|
|||||||
local rains=()
|
local rains=()
|
||||||
local num_rains=0
|
local num_rains=0
|
||||||
sigwinch
|
sigwinch
|
||||||
while (( exit_st <= 0 )); do
|
while ((exit_st <= 0)); do
|
||||||
if (( $exit_st <=0 )); then
|
if (($exit_st <= 0)); then
|
||||||
read -n 1 -t $step_duration ch
|
read -n 1 -t $step_duration ch
|
||||||
case "$ch" in
|
case "$ch" in
|
||||||
q|Q)
|
q | Q)
|
||||||
do_exit
|
do_exit
|
||||||
;;
|
;;
|
||||||
esac
|
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
|
# Need new |, 1-based
|
||||||
rain_drop="${rain_cars[rain_tab * RANDOM / 32768]}"
|
rain_drop="${rain_cars[rain_tab * RANDOM / 32768]}"
|
||||||
drop_color="${rain_colors[rain_color_tab * RANDOM / 32768]}"
|
drop_color="${rain_colors[rain_color_tab * RANDOM / 32768]}"
|
||||||
drop_length=$(( max_rain_height * RANDOM / 32768 + 1 ))
|
drop_length=$((max_rain_height * RANDOM / 32768 + 1))
|
||||||
X=$(( term_width * RANDOM / 32768 + 1 ))
|
X=$((term_width * RANDOM / 32768 + 1))
|
||||||
Y=$(( 1 - drop_length ))
|
Y=$((1 - drop_length))
|
||||||
rains=( "${rains[@]}" "$X" "$Y" "$rain_drop" "$drop_color" "$drop_length" )
|
rains=("${rains[@]}" "$X" "$Y" "$rain_drop" "$drop_color" "$drop_length")
|
||||||
(( num_rains++ ))
|
((num_rains++))
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Let rain fall!
|
# Let rain fall!
|
||||||
@@ -117,3 +152,6 @@ rain()
|
|||||||
trap - WINCH
|
trap - WINCH
|
||||||
}
|
}
|
||||||
export -f rain
|
export -f rain
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# EOF
|
||||||
|
|||||||
132
profile.d/ssh.sh
132
profile.d/ssh.sh
@@ -1,70 +1,116 @@
|
|||||||
|
#!/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.
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Remove host from know_host (name and IP) for the active user
|
# Remove host from know_host (name and IP) for the active user
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
rmhost ()
|
rmhost()
|
||||||
{
|
{
|
||||||
if [[ "$#" -lt 1 ]]; then
|
if [[ "$#" -lt 1 ]]; then
|
||||||
echo "Error: incorrect number of parameters."
|
disp E "Incorrect number of parameters."
|
||||||
echo "Usage: rmhost <hostname|ip> [hostname2|ip2 [...]]"
|
disp E "Usage: rmhost <hostname|ip> [hostname2|ip2 [...]]"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
while [[ $1 ]]; do
|
while [[ $1 ]]; do
|
||||||
local hst=$1 && shift
|
local hst=$1 && shift
|
||||||
isipv4 $hst > /dev/null
|
isipv4 "$hst" >/dev/null
|
||||||
local v4=$?
|
local v4=$?
|
||||||
isipv6 $hst > /dev/null
|
isipv6 "$hst" >/dev/null
|
||||||
local v6=$?
|
local v6=$?
|
||||||
|
|
||||||
if [[ $v4 -eq 0 || $v6 -eq 0 ]]; then
|
if [[ $v4 -eq 0 || $v6 -eq 0 ]]; then
|
||||||
local ip=$hst
|
local ip=$hst
|
||||||
unset hst
|
unset hst
|
||||||
fi
|
fi
|
||||||
unset v4 v6
|
unset v4 v6
|
||||||
|
|
||||||
if [[ ! $ip && $hst ]]; then
|
if [[ ! $ip && $hst ]]; then
|
||||||
ip=$(host $hst | grep "has address" | awk '{print $NF}')
|
if ! ip=$(host "$hst" 2>/dev/null | awk '/has address/ {print $NF; exit}'); then
|
||||||
[[ ! $? ]] &&
|
disp E "Impossible to extract IP from hostname." &&
|
||||||
echo "*** rmhost(): Error extracting IP from hostname." &&
|
return 1
|
||||||
return 1
|
fi
|
||||||
fi
|
[[ -z $ip ]] && {
|
||||||
|
disp E "Impossible to extract IP from hostname."
|
||||||
if [[ $hst ]]; then
|
return 1;
|
||||||
echo "Removing host $hst from ssh known_host..."
|
}
|
||||||
ssh-keygen -R $hst > /dev/null
|
fi
|
||||||
fi
|
|
||||||
if [[ $ip ]]; then
|
if [[ $hst ]]; then
|
||||||
echo "Removing IP $ip from ssh known_host..."
|
disp I "Removing host $hst from ssh known_host..."
|
||||||
ssh-keygen -R $ip > /dev/null
|
ssh-keygen -R $hst >/dev/null
|
||||||
fi
|
fi
|
||||||
unset hst ip
|
if [[ $ip ]]; then
|
||||||
|
disp I "Removing IP $ip from ssh known_host..."
|
||||||
|
ssh-keygen -R $ip >/dev/null
|
||||||
|
fi
|
||||||
|
unset hst ip
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
export -f rmhost
|
export -f rmhost
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Login root via SSH on the given machine
|
# Login root via SSH on the given machine
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
ssr ()
|
ssr()
|
||||||
{
|
{
|
||||||
for opt in $@ ; do
|
for opt in $@; do
|
||||||
case $opt in
|
case $opt in
|
||||||
"-h"|"--help")
|
"-h" | "--help")
|
||||||
echo "ssr: do a root user ssh login."
|
echo "ssr: do a root user ssh login."
|
||||||
echo
|
echo
|
||||||
echo "Usage: ssr <server [ssh options]>"
|
echo "Usage: ssr <server [ssh options]>"
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
command -v ssh >/dev/null 2>&1 || {
|
||||||
|
disp E "ssh is not installed."
|
||||||
|
return 127
|
||||||
|
}
|
||||||
[[ ! $1 ]] &&
|
[[ ! $1 ]] &&
|
||||||
echo "Please specify the server you want to log in." &&
|
disp E "Please specify the server you want to log in." &&
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
local srv=$1 && shift
|
local srv=$1 && shift
|
||||||
|
|
||||||
ssh -Y root@$srv $@
|
ssh -Y root@"$srv" "$@"
|
||||||
}
|
}
|
||||||
export -f ssr
|
export -f ssr
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# EOF
|
||||||
|
|||||||
135
profile.d/updates.sh
Normal file
135
profile.d/updates.sh
Normal file
@@ -0,0 +1,135 @@
|
|||||||
|
#!/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 BASE_URL="https://git.geoffray-levasseur.org/fatalerrors/profile"
|
||||||
|
export UPDT_URL="$BASE_URL/raw/branch/master"
|
||||||
|
export ARCH_URL="$BASE_URL/archive/master.tar.gz"
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# 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 $vfile ]]; then
|
||||||
|
local lastver=$(cat $vfile)
|
||||||
|
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=1
|
||||||
|
else
|
||||||
|
disp I "Your version is up-to-date."
|
||||||
|
result=0
|
||||||
|
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()
|
||||||
|
{
|
||||||
|
check_updates -q
|
||||||
|
local need_update=$?
|
||||||
|
[[ $need_update -ne 1 ]] && {
|
||||||
|
disp "No update available."
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
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 || {
|
||||||
|
disp E "Git pull failed, upgrade not applyed."
|
||||||
|
cd "$curdir"
|
||||||
|
return 2
|
||||||
|
}
|
||||||
|
disp I "Successfully upgraded using git."
|
||||||
|
cd "$curdir"
|
||||||
|
else
|
||||||
|
disp I "No Git detected. Downloading and applying upgrade from archive..."
|
||||||
|
local tmpdir="/tmp/profile_upg.$$"
|
||||||
|
mkdir -p "$tmpdir" || {
|
||||||
|
disp E "Failed to create temporary directory."
|
||||||
|
return 4
|
||||||
|
}
|
||||||
|
|
||||||
|
local archive="$tmpdir/profile.tar.gz"
|
||||||
|
wget -q "$ARCH_URL" -O "$archive" || {
|
||||||
|
disp E "Failed to download archive."
|
||||||
|
rm -rf "$tmpdir"
|
||||||
|
return 5
|
||||||
|
}
|
||||||
|
|
||||||
|
tar -xzf "$archive" -C "$tmpdir" || {
|
||||||
|
disp E "Archive extraction failed."
|
||||||
|
rm -rf "$tmpdir"
|
||||||
|
return 6
|
||||||
|
}
|
||||||
|
|
||||||
|
disp I "Installing new version..."
|
||||||
|
cp -r "$tmpdir"/profile/* "$MYPATH"/ || {
|
||||||
|
disp E "Failed to copy new files to $MYPATH."
|
||||||
|
rm -rf "$tmpdir"
|
||||||
|
return 7
|
||||||
|
}
|
||||||
|
|
||||||
|
disp I "Upgrade complete. You should now logout and login again."
|
||||||
|
rm -rf "$tmpdir"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
# EOF
|
||||||
98
profile.sh
98
profile.sh
@@ -1,42 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Begin profile
|
# Begin profile
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Initial version from Beyond Linux From Scratch by
|
|
||||||
# * James Robertson <jameswrobertson@earthlink.net>
|
|
||||||
# * Dagmar d'Surreal <rivyqntzne@pbzpnfg.arg>
|
|
||||||
# ------------------------------------------------------------------------------
|
|
||||||
# Current version from Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
|
|
||||||
# 16/02/2013 v1.0.0 : Initial version
|
|
||||||
# 24/10/2015 v2.0.0 : Added advanced functionnalities (clean, srr, etc.)
|
|
||||||
# 04/02/2017 v2.0.1 : clean improvements (--shell)
|
|
||||||
# 16/09/2018 v2.1.0 : Added rmhost, setc, setfr, more locales management
|
|
||||||
# 23/09/2019 v2.1.1 : [bugfix] dpkgs
|
|
||||||
# 24/09/2019 v2.1.2 : [bugfix] bug in profile version display
|
|
||||||
# 16/12/2019 v2.2.0 : Added showinfo, primary write of showdiskmap
|
|
||||||
# 08/01/2020 v2.3.0 : Added use of figlet and neofetch as a motd replace
|
|
||||||
# 16/01/2020 v2.3.1 : [bugfix] non-interactive were blocked with some functions
|
|
||||||
# 31/01/2020 v2.3.2 : Figlet: changed default font to ansi_shadow
|
|
||||||
# 02/03/2020 v2.4.0 : Added command auzip
|
|
||||||
# 03/03/2020 v2.5.0 : Added command taz and rmspc, auzip => utaz improved
|
|
||||||
# 05/03/2020 v2.5.1 : Language consistancy fix, added pigz support in taz
|
|
||||||
# 06/03/2020 v2.5.2 : Few aliases sorted out
|
|
||||||
# 11/09/2020 v2.5.3 : Few more aliases, improved code consistancy and typo,
|
|
||||||
# : improved utaz, removed showdiskmap, removed remaining French,
|
|
||||||
# : added license information for future publication
|
|
||||||
# 24/10/2020 v2.6.0 : Added session save and restore for Konsole
|
|
||||||
# 25/12/2020 v2.6.1 : Add check on rmhost, improvements rmspc, created expendlist
|
|
||||||
# 26/02/2021 v2.6.2 : [bugfix] taz: corrected bug with trailing slash on directories
|
|
||||||
# 18/10/2021 v2.6.3 : changed PS1 for status bar style version, few minor improvements
|
|
||||||
# 21/06/2022 v2.7.0 : added isipv4 and isipv6, use it in rmhost as an improvement
|
|
||||||
# 22/06/2022 v2.7.1 : [bugfix] few minor corrections, added help command
|
|
||||||
# 24/06/2022 v2.8.0 : Added backtrace, error and settrace, corrected showinfo
|
|
||||||
# 19/07/2022 v2.8.1 : few cleanup, fixes and optimizations
|
|
||||||
# 29/07/2022 v2.8.2 : added warning for non bash users
|
|
||||||
# 27/08/2022 v3.0.0 : splitted everything, added rain screensaver
|
|
||||||
# 07/11/2022 v3.0.1 : added concatenation to rmspc, added ku, error managed in meteo
|
|
||||||
# 08/11/2022 v3.1.0 : added password generator
|
|
||||||
# 10/11/2022 v3.1.1 : genpwd: test if password is doable
|
|
||||||
# ------------------------------------------------------------------------------
|
|
||||||
# Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
|
# Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
|
||||||
# Protected by the BSD3 license. Please read bellow for details.
|
# Protected by the BSD3 license. Please read bellow for details.
|
||||||
#
|
#
|
||||||
@@ -71,62 +35,80 @@
|
|||||||
# * OF SUCH DAMAGE.
|
# * OF SUCH DAMAGE.
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
export PROFVERSION="3.1.1"
|
if [[ ! $SHELL =~ bash|zsh ]]; then
|
||||||
|
echo "That environment script is designed to be used with bash or zsh being the shell."
|
||||||
export DEFAULT_CITY="Toulouse"
|
echo "Please consider using bash or zsh instead, or patch me ;)!"
|
||||||
|
|
||||||
if [[ ! $(echo $SHELL | grep bash) ]]; then
|
|
||||||
echo "That script is designed to be used with bash as being the shell."
|
|
||||||
echo "Please consider using bash instead, or patch me ;) !"
|
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# path* : private functions for PATH variable management
|
# path* : private functions for PATH variable management
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
pathremove ()
|
pathremove()
|
||||||
{
|
{
|
||||||
local ifs=':'
|
local IFS=':'
|
||||||
local newpath
|
local newpath
|
||||||
local dir
|
local dir
|
||||||
local pathvar=${2:-PATH}
|
local pathvar=${2:-PATH}
|
||||||
for dir in ${!pathvar} ; do
|
for dir in ${!pathvar}; do
|
||||||
if [ "$dir" != "$1" ] ; then
|
if [ "$dir" != "$1" ]; then
|
||||||
newpath=${newpath:+$newpath:}$dir
|
newpath=${newpath:+$newpath:}$dir
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
export $pathvar="$newpath"
|
export $pathvar="$newpath"
|
||||||
}
|
}
|
||||||
|
|
||||||
pathprepend ()
|
pathprepend()
|
||||||
{
|
{
|
||||||
pathremove $1 $2
|
pathremove $1 $2
|
||||||
local pathvar=${2:-PATH}
|
local pathvar=${2:-PATH}
|
||||||
export $pathvar="$1${!pathvar:+:${!pathvar}}"
|
export $pathvar="$1${!pathvar:+:${!pathvar}}"
|
||||||
}
|
}
|
||||||
|
|
||||||
pathappend ()
|
pathappend()
|
||||||
{
|
{
|
||||||
pathremove $1 $2
|
pathremove $1 $2
|
||||||
local pathvar=${2:-PATH}
|
local pathvar=${2:-PATH}
|
||||||
export $pathvar="${!pathvar:+${!pathvar}:}$1"
|
export $pathvar="${!pathvar:+${!pathvar}:}$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# ********************************** MAIN PROGRAM ******************************
|
# ********************************** 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
|
# Build PATH environment variable
|
||||||
if [[ $EUID -eq 0 ]] ; then
|
if [[ $EUID -eq 0 ]]; then
|
||||||
pathappend /sbin:/usr/sbin
|
pathappend /sbin:/usr/sbin
|
||||||
fi
|
fi
|
||||||
[[ -d /share/services/gestparc ]] && pathappend /share/services/gestparc
|
[[ -d /share/services/gestparc ]] && pathappend /share/services/gestparc
|
||||||
[[ -d ~/bin ]] && pathappend ~/bin
|
[[ -d ~/bin ]] && pathappend ~/bin
|
||||||
[[ -d ~/.local/bin ]] && pathappend ~/.local/bin
|
[[ -d ~/.local/bin ]] && pathappend ~/.local/bin
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# Default values are set here and will be overloaded with config file if any
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
# Set bash history
|
# Set bash history
|
||||||
export HISTSIZE=50000
|
export HISTSIZE=50000
|
||||||
export HISTIGNORE="&:[bf]g:exit"
|
export HISTIGNORE="&:[bf]g:exit"
|
||||||
@@ -142,17 +124,22 @@ 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 ]] && . $MYPATH/etc/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
|
||||||
done
|
done
|
||||||
@@ -188,6 +175,7 @@ if [[ $INTERACTIVE ]]; then
|
|||||||
alias du='du -ch'
|
alias du='du -ch'
|
||||||
|
|
||||||
alias sdu='du -sk ./* | sort -n'
|
alias sdu='du -sk ./* | sort -n'
|
||||||
|
alias hdu='du -hs ./* | sort -H'
|
||||||
|
|
||||||
# Define PS1
|
# Define PS1
|
||||||
trap 'timer_start' DEBUG
|
trap 'timer_start' DEBUG
|
||||||
@@ -196,7 +184,7 @@ if [[ $INTERACTIVE ]]; then
|
|||||||
# Set default language
|
# Set default language
|
||||||
setfr
|
setfr
|
||||||
showinfo
|
showinfo
|
||||||
echo "Profile version $PROFVERSION chargé..."
|
disp I "Profile version $PROFVERSION chargé..."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Cleanup
|
# Cleanup
|
||||||
|
|||||||
Reference in New Issue
Block a user