Browse Source

Initial commit and first release~

master
Bandie 1 year ago
parent
commit
6a9c9db7b8
Signed by: Bandie <bandie@chaospott.de> GPG Key ID: 843D7FA93BA46312
6 changed files with 244 additions and 1 deletions
  1. 18
    0
      Makefile
  2. 36
    1
      README.md
  3. 6
    0
      build/etc/default/grub
  4. 51
    0
      build/etc/grub.d/000_ownership
  5. 51
    0
      etc/grub.d/000_ownership
  6. 82
    0
      tools/grub_append_cfgkeys

+ 18
- 0
Makefile View File

@@ -0,0 +1,18 @@
1
+# Author: Bandie <bandie@chaospott.de>
2
+# Copyright: Bandie, 2019, GNU-GPLv3
3
+all: 
4
+	@echo "Nothing to make. Please run \"make install\"."
5
+	@exit 0
6
+install:
7
+	@echo "Installing grub-ownership..."
8
+	install -vDm 755 etc/grub.d/000_ownership -t "$(PREFIX)/etc/grub.d/"
9
+	@echo "Appending not existent config keys..."
10
+	./tools/grub_append_cfgkeys -i $(PREFIX)/etc/default/grub
11
+	@echo "DONE!"
12
+
13
+uninstall:
14
+	@echo "Remove grub-ownership..."
15
+	rm $(PREFIX)/etc/grub.d/000_ownership
16
+	@echo "Removing entries from config file..."
17
+	./tools/grub_append_cfgkeys -r $(PREFIX)/etc/default/grub
18
+	@echo "DONE!"

+ 36
- 1
README.md View File

@@ -1,2 +1,37 @@
1 1
 # grub-ownership
2
-Show an owner when grub is booting up
2
+Show an owner when grub is booting up.
3
+
4
+## Installation
5
+
6
+```
7
+sudo make install
8
+# OR with an autotools like PREFIX:
9
+sudo PREFIX=/another/root make install
10
+```
11
+
12
+
13
+## Configuration
14
+
15
+Edit the file `/etc/default/grub`.
16
+
17
+This is an example config
18
+
19
+```
20
+# Name and mail address of owner
21
+OWNER="Alex Alexsen <a@a.tld>"
22
+
23
+# Amounts of seconds for how long the owner information is displayed. It is skippable via ESC.
24
+OWNER_TIMEOUT=10
25
+```
26
+
27
+
28
+
29
+## Uninstall
30
+
31
+```
32
+sudo make uninstall
33
+# OR with an autotools like PREFIX:
34
+sudo PREFIX=/another/root make uninstall
35
+```
36
+
37
+

+ 6
- 0
build/etc/default/grub View File

@@ -0,0 +1,6 @@
1
+
2
+# Name and mail address of owner
3
+#OWNER="John Doe <john@doe.tld>"
4
+
5
+# Amounts of seconds for how long the owner information is displayed. It is skippable via ESC. Default: 5
6
+#OWNER_TIMEOUT=5

+ 51
- 0
build/etc/grub.d/000_ownership View File

@@ -0,0 +1,51 @@
1
+#!/bin/sh
2
+# Author: Bandie <bandie@chaospott.de>
3
+# Copyright: Bandie, 2019, GNU-GPLv3
4
+
5
+set -e
6
+
7
+## Get params from /etc/default/grub
8
+OWNER=$(cat /etc/default/grub | egrep "^OWNER=.*$" | sed "s/.*=\(.*\)/\1/;s/\"//g;s/'//g")
9
+OWNER_TIMEOUT=$(cat /etc/default/grub | egrep "^OWNER_TIMEOUT=.*$" | sed "s/.*=\(.*\)/\1/;s/\"//g;s/'//g")
10
+
11
+
12
+## Check if OWNER is set
13
+if [ -z "$OWNER" ]; then
14
+	echo "/etc/default/grub: No OWNER set." >&2
15
+	exit 0
16
+fi
17
+
18
+## Notify user about ownership
19
+echo "Show ==> $OWNER <== as owner" >&2
20
+
21
+
22
+## Generate spaces in case if the owner has a very short name
23
+for ((i=${#OWNER}; i<6; i++)); do
24
+	NSP="$NSP "
25
+done
26
+
27
+## Generate border around the owner message
28
+B="##########"
29
+for ((i=6; i<${#OWNER}; i++)); do
30
+	B="${B}#"
31
+	SPACE="$SPACE "
32
+done
33
+
34
+
35
+## Check if OWNER_TIMEOUT is set. If not, default 5
36
+if ! [[ $OWNER_TIMEOUT =~ ^[0-9]+$ ]]; then
37
+	OWNER_TIMEOUT=5
38
+	echo "/etc/default/grub: No OWNER_TIMEOUT set. Using default: 5 seconds." >&2
39
+fi
40
+
41
+## Write it into the grub.cfg
42
+cat << EOF
43
+echo ""
44
+echo "$B"
45
+echo "# Owner: ${SPACE}#"
46
+echo "# $OWNER $NSP#"
47
+echo "$B"
48
+echo ""
49
+echo ""
50
+sleep -i $OWNER_TIMEOUT
51
+EOF

+ 51
- 0
etc/grub.d/000_ownership View File

@@ -0,0 +1,51 @@
1
+#!/bin/sh
2
+# Author: Bandie <bandie@chaospott.de>
3
+# Copyright: Bandie, 2019, GNU-GPLv3
4
+
5
+set -e
6
+
7
+## Get params from /etc/default/grub
8
+OWNER=$(cat /etc/default/grub | egrep "^OWNER=.*$" | sed "s/.*=\(.*\)/\1/;s/\"//g;s/'//g")
9
+OWNER_TIMEOUT=$(cat /etc/default/grub | egrep "^OWNER_TIMEOUT=.*$" | sed "s/.*=\(.*\)/\1/;s/\"//g;s/'//g")
10
+
11
+
12
+## Check if OWNER is set
13
+if [ -z "$OWNER" ]; then
14
+	echo "/etc/default/grub: No OWNER set." >&2
15
+	exit 0
16
+fi
17
+
18
+## Notify user about ownership
19
+echo "Show ==> $OWNER <== as owner" >&2
20
+
21
+
22
+## Generate spaces in case if the owner has a very short name
23
+for ((i=${#OWNER}; i<6; i++)); do
24
+	NSP="$NSP "
25
+done
26
+
27
+## Generate border around the owner message
28
+B="##########"
29
+for ((i=6; i<${#OWNER}; i++)); do
30
+	B="${B}#"
31
+	SPACE="$SPACE "
32
+done
33
+
34
+
35
+## Check if OWNER_TIMEOUT is set. If not, default 5
36
+if ! [[ $OWNER_TIMEOUT =~ ^[0-9]+$ ]]; then
37
+	OWNER_TIMEOUT=5
38
+	echo "/etc/default/grub: No OWNER_TIMEOUT set. Using default: 5 seconds." >&2
39
+fi
40
+
41
+## Write it into the grub.cfg
42
+cat << EOF
43
+echo ""
44
+echo "$B"
45
+echo "# Owner: ${SPACE}#"
46
+echo "# $OWNER $NSP#"
47
+echo "$B"
48
+echo ""
49
+echo ""
50
+sleep -i $OWNER_TIMEOUT
51
+EOF

+ 82
- 0
tools/grub_append_cfgkeys View File

@@ -0,0 +1,82 @@
1
+#!/bin/bash
2
+# Author: Bandie <bandie@chaospott.de>
3
+# Copyright: Bandie, 2019, GNU-GPLv3
4
+
5
+CONFIG="/etc/default/grub"
6
+TMPCFG="grub_tmp"
7
+CFGKEYS=(
8
+
9
+  ## 'COMMENT'
10
+  ## 'KEY'
11
+  ## 'EXAMPLE_VALUE'
12
+
13
+  'Name and mail address of owner'
14
+  'OWNER'
15
+  '"John Doe <john@doe.tld>"'
16
+  
17
+  'Amounts of seconds for how long the owner information is displayed. It is skippable via ESC. Default: 5'
18
+  'OWNER_TIMEOUT'
19
+  '5'
20
+)
21
+
22
+
23
+function testPerms(){
24
+  if ! [ -e "$CONFIG" ]; then
25
+    echo "$0: ERROR: $CONFIG does not exist!"
26
+    exit 1
27
+  fi
28
+  if ! [ -w "$CONFIG" ]; then
29
+    echo "$0: ERROR: Permission denied for file $CONFIG"
30
+    exit 1
31
+  fi
32
+}
33
+
34
+
35
+function append(){
36
+  testPerms
37
+
38
+  for ((i=0; i<${#CFGKEYS[@]}; i+=3)); do
39
+    cat "$CONFIG" | grep "${CFGKEYS[(($i+1))]}" >> /dev/null
40
+    if [ $? -ne 0 ]; then
41
+      echo "Adding ${CFGKEYS[(($i+1))]} to $CONFIG..."
42
+      echo "" >> $CONFIG
43
+      echo "# ${CFGKEYS[$i]}" >> $CONFIG
44
+      echo "#${CFGKEYS[(($i+1))]}=${CFGKEYS[(($i+2))]}" >> $CONFIG
45
+    fi
46
+
47
+  done
48
+}
49
+
50
+function remove(){
51
+  testPerms
52
+  
53
+  for ((i=0; i<${#CFGKEYS[@]}; i+=3)); do
54
+    echo "Removing ${CFGKEYS[(($i+1))]} from $CONFIG..."
55
+    sed "$!N;/${CFGKEYS[$i]}/!P;D" "$CONFIG" | sed "/.*${CFGKEYS[(($i+1))]}=.*/d" > "$TMPCFG"
56
+    cp "$TMPCFG" "$CONFIG"
57
+  done
58
+  rm $TMPCFG
59
+}
60
+
61
+function h(){
62
+  echo "$0: Usage:"
63
+  echo "$0 -i [ CONFIGFILE ] - Install config keys to config file. Configfile optional."
64
+  echo "$0 -r [ CONFIGFILE ] - Remove config keys from config file. Configfile optional."
65
+}
66
+
67
+if [ -n "$2" ]; then
68
+  CONFIG="$2"
69
+fi
70
+
71
+case $1 in
72
+"-i")
73
+  append
74
+  ;;
75
+
76
+"-r")
77
+  remove
78
+  ;;
79
+
80
+*)
81
+  h
82
+esac

Loading…
Cancel
Save