Compare commits
43 Commits
v3.2.0
...
2ece711e1a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2ece711e1a | ||
|
|
39a7e7b40f | ||
|
|
6d5d872b71 | ||
|
|
128cfe8c87 | ||
|
|
e1c2705fdd | ||
|
|
368bc11acf | ||
|
|
a068d57ba5 | ||
|
|
ffee8c2e47 | ||
|
|
9ff5792790 | ||
|
|
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 |
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
|
||||||
|
|||||||
147
history.txt
Normal file
147
history.txt
Normal file
@@ -0,0 +1,147 @@
|
|||||||
|
------------------------------------------------------------------------------
|
||||||
|
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:
|
||||||
|
------------------------------------------------------------------------------
|
||||||
|
# 05/03/2026 v3.6.1
|
||||||
|
Fix a typo in compress.sh
|
||||||
|
|
||||||
|
# 05/03/2026 v3.6.0
|
||||||
|
Improved utaz to make it multiformat with lot of it
|
||||||
|
Introduced ppu and ppn
|
||||||
|
Improved update system
|
||||||
|
|
||||||
|
# 04/03/2026 v3.5.0
|
||||||
|
rain has now configurable speed and color
|
||||||
|
showinfo adapted to fastfetch, replacing neofetch
|
||||||
|
|
||||||
|
# 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,107 +1,360 @@
|
|||||||
|
#!/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
|
||||||
|
# Usage: utaz [option] [directorie(s)|file(s)]
|
||||||
|
# Options:
|
||||||
|
# -h, --help Display that help screen
|
||||||
|
# -d, --delete If decompression succeeded, delete the source file
|
||||||
|
# -c, --create-dir Always create a host directory
|
||||||
|
# -n, --no-dir Never create a host directory
|
||||||
utaz()
|
utaz()
|
||||||
{
|
{
|
||||||
for opt in $@ ; do
|
_ununzip()
|
||||||
case $opt in
|
{
|
||||||
"-h"|"--help")
|
unzip -o "$1" -d "$2" >/dev/null 2>&1
|
||||||
echo "utaz: uncompress all the given files and/or the ones found in the given"
|
}
|
||||||
echo " directories creating an host directory where needed."
|
|
||||||
echo
|
|
||||||
echo "Usage: utaz [option] [directorie(s)|file(s)]"
|
|
||||||
echo
|
|
||||||
echo "Options:"
|
|
||||||
echo " -h, --help Display that help screen"
|
|
||||||
echo " -d, --delete If decompression succeeded, delete the source file"
|
|
||||||
echo " -c, --create-dir Always create a host directory"
|
|
||||||
echo " -n, --no-dir Never create a host directory"
|
|
||||||
echo
|
|
||||||
return 0
|
|
||||||
;;
|
|
||||||
|
|
||||||
"-d"|"--delete")
|
_untar()
|
||||||
local willrm=1
|
{
|
||||||
;;
|
tar -xf "$1" -C "$2"
|
||||||
|
}
|
||||||
|
|
||||||
"-c"|"--create-dir")
|
_ungzip()
|
||||||
local createdir=1
|
{
|
||||||
;;
|
tar -xzf "$1" -C "$2"
|
||||||
|
}
|
||||||
|
|
||||||
"-n"|"--no-dir")
|
_unbzip2()
|
||||||
local nodir=1
|
{
|
||||||
;;
|
tar -xjf "$1" -C "$2"
|
||||||
|
}
|
||||||
|
|
||||||
"-"*)
|
_unxz()
|
||||||
disp E "Invalid option, use \"utaz --help\" to display options list"
|
{
|
||||||
echo
|
tar -xJf "$1" -C "$2"
|
||||||
return 1
|
}
|
||||||
;;
|
|
||||||
|
|
||||||
*)
|
_unlzop()
|
||||||
# The ${opt%/} writing is to remove trailing / if any
|
{
|
||||||
local LIST="$LIST ${opt%/}"
|
lzop -d "$1" -o "$2/$(basename "${1%.*}")"
|
||||||
;;
|
}
|
||||||
|
|
||||||
|
_unlzip()
|
||||||
|
{
|
||||||
|
if command -v plzip >/dev/null 2>&1; then
|
||||||
|
plzip -d -c "$1" > "$2/$(basename "${1%.*}")"
|
||||||
|
else
|
||||||
|
lzip -d -c "$1" > "$2/$(basename "${1%.*}")"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
_ununrar()
|
||||||
|
{
|
||||||
|
unrar x -o+ "$1" "$2/" >/dev/null 2>&1
|
||||||
|
}
|
||||||
|
|
||||||
|
_ununarj()
|
||||||
|
{
|
||||||
|
unarj e "$1" "$2/" >/dev/null 2>&1
|
||||||
|
}
|
||||||
|
|
||||||
|
_unlza()
|
||||||
|
{
|
||||||
|
# lha typically extracts into the current directory
|
||||||
|
# We ensure it hits the target directory
|
||||||
|
(cd "$2" && lha -x "../$1") >/dev/null 2>&1
|
||||||
|
}
|
||||||
|
|
||||||
|
_ununace()
|
||||||
|
{
|
||||||
|
unace x "$1" "$2/" >/dev/null 2>&1
|
||||||
|
}
|
||||||
|
|
||||||
|
_un7z()
|
||||||
|
{
|
||||||
|
7z x "$1" -o"$2/" >/dev/null 2>&1
|
||||||
|
}
|
||||||
|
|
||||||
|
_unzstd()
|
||||||
|
{
|
||||||
|
# Zstd decompresses files directly, often requiring tar for archives
|
||||||
|
tar --zstd -xf "$1" -C "$2"
|
||||||
|
}
|
||||||
|
|
||||||
|
_uncpio()
|
||||||
|
{
|
||||||
|
# CPIO requires careful directory handling
|
||||||
|
(cd "$2" && cpio -id < "../$1") >/dev/null 2>&1
|
||||||
|
}
|
||||||
|
|
||||||
|
_uncabextract()
|
||||||
|
{
|
||||||
|
# Requires 'cabextract' package
|
||||||
|
cabextract "$1" -d "$2/" >/dev/null 2>&1
|
||||||
|
}
|
||||||
|
|
||||||
|
_undeb()
|
||||||
|
{
|
||||||
|
# Extracts data content from a Debian package
|
||||||
|
dpkg-deb -x "$1" "$2/" >/dev/null 2>&1
|
||||||
|
}
|
||||||
|
|
||||||
|
_unrpm()
|
||||||
|
{
|
||||||
|
# Extracts CPIO-based payload from an RPM package
|
||||||
|
# Needs rpm2cpio and cpio
|
||||||
|
rpm2cpio "$1" | (cd "$2/" && cpio -idmv) >/dev/null 2>&1
|
||||||
|
}
|
||||||
|
|
||||||
|
local PARSED=$(getopt -o hdcn --long help,delete,create-dir,no-dir -n 'utaz' -- "$@")
|
||||||
|
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
disp E "Invalid options, use \"utaz --help\" to display usage."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
eval set -- "$PARSED"
|
||||||
|
while true; do
|
||||||
|
case "$1" in
|
||||||
|
-h|--help)
|
||||||
|
printf "utaz: uncompress all the given files and/or the ones found in the given\n"
|
||||||
|
printf " directories creating an host directory where needed.\n\n"
|
||||||
|
printf "Usage: utaz [option] [directorie(s)|file(s)]\n\n"
|
||||||
|
printf "Options:\n"
|
||||||
|
printf "\t-h, --help\t\tDisplay that help screen\n"
|
||||||
|
printf "\t-d, --delete\t\tIf decompression succeeded, delete the source file\n"
|
||||||
|
printf "\t-c, --create-dir\tAlways create a host directory\n"
|
||||||
|
printf "\t-n, --no-dir\t\tNever create a host directory\n\n"
|
||||||
|
printf "Supported archive format:\n"
|
||||||
|
printf "\t- zip\n"
|
||||||
|
printf "\t- tar.gz, .tgz\n"
|
||||||
|
printf "\t- tar.bz2, .tbz2\n"
|
||||||
|
printf "\t- tar.xz, .txz\n"
|
||||||
|
printf "\t- tar.lz, .tlz\n"
|
||||||
|
printf "\t- rar\n"
|
||||||
|
printf "\t- arj\n"
|
||||||
|
printf "\t- lha, lzh\n"
|
||||||
|
printf "\t- ace\n"
|
||||||
|
printf "\t- 7z, p7z\n"
|
||||||
|
printf "\t- zst\n"
|
||||||
|
printf "\t- cpio\n"
|
||||||
|
printf "\t- cab\n"
|
||||||
|
printf "\t- deb\n"
|
||||||
|
printf "\t- rpm\n"
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
-d|--delete)
|
||||||
|
local willrm=1
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
-c|--create-dir)
|
||||||
|
local createdir=1
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
-n|--no-dir)
|
||||||
|
local nodir=1
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--)
|
||||||
|
shift
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
disp E "Invalid option, use \"utaz --help\" to display options list"
|
||||||
|
return 1
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
# The remaining arguments after -- are the files/directories to process,
|
||||||
|
# "." is used if none is given
|
||||||
|
local FILES=("$@")
|
||||||
|
[[ ${#FILES[@]} -eq 0 ]] && FILES=(".")
|
||||||
|
|
||||||
[[ $createdir && $nodir ]] && disp E "The --create-dir and --no-dir options are mutually exclusive."
|
[[ -n ${createdir} && -n ${nodir} ]] && \
|
||||||
|
disp E "The --create-dir and --no-dir options are mutually exclusive."
|
||||||
|
|
||||||
[[ ! $LIST ]] && local LIST="."
|
for zitem in "${FILES[@]}"; do
|
||||||
|
for f in "${zitem}"/*; do
|
||||||
|
local dir="${f%.*}"
|
||||||
|
local extractor=""
|
||||||
|
case "$f" in
|
||||||
|
*.zip)
|
||||||
|
extractor="_ununzip"
|
||||||
|
;;
|
||||||
|
*.tar.gz|*.tgz)
|
||||||
|
extractor="_ungzip"
|
||||||
|
;;
|
||||||
|
*.tar.bz2|*.tbz2)
|
||||||
|
extractor="_unbzip2"
|
||||||
|
;;
|
||||||
|
*.tar.xz|*.txz)
|
||||||
|
extractor="_unxz"
|
||||||
|
;;
|
||||||
|
*.tar.lz|*.tlz)
|
||||||
|
extractor="_unlzop"
|
||||||
|
;;
|
||||||
|
*.tar)
|
||||||
|
extractor="_untar"
|
||||||
|
;;
|
||||||
|
*.rar)
|
||||||
|
extractor="_ununrar"
|
||||||
|
;;
|
||||||
|
*.arj)
|
||||||
|
extractor="_ununarj"
|
||||||
|
;;
|
||||||
|
*.lzh|*.lha)
|
||||||
|
extractor="_unlha"
|
||||||
|
;;
|
||||||
|
*.ace)
|
||||||
|
extractor="_ununace"
|
||||||
|
;;
|
||||||
|
*.7z|*.p7z)
|
||||||
|
extractor="_un7z"
|
||||||
|
;;
|
||||||
|
*.zst)
|
||||||
|
extractor="_unzstd"
|
||||||
|
;;
|
||||||
|
*.cpio)
|
||||||
|
extractor="_uncpio"
|
||||||
|
;;
|
||||||
|
*.cab)
|
||||||
|
extractor="_uncabextract"
|
||||||
|
;;
|
||||||
|
*.deb)
|
||||||
|
extractor="_undeb"
|
||||||
|
;;
|
||||||
|
*.rpm)
|
||||||
|
extractor="_unrpm"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
disp I "File ${f} is not a supported archive, skipping."
|
||||||
|
continue
|
||||||
|
;; # Skip non-archive files
|
||||||
|
esac
|
||||||
|
|
||||||
for zitem in $LIST; do
|
# Verify binary existence
|
||||||
[[ $(ls $zitem/*.zip 2> /dev/null | wc -l) -eq 0 ]] &&
|
local cmd=${extractor//_un/}
|
||||||
disp W "$zitem contains no supported archive file, skipping." &&
|
if [[ $cmd == "deb" ]]; then
|
||||||
continue
|
command -v dpkg-deb >/dev/null 2>&1 || {
|
||||||
|
disp E "The program 'dpkg-deb' is not installed, aborting."
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
elif [[ $cmd == "rpm" ]]; then
|
||||||
|
command -v rpm2cpio >/dev/null 2>&1 || {
|
||||||
|
disp E "The program 'rpm2cpio' is not installed, aborting."
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
command -v cpio >/dev/null 2>&1 || {
|
||||||
|
disp E "The program 'cpio' is not installed, aborting."
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
else
|
||||||
|
command -v ${cmd} >/dev/null 2>&1 || {
|
||||||
|
disp E "Binary ${cmd} necessary to extract ${f} is missing."
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
fi
|
||||||
|
|
||||||
for f in $zitem/*.zip; do
|
disp I "Processing archive ${f} with ${extractor}..."
|
||||||
disp I "Processing archive $zitem/$f... "
|
mkdir -p "${dir}"
|
||||||
local dir=${f::-4}
|
|
||||||
|
|
||||||
mkdir -p $dir
|
|
||||||
[[ $? -gt 0 ]] &&
|
[[ $? -gt 0 ]] &&
|
||||||
disp E "The 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
|
${extractor} "${f}" "${dir}"
|
||||||
case $? in
|
case $? in
|
||||||
0)
|
0)
|
||||||
[[ $willrm ]] && rm -f $f && disp I "File $zitem/$f deleted."
|
[[ -n ${willrm} ]] &&
|
||||||
;;
|
rm -f "${f}" && disp I "File ${zitem}/${f} deleted."
|
||||||
|
;;
|
||||||
1)
|
1)
|
||||||
|
if [[ -n ${willrm} ]]; then
|
||||||
disp W "Compression program returned a warning: deletion canceled."
|
disp W "Compression program returned a warning: deletion canceled."
|
||||||
;;
|
else
|
||||||
*)
|
disp W "Compression program returned a warning."
|
||||||
disp E "The zip file seems corrupted, failed."
|
fi
|
||||||
rm -rf $dir > /dev/null 2>&1
|
;;
|
||||||
continue
|
*)
|
||||||
;;
|
disp E "The compressed file ${f} seems corrupted, failed."
|
||||||
|
rm -rf "${dir}" >/dev/null 2>&1
|
||||||
|
continue
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
if [[ $createdir ]]; then
|
if [[ -n ${createdir} ]]; then
|
||||||
disp I "Archive extracted successfully in subdirectory."
|
disp I "Archive extracted successfully in subdirectory."
|
||||||
elif [[ $nodir ]]; then
|
elif [[ -n ${nodir} ]]; then
|
||||||
mv ./$dir/* ./ && rmdir $dir
|
mv "./${dir}/"* ./ && rmdir "${dir}"
|
||||||
disp I "Archive extracted successfully, no subdirectory needed."
|
disp I "Archive extracted successfully, no subdirectory needed."
|
||||||
else
|
else
|
||||||
subdirs=$(find $dir -maxdepth 1 | wc -l)
|
# Set nullglob to ensure the array is empty if no files match
|
||||||
if [[ $subdirs -eq 2 ]]; then
|
shopt -s nullglob
|
||||||
mv ./$dir/* ./ && rmdir $dir
|
local contents=( "${dir}"/* )
|
||||||
|
|
||||||
|
# Check if exactly one item exists and if that item is a directory
|
||||||
|
if [[ ${#contents[@]} -eq 1 ]] && [[ -d "${contents[0]}" ]]; then
|
||||||
|
# Single directory detected
|
||||||
|
mv "${contents[0]}"/* ./ && rmdir "${dir}"
|
||||||
disp I "Archive extracted successfully, no subdirectory needed."
|
disp I "Archive extracted successfully, no subdirectory needed."
|
||||||
else
|
else
|
||||||
disp I "Archive extracted successfully in subdirectory."
|
disp I "Archive extracted successfully in subdirectory."
|
||||||
fi
|
fi
|
||||||
|
shopt -u nullglob
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
export -f utaz
|
export -f utaz
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Compress directories or files into one or more archive
|
# Compress directories or files into one or more archive
|
||||||
# ------------------------------------------------------------------------------
|
# Usage: taz [option] [--parallel=<n>] [--format=<format>] [directory1 ... directoryN]
|
||||||
taz ()
|
# Options:
|
||||||
|
# -h, --help Display that help screen
|
||||||
|
# -d, --delete Delete source file or directory after success
|
||||||
|
# -f, --format Chose archive format in the given list. If several format are
|
||||||
|
# given, the smalest is kept
|
||||||
|
# -p, --parallel Number of threads to use (if allowed by underlying utility)
|
||||||
|
# -v, --verbose Display progress where possible
|
||||||
|
# -q, --quiet Display less messages (only errors and warnings)
|
||||||
|
# -1, .., -9 Compression level to use [1=fast/biggest, 9=slow/smallest]
|
||||||
|
taz()
|
||||||
{
|
{
|
||||||
_doxz()
|
_doxz()
|
||||||
{
|
{
|
||||||
@@ -116,7 +369,7 @@ taz ()
|
|||||||
disp W "xz format is not suited for long term archiving."
|
disp W "xz format is not suited for long term archiving."
|
||||||
disp I "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 $?
|
||||||
}
|
}
|
||||||
@@ -131,11 +384,11 @@ taz ()
|
|||||||
disp E "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 ]] &&
|
||||||
disp W "lzip doesn't support multithreading, falling back to 1 thread." &&
|
disp W "lzip doesn't support multithreading, falling back to 1 thread." &&
|
||||||
disp W "Consitder installing plzip to obtain multithreading abilities."
|
disp W "Consider installing plzip to obtain multithreading abilities."
|
||||||
}
|
}
|
||||||
|
|
||||||
[[ $4 ]] && local verb="-vv"
|
[[ $4 ]] && local verb="-vv"
|
||||||
@@ -159,7 +412,7 @@ taz ()
|
|||||||
local procopt=""
|
local procopt=""
|
||||||
[[ $2 -gt 1 ]] &&
|
[[ $2 -gt 1 ]] &&
|
||||||
disp W "gzip doesn't support multithreading, falling back to 1 thread." &&
|
disp W "gzip doesn't support multithreading, falling back to 1 thread." &&
|
||||||
disp W "Consitder installing pigz to obtain multithreading abilities."
|
disp W "Consider installing pigz to obtain multithreading abilities."
|
||||||
}
|
}
|
||||||
|
|
||||||
[[ $4 ]] && local verb="--verbose"
|
[[ $4 ]] && local verb="--verbose"
|
||||||
@@ -183,7 +436,7 @@ taz ()
|
|||||||
local procopt=""
|
local procopt=""
|
||||||
[[ $2 -gt 1 ]] &&
|
[[ $2 -gt 1 ]] &&
|
||||||
disp W "bzip2 doesn't support multithreading, falling back to 1 thread." &&
|
disp W "bzip2 doesn't support multithreading, falling back to 1 thread." &&
|
||||||
disp W "Consitder installing pbzip2 to obtain multithreading abilities."
|
disp W "Consider installing pbzip2 to obtain multithreading abilities."
|
||||||
}
|
}
|
||||||
|
|
||||||
[[ $4 ]] && local verb="-v"
|
[[ $4 ]] && local verb="-v"
|
||||||
@@ -208,85 +461,99 @@ taz ()
|
|||||||
return $?
|
return $?
|
||||||
}
|
}
|
||||||
|
|
||||||
for opt in $@ ; do
|
local PARSED
|
||||||
case $opt in
|
PARSED=$(getopt -o hdf:p:vq123456789 --long help,delete,format:,parallel:,verbose,quiet --name "taz" -- "$@")
|
||||||
"-h"|"--help")
|
if [ $? -ne 0 ]; then
|
||||||
echo "taz: archive all files of a directory."
|
disp E "Invalid options, use \"taz --help\" to display usage."
|
||||||
echo
|
return 1
|
||||||
echo "Usage: taz [option] [--parallel=<n>] [--format=<format>] [directory1 ... directoryN]"
|
fi
|
||||||
echo
|
eval set -- "$PARSED"
|
||||||
echo "Options:"
|
while true; do
|
||||||
echo " -h, --help Display that help screen"
|
case "$1" in
|
||||||
echo " -d, --delete Delete source file or directory after success"
|
-h|--help)
|
||||||
echo " -f, --format Chose archive format in the given list. If several format are"
|
printf "taz: archive all files of a directory.\n\n"
|
||||||
echo " given, the smalest is kept"
|
printf "Usage: taz [option] [--parallel=<n>] [--format=<format>] [directory1 ... directoryN]\n\n"
|
||||||
echo " -p, --parallel Number of threads to use (if allowed by underlying utility)"
|
printf "Options:\n"
|
||||||
echo " -v, --verbose Display progress where possible"
|
printf "\t-h, --help\tDisplay that help screen\n"
|
||||||
echo " -q, --quiet Display less messages (only errors and warnings)"
|
printf "\t-d, --delete\tDelete source file or directory after success\n"
|
||||||
echo " -1, .., -9 Compression level to use [1=fast/big, 9=slow/small]"
|
printf "\t-f, --format\tChose archive format in the given list. If several format are"
|
||||||
echo
|
printf "\t\t\tgiven, the smalest is kept\n"
|
||||||
echo "Supported archive format:"
|
printf "\t-p, --parallel\tNumber of threads to use (if allowed by underlying utility)\n"
|
||||||
echo " Param.| programs | Algo. | Description"
|
printf "\t-v, --verbose\tDisplay progress where possible\n"
|
||||||
echo " ------+---------------+-------+----------------------------------------"
|
printf "\t-q, --quiet\tDisplay less messages (only errors and warnings)\n"
|
||||||
echo " lz | plzip, lzip | lzma | Safe efficient default format"
|
printf "\t-1, .., -9\tCompression level to use [1=fast/biggest, 9=slow/smallest]\n\n"
|
||||||
echo " xz | xz | lzma2 | Unsafe, not for long term"
|
printf "Supported archive format:\n"
|
||||||
echo " bz2 | pbzip2, bzip2 | bzip2 | Historical but less efficient than lz"
|
printf "\tParam.| programs | Algo. | Description\n"
|
||||||
echo " gz | pigz, gzip | lz77 | Historical, safe, fast"
|
printf "\t------+---------------+-------+----------------------------------------\n"
|
||||||
echo " lzo | lzop | lzo | Very fast but no multithread"
|
printf "\t lz | plzip, lzip | lzma | Safe efficient default format\n"
|
||||||
echo " tar | tar | tar | No compression"
|
printf "\t xz | xz | lzma2 | Unsafe, not for long term\n"
|
||||||
echo
|
printf "\t bz2 | pbzip2, bzip2 | bzip2 | Historical but less efficient than lz\n"
|
||||||
return 0
|
printf "\t gz | pigz, gzip | lz77 | Historical, safe, fast\n"
|
||||||
;;
|
printf "\t lzo | lzop | lzo | Very fast but no multithread\n"
|
||||||
|
printf "\t tar | tar | tar | No compression\n"
|
||||||
|
printf "\n"
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
|
||||||
"-d"|"--delete")
|
-d|--delete)
|
||||||
local willrm=1
|
local willrm=1
|
||||||
;;
|
shift
|
||||||
|
;;
|
||||||
|
|
||||||
"-f"?*|"--format"?*)
|
-f|--format)
|
||||||
local compform=$(echo "$opt" | cut -f 2- -d '=')
|
local compform=$2
|
||||||
;;
|
shift 2
|
||||||
|
;;
|
||||||
|
|
||||||
"-p"?*|"--parallel"?*)
|
-p|--parallel)
|
||||||
local nproc=$(echo "$opt" | cut -f 2- -d '=')
|
local nproc=$2
|
||||||
;;
|
shift 2
|
||||||
|
;;
|
||||||
|
|
||||||
"-v"|"--verbose")
|
-v|--verbose)
|
||||||
local verbose=1
|
local verbose=1
|
||||||
;;
|
shift
|
||||||
|
;;
|
||||||
|
|
||||||
"-q"|"--quiet")
|
-q|--quiet)
|
||||||
QUIET=1
|
local quiet=1
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
|
||||||
"-"[1..9])
|
-[1-9])
|
||||||
local complevel=$(echo $opt | sed 's/-//')
|
compression="${1#-}"
|
||||||
;;
|
shift
|
||||||
|
;;
|
||||||
"-"*)
|
--)
|
||||||
echo "Invalid option, use taz --help to display options list"
|
shift
|
||||||
echo
|
break
|
||||||
return 1
|
;;
|
||||||
;;
|
*)
|
||||||
|
disp E "Invalid option, use \"taz --help\" to display options list"
|
||||||
*)
|
return 1
|
||||||
local LIST="$LIST ${opt%/}"
|
;;
|
||||||
;;
|
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# The remaining arguments after -- are the files/directories to process,
|
||||||
|
# "." is used if none is given
|
||||||
|
local FILES=("$@")
|
||||||
|
[[ ${#FILES[@]} -eq 0 ]] && FILES=(".")
|
||||||
|
|
||||||
[[ ! $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 ]] &&
|
[[ $verbose -gt 1 && $quiet -gt 1 ]] &&
|
||||||
disp E "The --verbose and --quiet options can't be used together."
|
disp E "The --verbose and --quiet options can't be used together."
|
||||||
|
|
||||||
for item in $LIST; do
|
for item in "${FILES[@]}"; do
|
||||||
local donetar=0
|
local donetar=0
|
||||||
disp I "Processing $item..."
|
disp I "Processing $item..."
|
||||||
|
|
||||||
if [[ -d $item ]]; then
|
if [[ -d "$item" ]]; then
|
||||||
disp I "\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
|
||||||
disp E "tar file creation failed, skipping to next item."
|
disp E "tar file creation failed, skipping to next item."
|
||||||
continue
|
continue
|
||||||
@@ -301,26 +568,30 @@ taz ()
|
|||||||
# Skip compression part if tar is asked
|
# Skip compression part if tar is asked
|
||||||
if [[ $compform != "tar" ]]; then
|
if [[ $compform != "tar" ]]; then
|
||||||
disp I "\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)
|
||||||
disp E "Compression program unavailable, aborting."
|
disp E "Compression program unavailable, aborting."
|
||||||
return 127
|
return 127
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
disp E "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
|
||||||
disp I "\t Deleting original source as asked... "
|
disp I "\t Deleting original source as asked... "
|
||||||
rm -r $item
|
rm -r "$item"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
unset QUIET
|
unset quiet
|
||||||
}
|
}
|
||||||
export -f taz
|
export -f taz
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
# EOF
|
||||||
|
|||||||
@@ -1,72 +1,123 @@
|
|||||||
|
#!/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
|
||||||
# ------------------------------------------------------------------------------
|
# Usage: backtrace
|
||||||
function backtrace ()
|
function backtrace()
|
||||||
{
|
{
|
||||||
echo "========= Call stack ========="
|
printf "========= Call stack =========\n"
|
||||||
typeset -i i=0
|
local i=1 # We begin at 1 to ignore backtrace itself
|
||||||
|
while [[ $i -lt ${#FUNCNAME[@]} ]]; do
|
||||||
local func=
|
printf '%15s() %s:%d\n' \
|
||||||
for func in "${FUNCNAME[@]}"; do
|
"${FUNCNAME[$i]}" "${BASH_SOURCE[$i]}" "${BASH_LINENO[$(( i-1 ))]}"
|
||||||
if [[ $i -ne 0 ]]; then
|
((i++))
|
||||||
printf '%15s() %s:%d\n' \
|
|
||||||
"$func" "${BASH_SOURCE[$i]}" "${BASH_LINENO[ (( $i - 1)) ]}"
|
|
||||||
fi
|
|
||||||
let i++ || true
|
|
||||||
done
|
done
|
||||||
unset func i
|
unset func i
|
||||||
echo "=============================="
|
printf "==============================\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# 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
|
||||||
# ------------------------------------------------------------------------------
|
# Usage: settrace <--on|--off|--status>
|
||||||
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
|
|
||||||
case $opt in
|
local PARSED
|
||||||
"-h"|"--help")
|
PARSED=$(getopt -oh --long help,on,off,status -- "$@")
|
||||||
echo "Try to activate backtrace display for script debugging."
|
if [[ $? -ne 0 ]]; then
|
||||||
echo
|
disp E "Invalid options, use \"settrace --help\" to display usage."
|
||||||
echo "Options:"
|
return 1
|
||||||
echo " --on Activate backtrace generation"
|
fi
|
||||||
echo " --off Deactivate backtrace generation"
|
eval set -- "$PARSED"
|
||||||
echo
|
while true; do
|
||||||
echo "That function active a trap event on error. If the script you want to"
|
case $1 in
|
||||||
echo "debug overload the ERR bash trap, it will not work."
|
-h|--help)
|
||||||
echo
|
printf "Try to activate backtrace display for script debugging.\n\n"
|
||||||
;;
|
printf "Options:\n"
|
||||||
"--on")
|
printf "\t--on\t\tActivate backtrace generation\n"
|
||||||
if [[ $status == "on" ]]; then
|
printf "\t--off\t\tDeactivate backtrace generation\n\n"
|
||||||
disp W "ERR signal trap is already set, replacing previous trap!"
|
printf "That function active a trap event on error. If the script you want to\n"
|
||||||
fi
|
printf "debug overload the ERR bash trap, it will not work.\n"
|
||||||
trap "error" ERR
|
return 0
|
||||||
;;
|
;;
|
||||||
"--off")
|
--on)
|
||||||
if [[ $status != "on" ]]; then
|
if [[ ${status} == "on" ]]; then
|
||||||
disp W "ERR signal trap is already unset!"
|
disp W "ERR signal trap is already set, replacing previous trap!"
|
||||||
fi
|
fi
|
||||||
trap - ERR
|
trap "error" ERR
|
||||||
;;
|
shift
|
||||||
"--status")
|
;;
|
||||||
disp "ERR trap signal is ${status}."
|
--off)
|
||||||
;;
|
if [[ ${status} != "on" ]]; then
|
||||||
esac
|
disp W "ERR signal trap is already unset!"
|
||||||
|
fi
|
||||||
|
trap - ERR
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--status)
|
||||||
|
disp "ERR trap signal is ${status}."
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--)
|
||||||
|
shift
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
disp E "Invalid options, use \"settrace --help\" to display usage."
|
||||||
|
return 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
done
|
done
|
||||||
unset status
|
unset status
|
||||||
}
|
}
|
||||||
export -f settrace
|
export -f settrace
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
# EOF
|
||||||
|
|||||||
@@ -1,9 +1,46 @@
|
|||||||
# Color definitions
|
#!/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
|
# Standard 16 colors display declaration
|
||||||
export DEFAULTFG="\e[0;39m"
|
export DEFAULTFG='\e[0;39m'
|
||||||
export DEFAULTBG="\e[0;49m"
|
export DEFAULTBG='\e[0;49m'
|
||||||
export DEFAULTCOL=${DEFAULTBG}${DEFAULTFG}
|
export DEFAULTCOL="${DEFAULTBG}${DEFAULTFG}"
|
||||||
|
export RESETCOL=$'\e[0m'
|
||||||
|
|
||||||
# Regular Colors
|
# Regular Colors
|
||||||
export Black='\e[0;30m'
|
export Black='\e[0;30m'
|
||||||
@@ -74,39 +111,50 @@ export On_IBlue='\e[0;104m'
|
|||||||
export On_IPurple='\e[0;105m'
|
export On_IPurple='\e[0;105m'
|
||||||
export On_ICyan='\e[0;106m'
|
export On_ICyan='\e[0;106m'
|
||||||
export On_IWhite='\e[0;107m'
|
export On_IWhite='\e[0;107m'
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Display a message
|
# Display a message
|
||||||
# ------------------------------------------------------------------------------
|
# Usage: disp <type> <message>
|
||||||
|
# Types:
|
||||||
|
# I : info (green)
|
||||||
|
# W : warning (yellow)
|
||||||
|
# E : error (red)
|
||||||
|
# D : debug (cyan)
|
||||||
disp()
|
disp()
|
||||||
{
|
{
|
||||||
case $1 in
|
case $1 in
|
||||||
"I")
|
"I")
|
||||||
local heads="[ ${IGreen}info${DEFAULTFG} ]"
|
local heads="[ ${IGreen}info${DEFAULTFG} ]"
|
||||||
shift
|
shift
|
||||||
[[ -z $QUIET || $QUIET -ne 1 ]] && echo -e "${heads} $@"
|
[[ -z $QUIET || $QUIET -ne 1 ]] && \
|
||||||
;;
|
printf "%b\n" "${heads} $*${RESETCOL}"
|
||||||
"W")
|
;;
|
||||||
local heads="[ ${IYellow}Warning${DEFAULTFG} ]"
|
"W")
|
||||||
shift
|
local heads="[ ${IYellow}Warning${DEFAULTFG} ]"
|
||||||
echo -e "${heads} $@" >&2
|
shift
|
||||||
;;
|
printf "%b\n" "${heads} $*${RESETCOL}" >&2
|
||||||
"E")
|
;;
|
||||||
local heads="[ ${IRed}ERROR${DEFAULTFG} ]"
|
"E")
|
||||||
shift
|
local heads="[ ${IRed}ERROR${DEFAULTFG} ]"
|
||||||
echo -e "${heads} $@" >&2
|
shift
|
||||||
;;
|
printf "%b\n" "${heads} $*${RESETCOL}" >&2
|
||||||
"D")
|
;;
|
||||||
local heads"[ ${ICyan}debug${DEFAULTFG} ]"
|
"D")
|
||||||
shift
|
local heads="[ ${ICyan}debug${DEFAULTFG} ]"
|
||||||
[[ -n $DEBUG && $DEBUG -gt 1 ]] && echo -e "${heads} $@"
|
shift
|
||||||
;;
|
[[ -n $DEBUG && $DEBUG -gt 1 ]] && \
|
||||||
"*")
|
printf "%b\n" "${heads} $*${RESETCOL}"
|
||||||
local heads=""
|
;;
|
||||||
[[ -z $QUIET || $QUIET -ne 1 ]] && echo -e "$@"
|
* )
|
||||||
;;
|
[[ -z $QUIET || $QUIET -ne 1 ]] && \
|
||||||
|
printf "%b\n" "$*"
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
unset heads
|
|
||||||
}
|
}
|
||||||
export -f disp
|
export -f disp
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
# EOF
|
||||||
|
|||||||
@@ -1,8 +1,52 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# Copyright (c) 2013-2022 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
|
||||||
|
# Protected by the BSD3 license. Please read bellow for details.
|
||||||
|
#
|
||||||
|
# * Redistribution and use in source and binary forms,
|
||||||
|
# * with or without modification, are permitted provided
|
||||||
|
# * that the following conditions are met:
|
||||||
|
# *
|
||||||
|
# * Redistributions of source code must retain the above
|
||||||
|
# * copyright notice, this list of conditions and the
|
||||||
|
# * following disclaimer.
|
||||||
|
# *
|
||||||
|
# * Redistributions in binary form must reproduce the above
|
||||||
|
# * copyright notice, this list of conditions and the following
|
||||||
|
# * disclaimer in the documentation and/or other materials
|
||||||
|
# * provided with the distribution.
|
||||||
|
# *
|
||||||
|
# * Neither the name of the copyright holder nor the names
|
||||||
|
# * of any other contributors may be used to endorse or
|
||||||
|
# * promote products derived from this software without
|
||||||
|
# * specific prior written permission.
|
||||||
|
# *
|
||||||
|
# * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||||
|
# * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||||
|
# * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
|
# * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
# * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||||
|
# * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
# * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
# * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
# * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
# * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||||
|
# * OF SUCH DAMAGE.
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# expandlist : treat wildcards in a file/directory list
|
# expandlist : treat wildcards in a file/directory list
|
||||||
# ------------------------------------------------------------------------------
|
# Usage: expandlist <item1 [item2 ... itemN]>
|
||||||
expandlist()
|
expandlist()
|
||||||
{
|
{
|
||||||
|
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
|
||||||
|
printf "expandlist: Wraps a list of items in double quotes.\n\n"
|
||||||
|
printf "Usage: expandlist <item1 [item2 ... itemN]>\n\n"
|
||||||
|
printf "Options:\n"
|
||||||
|
printf "\t-h, --help\t\tDisplay this help screen\n"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
local result=""
|
local result=""
|
||||||
for item in "$1"; do
|
for item in "$1"; do
|
||||||
for content in "$item"; do
|
for content in "$item"; do
|
||||||
@@ -11,63 +55,78 @@ expandlist()
|
|||||||
done
|
done
|
||||||
echo $result
|
echo $result
|
||||||
}
|
}
|
||||||
|
export -f expandlist
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Clean a directory or a tree from temporary or backup files
|
# Clean a directory or a tree from temporary or backup files
|
||||||
# ------------------------------------------------------------------------------
|
# Usage: clean [options] [directory1] [...[directoryX]]
|
||||||
clean ()
|
# Options:
|
||||||
|
# -h, --help: display help screen
|
||||||
|
# -r, --recurs: do a recursive cleaning
|
||||||
|
# -f, --force: do not ask for confirmation (use with care)
|
||||||
|
# -s, --shell: do nothing and display what will be executed
|
||||||
|
clean()
|
||||||
{
|
{
|
||||||
for opt in $@ ; do
|
local recursive=0 force=0 outshell=0
|
||||||
case $opt in
|
|
||||||
"-r"|"--recurs")
|
|
||||||
local recursive=1
|
|
||||||
;;
|
|
||||||
|
|
||||||
"-h"|"--help")
|
# Define short and long options
|
||||||
echo "clean: erase backup files in the given directories."
|
local PARSED
|
||||||
echo
|
PARSED=$(getopt -o hrsf --long help,recurs,shell,force -n 'clean' -- "$@")
|
||||||
echo "Usage: clean [option] [directory1] [...[directoryX]]"
|
|
||||||
echo
|
if [[ $? -ne 0 ]]; then
|
||||||
echo "Options:"
|
disp E "Invalid options, use \"clean --help\" to display usage."
|
||||||
echo " -h, --help Display that help screen"
|
return 1
|
||||||
echo " -r, --recurs Do a recursive cleaning"
|
fi
|
||||||
echo " -f, --force Do not ask for confirmation (use with care)"
|
|
||||||
echo " -s, --shell Do nothing and display what will be executed"
|
eval set -- "$PARSED"
|
||||||
echo
|
|
||||||
|
while true; do
|
||||||
|
case "$1" in
|
||||||
|
-r|--recurs)
|
||||||
|
local recursive=1
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
-h|--help)
|
||||||
|
printf "clean: erase backup files in the given directories.\n\n"
|
||||||
|
printf "Usage: clean [option] [directory1] [...[directoryX]]\n"
|
||||||
|
printf "Options:\n"
|
||||||
|
printf "\t-h, --help\t\tDisplay that help screen\n"
|
||||||
|
printf "\t-r, --recurs\t\tDo a recursive cleaning\n"
|
||||||
|
printf "\t-f, --force\t\tDo not ask for confirmation (use with care)\n"
|
||||||
|
printf "\t-s, --shell\t\tDo nothing and display what will be executed\n"
|
||||||
|
printf "\n"
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
|
-s|--shell)
|
||||||
"-s"|"--shell")
|
|
||||||
local outshell=1
|
local outshell=1
|
||||||
|
shift
|
||||||
;;
|
;;
|
||||||
|
-f|--force)
|
||||||
"-f"|"--force")
|
|
||||||
local force=1
|
local force=1
|
||||||
|
shift
|
||||||
;;
|
;;
|
||||||
|
--)
|
||||||
"-"*)
|
shift
|
||||||
disp E "Invalid option, use \"clean --help\" to display usage."
|
break
|
||||||
echo
|
|
||||||
return 1
|
|
||||||
;;
|
;;
|
||||||
|
|
||||||
*)
|
*)
|
||||||
local dirlist="$dirlist $opt"
|
disp E "Invalid parameter, use \"clean --help\" to display options list"
|
||||||
;;
|
return 1
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
[[ ! $dirlist ]] && local dirlist=$(pwd)
|
# Handle remaining arguments as directories
|
||||||
|
local dirlist=("$@")
|
||||||
|
[[ ${#dirlist[@]} -eq 0 ]] && dirlist=(".")
|
||||||
|
|
||||||
[[ ! $recursive ]] && local findopt="-maxdepth 1"
|
[[ ! $recursive ]] && local findopt="-maxdepth 1"
|
||||||
[[ ! $force ]] && local rmopt="-i"
|
[[ ! $force ]] && local rmopt="-i"
|
||||||
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 "#*#" \
|
find "$dir" "${findopt[@]}" -type f \( -name "*~" -o -name "#*#" -o -name "*.bak" -o -name ".~*#" \) -print0 | while IFS= read -r -d '' f; do
|
||||||
-o -name "*.bak" -o -name ".~*#")
|
|
||||||
for f in $dellist; do
|
|
||||||
if [[ ! $outshell ]]; then
|
if [[ ! $outshell ]]; then
|
||||||
rm $rmopt $f
|
rm $rmopt $f
|
||||||
else
|
else
|
||||||
@@ -78,69 +137,98 @@ clean ()
|
|||||||
unset outshell dirlist dellist findopt rmopt
|
unset outshell dirlist dellist findopt rmopt
|
||||||
}
|
}
|
||||||
export -f clean
|
export -f clean
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Create a directory then goes inside
|
# Create a directory then goes inside
|
||||||
# ------------------------------------------------------------------------------
|
# Usage: mcd <directory>
|
||||||
mcd ()
|
mcd()
|
||||||
{
|
{
|
||||||
if [[ ! $# -eq 1 ]] ; then
|
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
|
||||||
disp E "Create a directory then goes inside."
|
printf "mcd: Create a directory and enter it.\n\n"
|
||||||
disp E "Usage: mcd <directory>"
|
printf "Usage: mcd <directory>\n"
|
||||||
|
printf "Options:\n"
|
||||||
|
printf "\t-h, --help\t\tDisplay this help screen\n"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ ! $# -eq 1 ]]; then
|
||||||
|
disp E "Missing parameter. Use \"mcd --help\" to display usage."
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
mkdir -pv $1 && cd $1
|
mkdir -pv "$1" && cd "$1" || {
|
||||||
|
printf "Failed create and/or change directory.\n"
|
||||||
|
return 1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
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 _
|
||||||
# ------------------------------------------------------------------------------
|
# Usage: rmspc [options]
|
||||||
rmspc ()
|
# Options:
|
||||||
|
# -h, --help: display help screen
|
||||||
|
# -r, --recursive: treat subdirectories of the given directory
|
||||||
|
# -c, --subst-char: change the replacement character (default is underscore)
|
||||||
|
# -v, --verbose: display more details (recursive mode only)
|
||||||
|
# -s, --shell: do nothing and display commands that would be executed
|
||||||
|
rmspc()
|
||||||
{
|
{
|
||||||
local lst=""
|
local lst=""
|
||||||
for opt in $@ ; do
|
local PARSED
|
||||||
case $opt in
|
PARSED=$(getopt -o hr:c::vs --long help,recursive,subst-char::,verbose,shell -n 'rmspc' -- "$@")
|
||||||
"-h"|"--help")
|
if [[ $? -ne 0 ]]; then
|
||||||
echo "rmspc: remove spaces from all filenames in current directories"
|
disp E "Invalid options, use \"rmspc --help\" to display usage."
|
||||||
echo
|
return 1
|
||||||
echo "Usage: rmspc [option]"
|
fi
|
||||||
echo
|
eval set -- "$PARSED"
|
||||||
echo "Options:"
|
|
||||||
echo " -h, --help Display that help screen"
|
|
||||||
echo " -r, --recursive Treat subdirectories of the given directory"
|
|
||||||
echo " -c, --subst-char Change the replacement character (default is underscore)"
|
|
||||||
echo " -v, --verbose Display what is being done"
|
|
||||||
echo " -s, --shell Do nothing and display commands that would be executed"
|
|
||||||
echo
|
|
||||||
echo "Note: if the --subst-char option is given without parameters, spaces will be"
|
|
||||||
echo " replaced with nothing (concatenation)."
|
|
||||||
echo
|
|
||||||
return 0
|
|
||||||
;;
|
|
||||||
|
|
||||||
"-r"|"--recursive")
|
while true; do
|
||||||
|
case "$1" in
|
||||||
|
-h|--help)
|
||||||
|
printf "rmspc: remove spaces from all filenames in current directories\n\n"
|
||||||
|
printf "Usage: rmspc [option]\n\n"
|
||||||
|
printf "Options:\n"
|
||||||
|
printf "\t-h, --help\t\tDisplay that help screen\n"
|
||||||
|
printf "\t-r, --recursive\t\tTreat subdirectories of the given directory\n"
|
||||||
|
printf "\t-c, --subst-char\tChange the replacement character (default is underscore)\n"
|
||||||
|
printf "\t-v, --verbose\t\tDisplay more details (recursive mode only)\n"
|
||||||
|
printf "\t-s, --shell\t\tDo nothing and display commands that would be executed\n\n"
|
||||||
|
printf "Note: if the --subst-char option is given without parameters, spaces will be\n"
|
||||||
|
printf " replaced with nothing (concatenation).\n"
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
-r|--recursive)
|
||||||
local recurs=1
|
local recurs=1
|
||||||
|
shift
|
||||||
;;
|
;;
|
||||||
|
-c|--subst-char)
|
||||||
"-c"?*|"--subst-char"?*)
|
# Handle optional argument for short/long options
|
||||||
if [[ $(echo $opt | grep "=") ]]; then
|
case "$2" in
|
||||||
local substchar=$(echo "$opt" | cut -f 2- -d '=')
|
"")
|
||||||
else
|
substchar=""
|
||||||
local substchar='none'
|
;;
|
||||||
fi
|
*)
|
||||||
;;
|
substchar="$2"
|
||||||
|
;;
|
||||||
"-v"|"--verbose")
|
esac
|
||||||
local verb=1
|
shift 2
|
||||||
;;
|
;;
|
||||||
|
-v|--verbose)
|
||||||
"-s"|"--shell")
|
local verb=1
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
-s|--shell)
|
||||||
local shell=1
|
local shell=1
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--)
|
||||||
|
shift
|
||||||
|
break
|
||||||
;;
|
;;
|
||||||
|
|
||||||
*)
|
*)
|
||||||
disp E "Invalid parameter, use \"rmspc --help\" to display options list"
|
disp E "Invalid parameter, use \"rmspc --help\" to display options list"
|
||||||
echo
|
echo
|
||||||
@@ -156,14 +244,14 @@ rmspc ()
|
|||||||
for f in *; do
|
for f in *; do
|
||||||
[[ $recurs ]] && [[ -d "$f" ]] && (
|
[[ $recurs ]] && [[ -d "$f" ]] && (
|
||||||
[[ $verb ]] && disp I "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 ]] && disp I "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 +262,453 @@ 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
|
||||||
|
# Usage: file_stats [options] [path]
|
||||||
|
# Options:
|
||||||
|
# -H, --human Human readable sizes\n"
|
||||||
|
# -d, --details Display details (min/max/average/median)
|
||||||
|
# -m, --average Display only average size
|
||||||
|
# -M, --median Display only median size
|
||||||
|
# -c, --count Display only count of files
|
||||||
|
# -t, --total Display only total size
|
||||||
|
# -a, --all Display all stats in human readable format (shortcut for -H -d)
|
||||||
|
# -x, --ext [ext] Filter by extension (e.g. -x log for .log files)
|
||||||
|
# -X, --ext-list [list] Filter by multiple extensions (e.g. -X log,txt)
|
||||||
|
# --min [size] Minimum size (e.g., 10M)
|
||||||
|
# --max [size] Maximum size (e.g., 100M)
|
||||||
|
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 PARSED
|
||||||
|
# Short: H, d, m, M, c, t, a, x:, X:
|
||||||
|
# Long: human, details, average, median, count, total, all, ext:, ext-list:, min:, max:, help
|
||||||
|
PARSED=$(getopt -o HdmMctax:X:h --long human,details,average,median,count,total,all,ext:,ext-list:,min:,max:,help -n 'file_stats' -- "$@")
|
||||||
|
|
||||||
|
if [[ $? -ne 0 ]]; then
|
||||||
|
disp E "Invalid options, use \"file_stats --help\" to display usage."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
eval set -- "$PARSED"
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
case "$1" in
|
||||||
|
-h|--help)
|
||||||
|
printf "Usage: file_stats [options] [path]\n\n"
|
||||||
|
printf "Options:\n"
|
||||||
|
printf "\t-H, --human\t\tHuman readable sizes\n"
|
||||||
|
printf "\t-d, --details\t\tShow detailed histogram\n"
|
||||||
|
printf "\t-m, --average\t\tShow only average size\n"
|
||||||
|
printf "\t-M, --median\t\tShow only median size\n"
|
||||||
|
printf "\t-c, --count\t\tShow only file count\n"
|
||||||
|
printf "\t-t, --total\t\tShow only total size\n"
|
||||||
|
printf "\t-a, --all\t\tShow all (human + details)\n"
|
||||||
|
printf "\t-x, --ext [ext]\t\tFilter by extension\n"
|
||||||
|
printf "\t-X, --ext-list [list]\tFilter by comma-separated list\n"
|
||||||
|
printf "\t--min [size]\t\tMinimum size (e.g., 10M)\n"
|
||||||
|
printf "\t--max [size]\t\tMaximum size (e.g., 100M)\n"
|
||||||
|
return 0 ;;
|
||||||
|
-H|--human)
|
||||||
|
human=1
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
-d|--details)
|
||||||
|
details=1
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
-m|--average)
|
||||||
|
only_avg=1
|
||||||
|
show_all=0
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
-M|--median)
|
||||||
|
only_med=1
|
||||||
|
show_all=0
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
-c|--count)
|
||||||
|
only_count=1
|
||||||
|
show_all=0
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
-t|--total)
|
||||||
|
only_total=1
|
||||||
|
show_all=0
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
-a|--all)
|
||||||
|
human=1
|
||||||
|
details=1
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
-x|--ext)
|
||||||
|
ext_filter="${2#.}"
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
|
-X|--ext-list)
|
||||||
|
ext_list="$2"
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
|
--min)
|
||||||
|
min_size="$2"
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
|
--max)
|
||||||
|
max_size="$2"
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
|
--)
|
||||||
|
shift
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
disp E "Invalid option: $1"
|
||||||
|
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" '
|
||||||
|
# Convert function
|
||||||
|
function human_readable(x) {
|
||||||
|
split("B KiB MiB GiB TiB", units)
|
||||||
|
i = 1
|
||||||
|
while (x >= 1024 && i < 5) {
|
||||||
|
x /= 1024
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
return sprintf("%.2f %s", x, units[i])
|
||||||
|
}
|
||||||
|
|
||||||
|
# Display function
|
||||||
|
function out(label, val, is_size) {
|
||||||
|
if (human == 1 && is_size == 1) val = human_readable(val)
|
||||||
|
printf "%-20s : %s\n", label, val
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
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 "No files found."
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
|
||||||
|
average = total / count
|
||||||
|
# Simple sort for median (awk is not very good at this, we use existing logic)
|
||||||
|
if (count % 2 == 1) median = sizes[(count + 1) / 2]
|
||||||
|
else median = (sizes[count / 2] + sizes[count / 2 + 1]) / 2
|
||||||
|
|
||||||
|
if (only_avg) out("Average size", average, 1)
|
||||||
|
else if (only_med) out("Median size", median, 1)
|
||||||
|
else if (only_count) out("Number of files", count, 0)
|
||||||
|
else if (only_total) out("Total size", total, 1)
|
||||||
|
else {
|
||||||
|
if (show_all || human || details) {
|
||||||
|
printf "Statistics for \"%s\"\n", path
|
||||||
|
printf "-------------------------\n"
|
||||||
|
}
|
||||||
|
out("Number of files", count, 0)
|
||||||
|
out("Total size", total, 1)
|
||||||
|
out("Average size", average, 1)
|
||||||
|
out("Median size", median, 1)
|
||||||
|
out("Minimum size", min, 1)
|
||||||
|
out("Maximum size", max, 1)
|
||||||
|
}
|
||||||
|
if (details) {
|
||||||
|
print "\nSize histogram:"
|
||||||
|
|
||||||
|
# Use a separate array for the loop to avoid collision
|
||||||
|
for (b in bucket) {
|
||||||
|
# Pre-calculate label parts
|
||||||
|
# 1024^0 = 1 (B), 1024^1 = 1K, etc.
|
||||||
|
low = (b == 0) ? 0 : (1024^b)
|
||||||
|
high = 1024^(b+1)
|
||||||
|
|
||||||
|
label = sprintf("%-9s – %-9s",
|
||||||
|
(b == 0) ? "0" : human_readable(low),
|
||||||
|
human_readable(high))
|
||||||
|
|
||||||
|
# We store buckets in an array, access them by index b
|
||||||
|
printf "%-25s : %6d fichiers\n", label, bucket[b]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}'
|
||||||
|
}
|
||||||
|
export -f file_stats
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# Find the biggest files in a directory tree
|
||||||
|
# Usage: findbig [options] [directory]
|
||||||
|
# Options:
|
||||||
|
# -h : display help screen
|
||||||
|
# -d : display details (ls -l) for each file
|
||||||
|
# -x : do not cross filesystem boundaries
|
||||||
|
# -l : limit : number of files to return (default is 10)
|
||||||
|
findbig()
|
||||||
|
{
|
||||||
|
local details=0 limit=10 no_change=0 one_fs=0
|
||||||
|
|
||||||
|
local PARSED
|
||||||
|
PARSED=$(getopt -o hd:l:x --long help,details,one-fs,limit: -n 'findbig' -- "$@")
|
||||||
|
if [[ $? -ne 0 ]]; then
|
||||||
|
disp E "Invalid options, use \"findbig --help\" to display usage."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
eval set -- "$PARSED"
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
case "$1" in
|
||||||
|
-h|--help)
|
||||||
|
printf "findbig: Find the N biggest files in a directory tree.\n\n"
|
||||||
|
printf "Usage: findbig [options] [directory]\n\n"
|
||||||
|
printf "Options:\n"
|
||||||
|
printf "\t-h, --help\t\tDisplay this help screen\n"
|
||||||
|
printf "\t-d, --details\t\tShow detailed file info (ls -ld)\n"
|
||||||
|
printf "\t-l, --limit N\t\tNumber of files to return (default: 10)\n"
|
||||||
|
printf "\t-x, --one-fs\t\tDo not cross filesystem boundaries\n"
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
-d|--details)
|
||||||
|
details=1
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
-n|--no-change)
|
||||||
|
no_change=1
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
-l|--limit)
|
||||||
|
limit="$2"
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
|
--)
|
||||||
|
shift
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
disp E "Invalid option: $1"
|
||||||
|
return 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
local dir="${1:-.}"
|
||||||
|
|
||||||
|
# Prepare find arguments in an array for cleaner handling
|
||||||
|
local find_args=("-L" "$dir" "-type" "f")
|
||||||
|
(( one_fs )) && find_args+=("-xdev")
|
||||||
|
|
||||||
|
# Logic: find files, print size and path, sort numeric reverse, take N
|
||||||
|
if (( details )); then
|
||||||
|
find "${find_args[@]}" -printf "%s %p\n" 2>/dev/null | sort -rn | head -n "$limit" | while read -r size path; do
|
||||||
|
ls -ld "$path"
|
||||||
|
done
|
||||||
|
else
|
||||||
|
find "${find_args[@]}" -printf "%s %p\n" 2>/dev/null | sort -rn | head -n "$limit"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
export -f findbig
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# Find empty files in a directory tree
|
||||||
|
# Usage: findzero [options] [directory]
|
||||||
|
# Options:
|
||||||
|
# -h : display help screen
|
||||||
|
# -d : display details (ls -l) for each file
|
||||||
|
# -x : do not cross filesystem boundaries
|
||||||
|
# --delete : delete empty files and display their paths
|
||||||
|
findzero() {
|
||||||
|
local delete=0 details=0 one_fs=0 no_change=0
|
||||||
|
|
||||||
|
local PARSED
|
||||||
|
# o: options, long: long equivalents
|
||||||
|
PARSED=$(getopt -o hdx --long help,details,one-fs,delete -n 'findzero' -- "$@")
|
||||||
|
if [[ $? -ne 0 ]]; then
|
||||||
|
disp E "Invalid options, use \"findzero --help\" to display usage."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
eval set -- "$PARSED"
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
case "$1" in
|
||||||
|
-h|--help)
|
||||||
|
printf "findzero: Find or delete empty files in a directory tree.\n\n"
|
||||||
|
printf "Usage: findzero [options] [directory]\n\n"
|
||||||
|
printf "Options:\n"
|
||||||
|
printf "\t-h, --help\t\tDisplay this help screen\n"
|
||||||
|
printf "\t-d, --details\t\tShow detailed file info (ls -ls)\n"
|
||||||
|
printf "\t-x, --one-fs\t\tDo not cross filesystem boundaries\n"
|
||||||
|
printf "\t--delete\t\tActually remove the empty files\n"
|
||||||
|
return 0 ;;
|
||||||
|
-d|--details)
|
||||||
|
details=1
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
-x|--one-fs)
|
||||||
|
one_fs=1
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--delete)
|
||||||
|
delete=1
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--)
|
||||||
|
shift
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
disp E "Invalid option: $1"
|
||||||
|
return 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
local dir="${1:-.}"
|
||||||
|
local find_args=("-L" "$dir" "-type" "f" "-empty")
|
||||||
|
|
||||||
|
(( one_fs )) && find_args+=("-xdev")
|
||||||
|
|
||||||
|
# Execution logic
|
||||||
|
if (( delete )); then
|
||||||
|
disp W "Deleting empty files in $dir..."
|
||||||
|
find "${find_args[@]}" -delete -print
|
||||||
|
elif (( details )); then
|
||||||
|
find "${find_args[@]}" -ls
|
||||||
|
else
|
||||||
|
find "${find_args[@]}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
export -f findzero
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# Find dead symbolic links in a directory tree
|
||||||
|
# Usage: finddead [options] [directory]
|
||||||
|
# Options:
|
||||||
|
# -h : display help screen
|
||||||
|
# -d : display details (ls -l) for each link
|
||||||
|
# -x : do not cross filesystem boundaries
|
||||||
|
# --delete : delete dead links and display their paths
|
||||||
|
finddead() {
|
||||||
|
local delete=0 details=0 one_fs=0 no_change=0
|
||||||
|
|
||||||
|
local PARSED
|
||||||
|
PARSED=$(getopt -o hdx --long help,details,one-fs,delete -n 'finddead' -- "$@")
|
||||||
|
if [[ $? -ne 0 ]]; then
|
||||||
|
disp E "Invalid options, use \"finddead --help\" to display usage."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
eval set -- "$PARSED"
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
case "$1" in
|
||||||
|
-h|--help)
|
||||||
|
printf "finddead: Find or delete dead/broken symbolic links.\n\n"
|
||||||
|
printf "Usage: finddead [options] [directory]\n\n"
|
||||||
|
printf "Options:\n"
|
||||||
|
printf "\t-h, --help\t\tDisplay this help screen\n"
|
||||||
|
printf "\t-d, --details\t\tShow detailed symlink info (ls -ls)\n"
|
||||||
|
printf "\t-x, --one-fs\t\tDo not cross filesystem boundaries\n"
|
||||||
|
printf "\t--delete\t\tActually remove the dead links\n"
|
||||||
|
return 0 ;;
|
||||||
|
-d|--details)
|
||||||
|
details=1
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
-x|--one-fs)
|
||||||
|
one_fs=1
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--delete)
|
||||||
|
delete=1
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--)
|
||||||
|
shift
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
disp E "Invalid option: $1"
|
||||||
|
return 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
local dir="${1:-.}"
|
||||||
|
# -xtype l searches for links that do not point to an existing file
|
||||||
|
local find_args=("$dir" "-xtype" "l")
|
||||||
|
(( one_fs )) && find_args+=("-xdev")
|
||||||
|
|
||||||
|
# Execution logic
|
||||||
|
if (( delete )); then
|
||||||
|
disp W "Deleting dead symlinks in $dir..."
|
||||||
|
find "${find_args[@]}" -delete -print
|
||||||
|
elif (( details )); then
|
||||||
|
find "${find_args[@]}" -ls
|
||||||
|
else
|
||||||
|
find "${find_args[@]}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
export -f finddead
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
# EOF
|
||||||
|
|||||||
108
profile.d/fun.sh
Normal file
108
profile.d/fun.sh
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
#!/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
|
||||||
|
# Usage: busy [options] [pattern]
|
||||||
|
# Options:
|
||||||
|
# --delay=<ms> : add a delay between each line output (milliseconds)
|
||||||
|
# pattern : the string to search for in the hexdump output (default is "ca fe")
|
||||||
|
busy()
|
||||||
|
{
|
||||||
|
local pattern="ca fe" delay_ms=0
|
||||||
|
|
||||||
|
local PARSED
|
||||||
|
# Short: h, p:, d:
|
||||||
|
# Long: help, pattern:, delay:
|
||||||
|
PARSED=$(getopt -o hp:d: --long help,pattern:,delay: -n 'busy' -- "$@")
|
||||||
|
if [[ $? -ne 0 ]]; then
|
||||||
|
disp E "Invalid options, use \"busy --help\" to display usage."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
eval set -- "$PARSED"
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
case "$1" in
|
||||||
|
-h|--help)
|
||||||
|
printf "busy: Monitor /dev/urandom for a specific pattern.\n\n"
|
||||||
|
printf "Usage: busy [options] [pattern]\n\n"
|
||||||
|
printf "Options:\n"
|
||||||
|
printf "\t-h, --help\t\tDisplay this help screen\n"
|
||||||
|
printf "\t-p, --pattern PATTERN\tHex pattern to search (default: \"ca fe\")\n"
|
||||||
|
printf "\t-d, --delay MS\t\tDelay between matches in milliseconds\n"
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
-p|--pattern)
|
||||||
|
pattern="$2"
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
|
-d|--delay)
|
||||||
|
delay_ms="$2"
|
||||||
|
if ! [[ "$delay_ms" =~ ^[0-9]+$ ]]; then
|
||||||
|
disp E "Invalid delay: must be an integer (milliseconds)."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
|
--)
|
||||||
|
shift
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
disp E "Invalid option: $1"
|
||||||
|
return 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
# If a pattern was provided as a positional argument (e.g., 'busy "ff 00"'),
|
||||||
|
# it is captured here.
|
||||||
|
[[ -n "$1" ]] && pattern="$1"
|
||||||
|
|
||||||
|
# Convert milliseconds to seconds for 'sleep'
|
||||||
|
local delay_s=$(awk "BEGIN { printf \"%.3f\", $delay_ms / 1000 }")
|
||||||
|
|
||||||
|
# Monitor /dev/urandom
|
||||||
|
cat /dev/urandom | hexdump -C | grep --line-buffered "$pattern" | \
|
||||||
|
while read -r line; do
|
||||||
|
echo "$line"
|
||||||
|
[[ $delay_ms -gt 0 ]] && sleep "$delay_s"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
# EOF
|
||||||
@@ -1,33 +1,78 @@
|
|||||||
|
#!/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
|
||||||
# ------------------------------------------------------------------------------
|
# Usage: help
|
||||||
help()
|
help()
|
||||||
{
|
{
|
||||||
cat <<EOF
|
printf "check_updates\tCheck for profile updates\n"
|
||||||
clean Erase backup files
|
printf "clean\t\tErase backup files\n"
|
||||||
dpkgs Search for the given package in the installed ones
|
printf "dpkgs\t\tSearch for the given package in the installed ones\n"
|
||||||
gpid Give the list of PIDs for the given process name
|
printf "findbig\t\tFind big files in the given (or current) directory\n"
|
||||||
isipv4 Tell if the given IPv4 is valid
|
printf "findempty\tFind empty files and directories in the given (or current) directory\n"
|
||||||
isipv6 Tell if the given IPv6 is valid
|
printf "finddead\tFind dead symbolic links in the given (or current) directory\n"
|
||||||
ku Kill process owned by users in parameter
|
printf "gpid\t\tGive the list of PIDs for the given process name\n"
|
||||||
mcd Create a directory and go inside
|
printf "isipv4\t\tTell if the given IPv4 is valid\n"
|
||||||
meteo Display curent weather forecast for the configured city
|
printf "isipv6\t\tTell if the given IPv6 is valid\n"
|
||||||
ppg Display process matching the given parameter
|
printf "ku\t\tKill process owned by users in parameter\n"
|
||||||
rain Let the rain fall
|
printf "mcd\t\tCreate a directory and go inside\n"
|
||||||
rmhost Remove host (IP and/or DNS name) for current known_host
|
printf "meteo\t\tDisplay curent weather forecast for the configured city\n"
|
||||||
rmspc Remove spaces from all the files in working directory
|
printf "ppg\t\tDisplay process matching the given parameter\n"
|
||||||
setc Set console language to C
|
printf "ppn\t\tDisplay process matching the exact process name given in parameter\n"
|
||||||
setfr Set console language to French
|
printf "ppu\t\tDisplay processes owned by the given user\n"
|
||||||
settrace Activate/deactivate call trace for script debugging
|
printf "profile_update\tUpdate profile to the latest version\n"
|
||||||
setus Set console language to US English
|
printf "rain\t\tLet the rain fall\n"
|
||||||
showinfo Show the welcoming baner with basic system information
|
printf "rmhost\t\tRemove host (IP and/or DNS name) for current known_host\n"
|
||||||
ssr Do a root login to the given address
|
printf "rmspc\t\tRemove spaces from all the files in working directory\n"
|
||||||
taz Compress smartly the given files or directory
|
printf "setlocale\tSet console language to the current locale\n"
|
||||||
utaz Uncompress all zip files in the given (or current) directory
|
printf " * setc\tSet console language to C\n"
|
||||||
ver Display version of your copy of profile
|
printf " * setfr\tSet console language to French\n"
|
||||||
|
printf " * setus\tSet console language to US English\n"
|
||||||
|
printf "settrace\tActivate/deactivate call trace for script debugging\n"
|
||||||
|
printf "showinfo\tShow the welcoming baner with basic system information\n"
|
||||||
|
printf "ssr\t\tDo a root login to the given address\n"
|
||||||
|
printf "taz\t\tCompress smartly the given files or directory\n"
|
||||||
|
printf "utaz\t\tUncompress all zip files in the given (or current) directory\n"
|
||||||
|
printf "ver\t\tDisplay version of your copy of profile\n\n"
|
||||||
|
|
||||||
Please use <command> --help to obtain usage details.
|
printf "\nPlease use <command> --help to obtain usage details.\n"
|
||||||
EOF
|
|
||||||
}
|
}
|
||||||
export -f help
|
export -f help
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
# EOF
|
||||||
|
|||||||
@@ -1,55 +1,109 @@
|
|||||||
|
#!/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
|
||||||
# ------------------------------------------------------------------------------
|
# Usage: ver
|
||||||
ver ()
|
ver()
|
||||||
{
|
{
|
||||||
|
[[ -z $PROFVERSION ]] && \
|
||||||
|
disp W "No version defined. Profile is probably badly installed." && \
|
||||||
|
return 1
|
||||||
disp "Profile version $PROFVERSION."
|
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)
|
||||||
# ------------------------------------------------------------------------------
|
# Usage: meteo [city1 city2 ...]
|
||||||
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 || disp E "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
|
||||||
# ------------------------------------------------------------------------------
|
# Usage: showinfo
|
||||||
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,133 @@
|
|||||||
|
#!/bin/bash
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Change locale to French
|
# 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.
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
setfr ()
|
|
||||||
|
locale_check()
|
||||||
{
|
{
|
||||||
# Set fr locale definitions
|
locale -a | grep -qx "$1" || {
|
||||||
export LANG=fr_FR.UTF-8
|
disp W "Locale '$1' is not installed on this system."
|
||||||
export LC_MESSAGES=fr_FR.UTF-8
|
return 1
|
||||||
export LC_ALL=fr_FR.UTF-8
|
}
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
export -f setfr
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Change locale to C standard
|
# Change locale to the given one in parameter
|
||||||
|
# Usage: setlocale <locale>
|
||||||
|
setlocale()
|
||||||
|
{
|
||||||
|
local PARSED
|
||||||
|
PARSED=$(getopt -o h --long help -n 'setlocale' -- "$@")
|
||||||
|
if [[ $? -ne 0 ]]; then
|
||||||
|
disp E "Invalid options, use \"setlocale --help\" to display usage."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
eval set -- "$PARSED"
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
-h|--help)
|
||||||
|
printf "setlocale: Configure system environment locale variables.\n\n"
|
||||||
|
printf "Usage: setlocale <locale>\n\n"
|
||||||
|
printf "Options:\n"
|
||||||
|
printf " -h, --help Display this help screen\n"
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
--)
|
||||||
|
shift
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
disp E "Invalid options, use \"setlocale --help\" to display usage."
|
||||||
|
return 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
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
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
setc ()
|
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# Special case : change locale to C standard
|
||||||
|
# Usage: setc
|
||||||
|
setc()
|
||||||
{
|
{
|
||||||
# Locale definitions
|
# Locale definitions
|
||||||
export LANG=C
|
|
||||||
export LC_MESSAGES=C
|
|
||||||
export LC_ALL=C
|
export LC_ALL=C
|
||||||
|
disp I "Locale changed to standard C (POSIX)."
|
||||||
}
|
}
|
||||||
export -f setc
|
export -f setc
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# Change locale to French
|
||||||
|
# Usage: setfr
|
||||||
|
setfr()
|
||||||
|
{
|
||||||
|
# Set fr locale definitions
|
||||||
|
setlocale "fr_FR.UTF-8"
|
||||||
|
}
|
||||||
|
export -f setfr
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Change locale to US (needed by Steam)
|
# Change locale to US (needed by Steam)
|
||||||
# ------------------------------------------------------------------------------
|
# Usage: setus
|
||||||
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
|
||||||
|
|||||||
107
profile.d/net.sh
107
profile.d/net.sh
@@ -1,49 +1,112 @@
|
|||||||
|
#!/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
|
||||||
# ------------------------------------------------------------------------------
|
# Usage: isipv4 <ip_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
|
||||||
disp "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
|
||||||
disp "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
|
||||||
# ------------------------------------------------------------------------------
|
# Usage: isipv6 <ip_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
|
||||||
disp "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
|
||||||
disp "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
|
||||||
|
# Usage: urlencode <string>
|
||||||
|
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,99 @@
|
|||||||
|
#!/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
|
||||||
# ------------------------------------------------------------------------------
|
# Usage: dpkgs <string>
|
||||||
dpkgs ()
|
pkgs()
|
||||||
{
|
{
|
||||||
local count=0
|
local ignore_case=0
|
||||||
for opt in $@ ; do
|
|
||||||
case $opt in
|
local PARSED
|
||||||
"-h"|"--help")
|
PARSED=$(getopt -o hi --long help,ignore-case -n 'pkgs' -- "$@")
|
||||||
echo "dpkgs: look for an installed package by it's name."
|
if [[ $? -ne 0 ]]; then
|
||||||
echo
|
disp E "Invalid options, use \"pkgs --help\" to display usage."
|
||||||
echo "Usage: dpkgs <string>"
|
return 1
|
||||||
|
fi
|
||||||
|
eval set -- "$PARSED"
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
case "$1" in
|
||||||
|
-h|--help)
|
||||||
|
printf "pkgs: Look for an installed package by its name.\n\n"
|
||||||
|
printf "Usage: pkgs [options] <string>\n\n"
|
||||||
|
printf "Options:\n"
|
||||||
|
printf "\t-h, --help\tDisplay this help screen\n"
|
||||||
|
printf "\t-i, --ignore-case\tIgnore case distinctions\n"
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
|
-i|--ignore-case)
|
||||||
"-"*)
|
ignore_case=1
|
||||||
echo "Invalid option, use \"dpkgs --help\" to display usage."
|
shift
|
||||||
echo
|
;;
|
||||||
return 1
|
--)
|
||||||
|
shift
|
||||||
|
break
|
||||||
;;
|
;;
|
||||||
|
|
||||||
*)
|
*)
|
||||||
local pkg=$1 && shift
|
disp E "Invalid option: $1"
|
||||||
count=$(( $count + 1 ))
|
return 1
|
||||||
[[ $count -gt 1 ]] &&
|
|
||||||
disp E "Please specify a package name, without space, eventually partial." &&
|
|
||||||
return 1
|
|
||||||
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
[[ $count -lt 1 ]] &&
|
|
||||||
disp E "Please specify a package name, without space, eventually partial." &&
|
local pkg="$1"
|
||||||
|
[[ -z "$pkg" ]] && {
|
||||||
|
disp E "Please specify a package name, without space, eventually partial."
|
||||||
return 1
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
[[ -x /usr/sbin/dpkg ]] &&
|
# Build grep command
|
||||||
disp E "dpkg command seems unavialable." &&
|
local grep_opt=""
|
||||||
|
(( ignore_case )) && grep_opt="-i"
|
||||||
|
|
||||||
|
command -v dpkg >/dev/null 2>&1 && local cmd="dpkg -l"
|
||||||
|
command -v rpm >/dev/null 2>&1 && local cmd="rpm -qa"
|
||||||
|
if [[ -z $cmd ]]; then
|
||||||
|
disp E "No usable package manager seems unavialable."
|
||||||
return 2
|
return 2
|
||||||
|
fi
|
||||||
dpkg -l | grep $pkg
|
$cmd | grep $grep_opt $pkg
|
||||||
}
|
}
|
||||||
export -f dpkgs
|
export -f pkgs
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
# EOF
|
||||||
|
|||||||
@@ -1,18 +1,128 @@
|
|||||||
|
#!/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
|
||||||
# ------------------------------------------------------------------------------
|
# Usage: ppg <string>
|
||||||
ppg ()
|
ppg()
|
||||||
{
|
{
|
||||||
ps -edf | grep $@ | grep -v "grep $@"
|
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
|
||||||
|
printf "ppg: Search processes matching the given string.\n\n"
|
||||||
|
printf "Usage: ppg <string>\n\n"
|
||||||
|
printf "Options:\n"
|
||||||
|
printf "\t-h, --help\t\tDisplay this help screen\n"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
if [[ -z "$1" ]]; then
|
||||||
|
disp E "Usage: ppg <string>"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
ps -edf | grep "$@" | grep -v "grep $@"
|
||||||
}
|
}
|
||||||
export -f ppg
|
export -f ppg
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# List processes owned by a specific user
|
||||||
|
# Usage: ppu <username>
|
||||||
|
ppu()
|
||||||
|
{
|
||||||
|
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
|
||||||
|
printf "ppu: List processes owned by a specific user.\n\n"
|
||||||
|
printf "Usage: ppu <username>\n\n"
|
||||||
|
printf "Options:\n"
|
||||||
|
printf "\t-h, --help\t\tDisplay this help screen\n"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
if [[ -z "$1" ]]; then
|
||||||
|
disp E "Usage: ppu <username>"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# -u lists processes for a specific user
|
||||||
|
# -o provides a clean, standard output format
|
||||||
|
ps -u "$1" -o pid,user,%cpu,%mem,start,time,command
|
||||||
|
}
|
||||||
|
export -f ppu
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# List processes by exact command name (no path/parameters)
|
||||||
|
# Usage: ppn <command_name>
|
||||||
|
ppn()
|
||||||
|
{
|
||||||
|
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
|
||||||
|
printf "ppn: List processes by exact command name (no path/parameters).\n\n"
|
||||||
|
printf "Usage: ppn <command_name>\n\n"
|
||||||
|
printf "Options:\n"
|
||||||
|
printf "\t-h, --help\t\tDisplay this help screen\n"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
if [[ -z "$1" ]]; then
|
||||||
|
disp E "Usage: ppn <command_name>"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# -e: select all processes
|
||||||
|
# -o: specify custom output columns (PID and Command name)
|
||||||
|
# grep -w: ensures exact word matching so 'bash' doesn't match 'dbash'
|
||||||
|
ps -eo pid,comm | grep -w "$1"
|
||||||
|
}
|
||||||
|
export -f ppn
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Get PID list of the given process name
|
# Get PID list of the given process name
|
||||||
# ------------------------------------------------------------------------------
|
# Usage: ppid <process_name [process_name2 ...]>
|
||||||
gpid ()
|
gpid()
|
||||||
{
|
{
|
||||||
|
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
|
||||||
|
printf "gpid: Get PID list of the given process name.\n\n"
|
||||||
|
printf "Usage: gpid <process_name [process_name2 ...]>\n\n"
|
||||||
|
printf "Options:\n"
|
||||||
|
printf "\t-h, --help\t\tDisplay this help screen\n"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
if [[ -z "$1" ]]; then
|
||||||
|
disp E "Usage: gpid <process_name [process_name2 ...]>"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
[[ $UID -eq 0 ]] && local psopt="-A"
|
[[ $UID -eq 0 ]] && local psopt="-A"
|
||||||
[[ $# -eq 1 ]] && local single=1
|
[[ $# -eq 1 ]] && local single=1
|
||||||
for pid in $@; do
|
for pid in $@; do
|
||||||
@@ -26,15 +136,65 @@ gpid ()
|
|||||||
[[ $result ]] || return 1
|
[[ $result ]] || return 1
|
||||||
}
|
}
|
||||||
export -f gpid
|
export -f gpid
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Kill all processes owned by the given users
|
# Kill all processes owned by the given users (kill user)
|
||||||
# ------------------------------------------------------------------------------
|
# Usage: ku <username1 [username2 ...]>
|
||||||
ku ()
|
ku()
|
||||||
{
|
{
|
||||||
|
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
|
||||||
|
printf "ku: Kill all processes owned by the given users.\n\n"
|
||||||
|
printf "Usage: ku <username1 [username2 ...]>\n\n"
|
||||||
|
printf "Options:\n"
|
||||||
|
printf "\t-h, --help\t\tDisplay this help screen\n"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
if [[ -z "$1" ]]; then
|
||||||
|
disp E "Usage: ku <username1 [username2 ...]>"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
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 (kill tree)
|
||||||
|
# Usage: kt <pid> [kill_options]
|
||||||
|
kt()
|
||||||
|
{
|
||||||
|
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
|
||||||
|
printf "kt: Kill all children of a process then the process (kill tree).\n\n"
|
||||||
|
printf "Usage: kt <pid> [kill_options]\n\n"
|
||||||
|
printf "Options:\n"
|
||||||
|
printf "\t-h, --help\t\tDisplay this help screen\n"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
if [[ -z "$1" ]]; then
|
||||||
|
disp E "Usage: ppg <string>"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
local parent_pid="$1"
|
||||||
|
shift
|
||||||
|
if [[ "$parent_pid" == "0" || "$parent_pid" == "1" ]]; then
|
||||||
|
disp E "Safety abort: Refusing to kill PID $parent_pid (system critical)."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
children_pids=$(pgrep -P "$parent_pid")
|
||||||
|
|
||||||
|
for pid in $children_pids; do
|
||||||
|
kt "$pid" "$@" || break
|
||||||
|
done
|
||||||
|
kill "$@" "$parent_pid"
|
||||||
|
}
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
# EOF
|
||||||
|
|||||||
@@ -1,16 +1,60 @@
|
|||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# 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
|
||||||
# ------------------------------------------------------------------------------
|
# Usage: timer_now
|
||||||
|
# This function returns the current time in nanoseconds since the epoch. It
|
||||||
|
# first tries to use the %N format specifier for nanoseconds, but if that is
|
||||||
|
# not supported (e.g., on older systems), it falls back to seconds.
|
||||||
function timer_now
|
function timer_now
|
||||||
{
|
{
|
||||||
date +%s%N
|
date +%s%N 2>/dev/null || date +%s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Usage: timer_start
|
||||||
|
# This function initializes the timer_start variable with the current time in
|
||||||
|
# nanoseconds. It is used to measure the elapsed time for the prompt.
|
||||||
function timer_start
|
function timer_start
|
||||||
{
|
{
|
||||||
timer_start=${timer_start:-$(timer_now)}
|
timer_start=${timer_start:-$(timer_now)}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Usage: timer_stop
|
||||||
|
# This function calculates the elapsed time since timer_start and formats it
|
||||||
|
# into a human-readable string with appropriate units (us, ms, s, m, h
|
||||||
function timer_stop
|
function timer_stop
|
||||||
{
|
{
|
||||||
local delta_us=$((($(timer_now) - $timer_start) / 1000))
|
local delta_us=$((($(timer_now) - $timer_start) / 1000))
|
||||||
@@ -39,23 +83,26 @@ function timer_stop
|
|||||||
}
|
}
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Function triguered internaly by bash : defining prompt
|
# Function triggered internally by bash : defining prompt
|
||||||
# ------------------------------------------------------------------------------
|
# Usage: set_prompt
|
||||||
set_prompt ()
|
# This function is called by bash before displaying the prompt. It sets the
|
||||||
|
# PS1 variable to a custom prompt that includes the exit status of the last
|
||||||
|
# command, the elapsed time of the last command, and the current user and host.
|
||||||
|
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 +135,7 @@ set_prompt ()
|
|||||||
# the text color to the default.
|
# the text color to the default.
|
||||||
PS1+="$ICyan\\w \\\$$Default "
|
PS1+="$ICyan\\w \\\$$Default "
|
||||||
}
|
}
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
# EOF
|
||||||
|
|||||||
312
profile.d/pwd.sh
Executable file → Normal file
312
profile.d/pwd.sh
Executable file → Normal file
@@ -1,151 +1,203 @@
|
|||||||
|
#!/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
|
# Usage: genpwd [options] [--extracars=<cars>] [--length=<n>] [nb_passwd]
|
||||||
|
# Options:
|
||||||
|
# -h, --help Display that help screen
|
||||||
|
# -s, --nosymbols Exclude symbols
|
||||||
|
# -n, --nonumbers Exclude numbers
|
||||||
|
# -u, --noup Exclude uppercase letters
|
||||||
|
# -l, --nolow Exclude lowercase letters
|
||||||
|
# -e=<c>, --extracars=<c>
|
||||||
|
# Add the given caracters to the possible caracter list
|
||||||
|
# -L=<n>, --length=<n>
|
||||||
|
# Set length of the password (default is 16)
|
||||||
|
# -o=<n>, --occurences=<n>
|
||||||
|
# Set the maximum occurences of a same caracter (default is 2)
|
||||||
# The function is very slow on Windows
|
# The function is very slow on Windows
|
||||||
# ------------------------------------------------------------------------------
|
|
||||||
genpwd()
|
genpwd()
|
||||||
{
|
{
|
||||||
local length=16
|
local length=16
|
||||||
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
|
|
||||||
case $opt in
|
local PARSED
|
||||||
"-h"|"--help")
|
PARSED=$(getopt -o hsnu l e:L:o: --long \
|
||||||
echo "genpwd: generate a secure random password."
|
help,nosymbols,nonumbers,noup,nolow,extracars:,length:,occurences: -n 'genpwd' -- "$@")
|
||||||
echo
|
if [[ $? -ne 0 ]]; then return 1; fi
|
||||||
echo "Usage: genpwd [options] [--extracars=<cars>] [--length=<n>] [nb_passwd]"
|
eval set -- "$PARSED"
|
||||||
echo
|
|
||||||
echo "Options:"
|
while true; do
|
||||||
echo " -h, --help Display that help screen"
|
case "$1" in
|
||||||
echo " -s, --nosymbols Exclude symbols"
|
-h|--help)
|
||||||
echo " -n, --nonumbers Exclude numbers"
|
printf "genpwd: Generate secure random password(s).\n\n"
|
||||||
echo " -u, --noup Exclude uppercase letters"
|
printf "Usage: genpwd [options] [nb_passwd]\n\n"
|
||||||
echo " -l, --nolow Exclude lowercase letters"
|
printf "Options:\n"
|
||||||
echo " -e=<c>, --extracars=<c>"
|
printf "\t-h, --help\t\tDisplay this help screen\n"
|
||||||
echo " Add the given caracters to the possible caracter list"
|
printf "\t-s, --nosymbols\t\tExclude symbols\n"
|
||||||
echo " -L=<n>, --length=<n>"
|
printf "\t-n, --nonumbers\t\tExclude numbers\n"
|
||||||
echo " Set length of the password (default is $length)"
|
printf "\t-u, --noup\t\tExclude uppercase letters\n"
|
||||||
echo " -o=<n>, --occurences=<n>"
|
printf "\t-l, --nolow\t\tExclude lowercase letters\n"
|
||||||
echo " Set the maximum occurences of a same caracter (default is $occurs)"
|
printf "\t-e, --extracars <c>\tAdd characters to list\n"
|
||||||
echo
|
printf "\t-L, --length <n>\tSet password length (default: 16)\n"
|
||||||
echo "If the --extracars parameter is given, at least one of the given caracter will"
|
printf "\t-o, --occurences <n>\tMax occurences per character (default: 2)\n"
|
||||||
echo "be used in the final password."
|
return 0
|
||||||
echo
|
;;
|
||||||
echo "Please note that some caracters might be interpreted by Bash or Awk programs,"
|
-s|--nosymbols)
|
||||||
echo "and thus, cannot be used without provoquing errors. Those identified caracters"
|
symb=0
|
||||||
echo "are :"
|
shift
|
||||||
echo ' * ? \ $ { }'
|
;;
|
||||||
echo
|
-n|--nonumbers)
|
||||||
return 0
|
numb=0
|
||||||
;;
|
shift
|
||||||
"-s"|"--nosymbols")
|
;;
|
||||||
symb=0
|
-u|--noup)
|
||||||
;;
|
maj=0
|
||||||
"-n"|"--nonumbers")
|
shift
|
||||||
numb=0
|
;;
|
||||||
;;
|
-l|--nolow)
|
||||||
"-u"|"--noup")
|
min=0
|
||||||
maj=0
|
shift
|
||||||
;;
|
;;
|
||||||
"-l"|"--nolow")
|
-e|--extracars)
|
||||||
min=0
|
extcar="$2"
|
||||||
;;
|
shift 2
|
||||||
"-e"?*|"--extracars"?*)
|
;;
|
||||||
local extcar=$(echo "$opt" | cut -f 2- -d '=')
|
-L|--length)
|
||||||
;;
|
length="$2"
|
||||||
"-L"?*|"--length"?*)
|
if ! [[ $length =~ ^[0-9]+$ ]]; then
|
||||||
local length=$(echo "$opt" | cut -f 2- -d '=')
|
disp E "The --length parameter requires a number."
|
||||||
if ! [[ $length =~ ^[0-9]+$ ]]; then
|
return 1
|
||||||
disp E "The --length parameter requires a number."
|
fi
|
||||||
return 1
|
shift 2
|
||||||
fi
|
;;
|
||||||
;;
|
-o|--occurences)
|
||||||
"-o"?*|"--occurences"?*)
|
occurs="$2"
|
||||||
local occurs=$(echo "$opt" | cut -f 2- -d '=')
|
if ! [[ $occurs =~ ^[1-9]+$ ]]; then
|
||||||
if ! [[ $occurs =~ ^[1-9]+$ ]]; then
|
disp E "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
|
shift 2
|
||||||
;;
|
;;
|
||||||
"-*")
|
--)
|
||||||
disp E "Unknow parameter ${opt}."
|
shift; break
|
||||||
return 1
|
;;
|
||||||
;;
|
*)
|
||||||
*)
|
break
|
||||||
if ! [[ $opt =~ ^[1-9]+$ ]]; then
|
;;
|
||||||
disp E "Unknow parameter ${opt}."
|
esac
|
||||||
return 1
|
|
||||||
else
|
|
||||||
local nbpwd=$opt
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
done
|
||||||
|
|
||||||
|
if [[ -n "$1" ]]; then
|
||||||
|
nbpwd="$1"
|
||||||
|
if ! [[ $nbpwd =~ ^[0-9]+$ ]]; then
|
||||||
|
disp E "The number of password to generate must be a number."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
# 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"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
disp I "Generating $nbpwd passwords, please wait..."
|
disp I "Generating $nbpwd passwords, please wait..."
|
||||||
for n in $( seq 1 $nbpwd ); do
|
for (( n=1; n<=nbpwd; n++ )); 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
|
||||||
disp E 'Not enought caracters are authorised for the password length.'
|
disp E 'Not enought caracters are authorised for the password length.'
|
||||||
disp E '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,36 +1,145 @@
|
|||||||
|
#!/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
|
||||||
# ------------------------------------------------------------------------------
|
# Usage: rain [OPTIONS]
|
||||||
|
# Options:
|
||||||
|
# -s, --speed NUM Set the drop delay in seconds (default: 0.050).
|
||||||
|
# Lower values = faster rain.
|
||||||
|
# -c, --color COLOR Set the color theme (default: white).
|
||||||
|
# -h, --help Display this help message and exit.
|
||||||
|
# Available Colors:
|
||||||
|
# green : The classic Matrix digital rain
|
||||||
|
# blue : Deep ocean blue gradients
|
||||||
|
# red : Crimson/Blood rain
|
||||||
|
# yellow : Amber and gold tones
|
||||||
|
# cyan : Electric cyan/turquoise
|
||||||
|
# white : Greyscale and white (original style)
|
||||||
rain()
|
rain()
|
||||||
{
|
{
|
||||||
|
show_usage() {
|
||||||
|
printf "Usage: rain [OPTIONS]\n"
|
||||||
|
printf "Options:\n"
|
||||||
|
printf "\t-s, --speed NUM Set the drop delay in seconds (default: 0.050).\n"
|
||||||
|
printf "\t Lower values = faster rain.\n"
|
||||||
|
printf "\t-c, --color COLOR Set the color theme (default: white).\n"
|
||||||
|
printf "\t-h, --help Display this help message and exit.\n\n"
|
||||||
|
printf "Available Colors:\n"
|
||||||
|
printf "\t\e[32mgreen\e[0m\t: The classic Matrix digital rain\n"
|
||||||
|
printf "\t\e[34mblue\e[0m\t: Deep ocean blue gradients\n"
|
||||||
|
printf "\t\e[31mred\e[0m\t: Crimson/Blood rain\n"
|
||||||
|
printf "\t\e[33myellow\e[0m\t: Amber and gold tones\n"
|
||||||
|
printf "\t\e[36mcyan\e[0m\t: Electric cyan/turquoise\n"
|
||||||
|
printf "\twhite\t: Greyscale and white (original style)\n\n"
|
||||||
|
printf "Example: rain --color green --speed 0.03\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
local step_duration=0.050
|
||||||
|
local base_color="white" # default color scheme, can be overridden by --color
|
||||||
|
|
||||||
|
# Analyse arguments
|
||||||
|
while [[ "$#" -gt 0 ]]; do
|
||||||
|
case $1 in
|
||||||
|
-s|--speed)
|
||||||
|
if [[ -n "$2" && ! "$2" =~ ^- ]]; then
|
||||||
|
step_duration="$2"; shift
|
||||||
|
else
|
||||||
|
disp E "--speed requires a numeric value."
|
||||||
|
show_usage && return 1
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
-c|--color)
|
||||||
|
if [[ -n "$2" && ! "$2" =~ ^- ]]; then
|
||||||
|
base_color="$2"; shift
|
||||||
|
else
|
||||||
|
disp E "--color requires a color name."
|
||||||
|
show_usage && return 1
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
-h|--help)
|
||||||
|
show_usage && return 0
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
disp E "Unknown option: $1"
|
||||||
|
show_usage && return 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
|
||||||
|
# Define colors (256-colors gradients)
|
||||||
|
local rain_colors=()
|
||||||
|
case $base_color in
|
||||||
|
green) # Matrix style green
|
||||||
|
for i in {22..28} {34..40} {46..48}; do rain_colors+=("\e[38;5;${i}m"); done ;;
|
||||||
|
blue) # Deep ocean blues
|
||||||
|
for i in {17..21} {27..33} {39..45}; do rain_colors+=("\e[38;5;${i}m"); done ;;
|
||||||
|
red) # Crimson / blood red
|
||||||
|
for i in {52..52} {88..88} {124..124} {160..160} {196..201}; do rain_colors+=("\e[38;5;${i}m"); done ;;
|
||||||
|
yellow) # Amber / gold
|
||||||
|
for i in {58..58} {100..100} {142..142} {184..184} {226..229}; do rain_colors+=("\e[38;5;${i}m"); done ;;
|
||||||
|
cyan) # Electric cyan / turquoise
|
||||||
|
for i in {30..31} {37..38} {44..45} {50..51}; do rain_colors+=("\e[38;5;${i}m"); done ;;
|
||||||
|
*) # Greyscale / white (original style)
|
||||||
|
rain_colors=("\e[37m" "\e[37;1m")
|
||||||
|
for i in {244..255}; do rain_colors+=("\e[38;5;${i}m"); done ;;
|
||||||
|
esac
|
||||||
|
|
||||||
local exit_st=0
|
local exit_st=0
|
||||||
local rain_cars=("|" "│" "┃" "┆" "┇" "┊" "┋" "╽" "╿")
|
local rain_cars=("|" "│" "┃" "┆" "┇" "┊" "┋" "╽" "╿")
|
||||||
local rain_colors=("\e[37m" "\e[37;1m")
|
|
||||||
# More from 256 color mode
|
|
||||||
for i in {244..255}; do
|
|
||||||
rain_colors=( "${rain_colors[@]}" "\e[38;5;${i}m" )
|
|
||||||
done
|
|
||||||
local rain_tab=${#rain_cars[@]}
|
local rain_tab=${#rain_cars[@]}
|
||||||
local rain_color_tab=${#rain_colors[@]}
|
local rain_color_tab=${#rain_colors[@]}
|
||||||
local num_rain_metadata=5
|
local num_rain_metadata=5
|
||||||
local term_height=$(tput lines)
|
local term_height=$(tput lines)
|
||||||
local term_width=$(tput cols)
|
local term_width=$(tput cols)
|
||||||
local step_duration=0.050
|
|
||||||
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 +154,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,8 +176,8 @@ 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}"
|
printf "\e[${y};${X}H${drop_color}${rain_drop}"
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
@@ -77,30 +186,30 @@ rain()
|
|||||||
trap sigwinch WINCH
|
trap sigwinch WINCH
|
||||||
# No echo stdin and hide the cursor
|
# No echo stdin and hide the cursor
|
||||||
stty -echo
|
stty -echo
|
||||||
echo -ne "\e[?25l"
|
printf "\e[?25l"
|
||||||
|
printf "\e[2J"
|
||||||
|
|
||||||
echo -ne "\e[2J"
|
|
||||||
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 +226,6 @@ rain()
|
|||||||
trap - WINCH
|
trap - WINCH
|
||||||
}
|
}
|
||||||
export -f rain
|
export -f rain
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# EOF
|
||||||
|
|||||||
199
profile.d/ssh.sh
199
profile.d/ssh.sh
@@ -1,70 +1,159 @@
|
|||||||
|
#!/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
|
||||||
# ------------------------------------------------------------------------------
|
# Usage: rmhost <hostname|ip> [hostname2|ip2 [...]]
|
||||||
rmhost ()
|
rmhost()
|
||||||
{
|
{
|
||||||
if [[ "$#" -lt 1 ]]; then
|
local PARSED
|
||||||
disp E "Incorrect number of parameters."
|
PARSED=$(getopt -o h --long help -n 'rmhost' -- "$@")
|
||||||
disp E "Usage: rmhost <hostname|ip> [hostname2|ip2 [...]]"
|
if [[ $? -ne 0 ]]; then return 1; fi
|
||||||
return 1
|
eval set -- "$PARSED"
|
||||||
fi
|
|
||||||
|
|
||||||
while [[ $1 ]]; do
|
|
||||||
local hst=$1 && shift
|
|
||||||
isipv4 $hst > /dev/null
|
|
||||||
local v4=$?
|
|
||||||
isipv6 $hst > /dev/null
|
|
||||||
local v6=$?
|
|
||||||
|
|
||||||
if [[ $v4 -eq 0 || $v6 -eq 0 ]]; then
|
|
||||||
local ip=$hst
|
|
||||||
unset hst
|
|
||||||
fi
|
|
||||||
unset v4 v6
|
|
||||||
|
|
||||||
if [[ ! $ip && $hst ]]; then
|
|
||||||
ip=$(host $hst | grep "has address" | awk '{print $NF}')
|
|
||||||
[[ ! $? ]] &&
|
|
||||||
disp E "Impossible to extract IP from hostname." &&
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ $hst ]]; then
|
|
||||||
disp I "Removing host $hst from ssh known_host..."
|
|
||||||
ssh-keygen -R $hst > /dev/null
|
|
||||||
fi
|
|
||||||
if [[ $ip ]]; then
|
|
||||||
disp I "Removing IP $ip from ssh known_host..."
|
|
||||||
ssh-keygen -R $ip > /dev/null
|
|
||||||
fi
|
|
||||||
unset hst ip
|
|
||||||
done
|
|
||||||
}
|
|
||||||
export -f rmhost
|
|
||||||
|
|
||||||
|
while true; do
|
||||||
# ------------------------------------------------------------------------------
|
case "$1" in
|
||||||
# Login root via SSH on the given machine
|
-h|--help)
|
||||||
# ------------------------------------------------------------------------------
|
printf "rmhost: Remove host/IP from ~/.ssh/known_hosts.\n\n"
|
||||||
ssr ()
|
printf "Usage: rmhost <hostname|ip> [hostname2|ip2 ...]\n\n"
|
||||||
{
|
printf "Options:\n"
|
||||||
for opt in $@ ; do
|
printf " -h, --help Display this help screen\n"
|
||||||
case $opt in
|
|
||||||
"-h"|"--help")
|
|
||||||
echo "ssr: do a root user ssh login."
|
|
||||||
echo
|
|
||||||
echo "Usage: ssr <server [ssh options]>"
|
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
|
--)
|
||||||
|
shift
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
disp E "Invalid options, use \"rmhost --help\" to display usage."
|
||||||
|
break
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
[[ ! $1 ]] &&
|
# Validation: Ensure at least one argument remains
|
||||||
disp E "Please specify the server you want to log in." &&
|
if [[ $# -eq 0 ]]; then
|
||||||
|
disp E "Missing argument. Use 'rmhost --help' for usage."
|
||||||
return 1
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
for target in "$@"; do
|
||||||
|
local hst=$target
|
||||||
|
isipv4 "$hst" >/dev/null
|
||||||
|
local v4=$?
|
||||||
|
isipv6 "$hst" >/dev/null
|
||||||
|
local v6=$?
|
||||||
|
|
||||||
|
if [[ $v4 -eq 0 || $v6 -eq 0 ]]; then
|
||||||
|
local ip=$hst
|
||||||
|
unset hst
|
||||||
|
fi
|
||||||
|
unset v4 v6
|
||||||
|
|
||||||
|
if [[ ! $ip && $hst ]]; then
|
||||||
|
if ! ip=$(host "$hst" 2>/dev/null | awk '/has address/ {print $NF; exit}'); then
|
||||||
|
disp E "Impossible to extract IP from hostname." &&
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
[[ -z $ip ]] && {
|
||||||
|
disp E "Impossible to extract IP from hostname."
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $hst ]]; then
|
||||||
|
disp I "Removing host $hst from ssh known_host..."
|
||||||
|
ssh-keygen -R $hst >/dev/null
|
||||||
|
fi
|
||||||
|
if [[ $ip ]]; then
|
||||||
|
disp I "Removing IP $ip from ssh known_host..."
|
||||||
|
ssh-keygen -R $ip >/dev/null
|
||||||
|
fi
|
||||||
|
unset hst ip
|
||||||
|
done
|
||||||
|
}
|
||||||
|
export -f rmhost
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# Login root via SSH on the given machine
|
||||||
|
# Usage: ssr <server [ssh options]>
|
||||||
|
ssr()
|
||||||
|
{
|
||||||
|
local PARSED
|
||||||
|
PARSED=$(getopt -o h --long help -n 'ssr' -- "$@")
|
||||||
|
if [[ $? -ne 0 ]]; then return 1; fi
|
||||||
|
eval set -- "$PARSED"
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
case "$1" in
|
||||||
|
-h|--help)
|
||||||
|
printf "ssr: SSH into a server as root.\n\n"
|
||||||
|
printf "Usage: ssr <server> [ssh_options...]\n\n"
|
||||||
|
printf "Options:\n"
|
||||||
|
printf "\t-h, --help\t\tDisplay this help screen\n"
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
--)
|
||||||
|
shift
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
disp E "Invalid options, use \"ssr --help\" to display usage."
|
||||||
|
return 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
command -v ssh >/dev/null 2>&1 || {
|
||||||
|
disp E "ssh is not installed."
|
||||||
|
return 127
|
||||||
|
}
|
||||||
|
[[ ! $1 ]] && {
|
||||||
|
disp E "Please specify the server you want to log in."
|
||||||
|
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
|
||||||
|
|||||||
188
profile.d/updates.sh
Normal file
188
profile.d/updates.sh
Normal file
@@ -0,0 +1,188 @@
|
|||||||
|
#!/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
|
||||||
|
# Usage: check_updates [-q]
|
||||||
|
# If -q is specified, the function will operate in quiet mode (internal use only)
|
||||||
|
check_updates()
|
||||||
|
{
|
||||||
|
local quiet=0
|
||||||
|
local PARSED=$(getopt -o hq --long help,quiet -n 'check_updates' -- "$@")
|
||||||
|
if [[ $? -ne 0 ]]; then
|
||||||
|
disp E "Invalid options, use \"check_updates --help\" to display usage."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
eval set -- "$PARSED"
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
case "$1" in
|
||||||
|
-h|--help)
|
||||||
|
printf "check_updates: Check for new versions.\n\n"
|
||||||
|
printf "Usage: check_updates\n"
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
-q|--quiet)
|
||||||
|
quiet=1
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
--)
|
||||||
|
shift
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
[[ $quiet != 1 ]] && 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 != 1 ]] && disp I "You should upgrade to last version when possible."
|
||||||
|
result=1
|
||||||
|
else
|
||||||
|
[[ $quiet != 1 ]] && 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
|
||||||
|
# Usage: profile_upgrade
|
||||||
|
profile_upgrade()
|
||||||
|
{
|
||||||
|
local PARSED=$(getopt -o h --long help -n 'profile_upgrade' -- "$@")
|
||||||
|
if [[ $? -ne 0 ]]; then
|
||||||
|
printf "Invalid options, use \"profile_upgrade --help\" to display usage."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
eval set -- "$PARSED"
|
||||||
|
while true; do
|
||||||
|
case "$1" in
|
||||||
|
-h|--help)
|
||||||
|
printf "profile_upgrade: Upgrade the profile to the latest version.\n\n"
|
||||||
|
printf "Usage: profile_upgrade\n"
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
--)
|
||||||
|
shift
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
disp E "Invalid options, use \"profile_upgrade --help\" to display usage."
|
||||||
|
return 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if check_updates -q; then
|
||||||
|
disp "No update available."
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
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
|
||||||
100
profile.sh
100
profile.sh
@@ -1,43 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/usr/bin/env 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
|
|
||||||
# 18/11/2022 v3.2.0 : created disp command for display, make use of it
|
|
||||||
# ------------------------------------------------------------------------------
|
|
||||||
# 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.
|
||||||
#
|
#
|
||||||
@@ -72,12 +35,8 @@
|
|||||||
# * OF SUCH DAMAGE.
|
# * OF SUCH DAMAGE.
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
export PROFVERSION="3.2.0"
|
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"
|
|
||||||
|
|
||||||
if [[ ! $(echo $SHELL | grep bash) ]]; then
|
|
||||||
echo "That environmet script is designed to be used with bash or zsh being the shell."
|
|
||||||
echo "Please consider using bash or zsh instead, or patch me ;)!"
|
echo "Please consider using bash or zsh instead, or patch me ;)!"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
@@ -85,49 +44,71 @@ 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"
|
||||||
@@ -143,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
|
||||||
@@ -161,7 +147,7 @@ done
|
|||||||
# Interactive shell detection, two methods available each one of those might have different result
|
# Interactive shell detection, two methods available each one of those might have different result
|
||||||
# depending on distribution
|
# depending on distribution
|
||||||
#shopt -q login_shell && INTERACTIVE=1
|
#shopt -q login_shell && INTERACTIVE=1
|
||||||
[[ $- == *i* ]] && INTERACTIVE=1
|
[[ $- == *i* ]] && export INTERACTIVE=1
|
||||||
|
|
||||||
if [[ $INTERACTIVE ]]; then
|
if [[ $INTERACTIVE ]]; then
|
||||||
# For compiling (as we often compile with LFS/0linux...)
|
# For compiling (as we often compile with LFS/0linux...)
|
||||||
@@ -189,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
|
||||||
@@ -197,6 +184,7 @@ if [[ $INTERACTIVE ]]; then
|
|||||||
# Set default language
|
# Set default language
|
||||||
setfr
|
setfr
|
||||||
showinfo
|
showinfo
|
||||||
|
check_updates -q
|
||||||
disp I "Profile version $PROFVERSION chargé..."
|
disp I "Profile version $PROFVERSION chargé..."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user