Initial commit and first release~
This commit is contained in:
parent
25e38f198b
commit
6a9c9db7b8
18
Makefile
Normal file
18
Makefile
Normal file
@ -0,0 +1,18 @@
|
||||
# Author: Bandie <bandie@chaospott.de>
|
||||
# Copyright: Bandie, 2019, GNU-GPLv3
|
||||
all:
|
||||
@echo "Nothing to make. Please run \"make install\"."
|
||||
@exit 0
|
||||
install:
|
||||
@echo "Installing grub-ownership..."
|
||||
install -vDm 755 etc/grub.d/000_ownership -t "$(PREFIX)/etc/grub.d/"
|
||||
@echo "Appending not existent config keys..."
|
||||
./tools/grub_append_cfgkeys -i $(PREFIX)/etc/default/grub
|
||||
@echo "DONE!"
|
||||
|
||||
uninstall:
|
||||
@echo "Remove grub-ownership..."
|
||||
rm $(PREFIX)/etc/grub.d/000_ownership
|
||||
@echo "Removing entries from config file..."
|
||||
./tools/grub_append_cfgkeys -r $(PREFIX)/etc/default/grub
|
||||
@echo "DONE!"
|
37
README.md
37
README.md
@ -1,2 +1,37 @@
|
||||
# grub-ownership
|
||||
Show an owner when grub is booting up
|
||||
Show an owner when grub is booting up.
|
||||
|
||||
## Installation
|
||||
|
||||
```
|
||||
sudo make install
|
||||
# OR with an autotools like PREFIX:
|
||||
sudo PREFIX=/another/root make install
|
||||
```
|
||||
|
||||
|
||||
## Configuration
|
||||
|
||||
Edit the file `/etc/default/grub`.
|
||||
|
||||
This is an example config
|
||||
|
||||
```
|
||||
# Name and mail address of owner
|
||||
OWNER="Alex Alexsen <a@a.tld>"
|
||||
|
||||
# Amounts of seconds for how long the owner information is displayed. It is skippable via ESC.
|
||||
OWNER_TIMEOUT=10
|
||||
```
|
||||
|
||||
|
||||
|
||||
## Uninstall
|
||||
|
||||
```
|
||||
sudo make uninstall
|
||||
# OR with an autotools like PREFIX:
|
||||
sudo PREFIX=/another/root make uninstall
|
||||
```
|
||||
|
||||
|
||||
|
6
build/etc/default/grub
Normal file
6
build/etc/default/grub
Normal file
@ -0,0 +1,6 @@
|
||||
|
||||
# Name and mail address of owner
|
||||
#OWNER="John Doe <john@doe.tld>"
|
||||
|
||||
# Amounts of seconds for how long the owner information is displayed. It is skippable via ESC. Default: 5
|
||||
#OWNER_TIMEOUT=5
|
51
build/etc/grub.d/000_ownership
Executable file
51
build/etc/grub.d/000_ownership
Executable file
@ -0,0 +1,51 @@
|
||||
#!/bin/sh
|
||||
# Author: Bandie <bandie@chaospott.de>
|
||||
# Copyright: Bandie, 2019, GNU-GPLv3
|
||||
|
||||
set -e
|
||||
|
||||
## Get params from /etc/default/grub
|
||||
OWNER=$(cat /etc/default/grub | egrep "^OWNER=.*$" | sed "s/.*=\(.*\)/\1/;s/\"//g;s/'//g")
|
||||
OWNER_TIMEOUT=$(cat /etc/default/grub | egrep "^OWNER_TIMEOUT=.*$" | sed "s/.*=\(.*\)/\1/;s/\"//g;s/'//g")
|
||||
|
||||
|
||||
## Check if OWNER is set
|
||||
if [ -z "$OWNER" ]; then
|
||||
echo "/etc/default/grub: No OWNER set." >&2
|
||||
exit 0
|
||||
fi
|
||||
|
||||
## Notify user about ownership
|
||||
echo "Show ==> $OWNER <== as owner" >&2
|
||||
|
||||
|
||||
## Generate spaces in case if the owner has a very short name
|
||||
for ((i=${#OWNER}; i<6; i++)); do
|
||||
NSP="$NSP "
|
||||
done
|
||||
|
||||
## Generate border around the owner message
|
||||
B="##########"
|
||||
for ((i=6; i<${#OWNER}; i++)); do
|
||||
B="${B}#"
|
||||
SPACE="$SPACE "
|
||||
done
|
||||
|
||||
|
||||
## Check if OWNER_TIMEOUT is set. If not, default 5
|
||||
if ! [[ $OWNER_TIMEOUT =~ ^[0-9]+$ ]]; then
|
||||
OWNER_TIMEOUT=5
|
||||
echo "/etc/default/grub: No OWNER_TIMEOUT set. Using default: 5 seconds." >&2
|
||||
fi
|
||||
|
||||
## Write it into the grub.cfg
|
||||
cat << EOF
|
||||
echo ""
|
||||
echo "$B"
|
||||
echo "# Owner: ${SPACE}#"
|
||||
echo "# $OWNER $NSP#"
|
||||
echo "$B"
|
||||
echo ""
|
||||
echo ""
|
||||
sleep -i $OWNER_TIMEOUT
|
||||
EOF
|
51
etc/grub.d/000_ownership
Executable file
51
etc/grub.d/000_ownership
Executable file
@ -0,0 +1,51 @@
|
||||
#!/bin/sh
|
||||
# Author: Bandie <bandie@chaospott.de>
|
||||
# Copyright: Bandie, 2019, GNU-GPLv3
|
||||
|
||||
set -e
|
||||
|
||||
## Get params from /etc/default/grub
|
||||
OWNER=$(cat /etc/default/grub | egrep "^OWNER=.*$" | sed "s/.*=\(.*\)/\1/;s/\"//g;s/'//g")
|
||||
OWNER_TIMEOUT=$(cat /etc/default/grub | egrep "^OWNER_TIMEOUT=.*$" | sed "s/.*=\(.*\)/\1/;s/\"//g;s/'//g")
|
||||
|
||||
|
||||
## Check if OWNER is set
|
||||
if [ -z "$OWNER" ]; then
|
||||
echo "/etc/default/grub: No OWNER set." >&2
|
||||
exit 0
|
||||
fi
|
||||
|
||||
## Notify user about ownership
|
||||
echo "Show ==> $OWNER <== as owner" >&2
|
||||
|
||||
|
||||
## Generate spaces in case if the owner has a very short name
|
||||
for ((i=${#OWNER}; i<6; i++)); do
|
||||
NSP="$NSP "
|
||||
done
|
||||
|
||||
## Generate border around the owner message
|
||||
B="##########"
|
||||
for ((i=6; i<${#OWNER}; i++)); do
|
||||
B="${B}#"
|
||||
SPACE="$SPACE "
|
||||
done
|
||||
|
||||
|
||||
## Check if OWNER_TIMEOUT is set. If not, default 5
|
||||
if ! [[ $OWNER_TIMEOUT =~ ^[0-9]+$ ]]; then
|
||||
OWNER_TIMEOUT=5
|
||||
echo "/etc/default/grub: No OWNER_TIMEOUT set. Using default: 5 seconds." >&2
|
||||
fi
|
||||
|
||||
## Write it into the grub.cfg
|
||||
cat << EOF
|
||||
echo ""
|
||||
echo "$B"
|
||||
echo "# Owner: ${SPACE}#"
|
||||
echo "# $OWNER $NSP#"
|
||||
echo "$B"
|
||||
echo ""
|
||||
echo ""
|
||||
sleep -i $OWNER_TIMEOUT
|
||||
EOF
|
82
tools/grub_append_cfgkeys
Executable file
82
tools/grub_append_cfgkeys
Executable file
@ -0,0 +1,82 @@
|
||||
#!/bin/bash
|
||||
# Author: Bandie <bandie@chaospott.de>
|
||||
# Copyright: Bandie, 2019, GNU-GPLv3
|
||||
|
||||
CONFIG="/etc/default/grub"
|
||||
TMPCFG="grub_tmp"
|
||||
CFGKEYS=(
|
||||
|
||||
## 'COMMENT'
|
||||
## 'KEY'
|
||||
## 'EXAMPLE_VALUE'
|
||||
|
||||
'Name and mail address of owner'
|
||||
'OWNER'
|
||||
'"John Doe <john@doe.tld>"'
|
||||
|
||||
'Amounts of seconds for how long the owner information is displayed. It is skippable via ESC. Default: 5'
|
||||
'OWNER_TIMEOUT'
|
||||
'5'
|
||||
)
|
||||
|
||||
|
||||
function testPerms(){
|
||||
if ! [ -e "$CONFIG" ]; then
|
||||
echo "$0: ERROR: $CONFIG does not exist!"
|
||||
exit 1
|
||||
fi
|
||||
if ! [ -w "$CONFIG" ]; then
|
||||
echo "$0: ERROR: Permission denied for file $CONFIG"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
function append(){
|
||||
testPerms
|
||||
|
||||
for ((i=0; i<${#CFGKEYS[@]}; i+=3)); do
|
||||
cat "$CONFIG" | grep "${CFGKEYS[(($i+1))]}" >> /dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Adding ${CFGKEYS[(($i+1))]} to $CONFIG..."
|
||||
echo "" >> $CONFIG
|
||||
echo "# ${CFGKEYS[$i]}" >> $CONFIG
|
||||
echo "#${CFGKEYS[(($i+1))]}=${CFGKEYS[(($i+2))]}" >> $CONFIG
|
||||
fi
|
||||
|
||||
done
|
||||
}
|
||||
|
||||
function remove(){
|
||||
testPerms
|
||||
|
||||
for ((i=0; i<${#CFGKEYS[@]}; i+=3)); do
|
||||
echo "Removing ${CFGKEYS[(($i+1))]} from $CONFIG..."
|
||||
sed "$!N;/${CFGKEYS[$i]}/!P;D" "$CONFIG" | sed "/.*${CFGKEYS[(($i+1))]}=.*/d" > "$TMPCFG"
|
||||
cp "$TMPCFG" "$CONFIG"
|
||||
done
|
||||
rm $TMPCFG
|
||||
}
|
||||
|
||||
function h(){
|
||||
echo "$0: Usage:"
|
||||
echo "$0 -i [ CONFIGFILE ] - Install config keys to config file. Configfile optional."
|
||||
echo "$0 -r [ CONFIGFILE ] - Remove config keys from config file. Configfile optional."
|
||||
}
|
||||
|
||||
if [ -n "$2" ]; then
|
||||
CONFIG="$2"
|
||||
fi
|
||||
|
||||
case $1 in
|
||||
"-i")
|
||||
append
|
||||
;;
|
||||
|
||||
"-r")
|
||||
remove
|
||||
;;
|
||||
|
||||
*)
|
||||
h
|
||||
esac
|
Loading…
Reference in New Issue
Block a user