summarylogtreecommitdiffstats
path: root/autorebuild-dgrp.sh
blob: 50ee4913fa598c6ffa67aac1db8b246bd135c452 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/bash

# Part of the dgrp-1.9.35 PKGBUILD from Arch Linux AUR
# http://aur.archlinux.org/

# If you remove this script your package will not auto rebuild 
# and your hardware will stop working after the next kernel upgrade.

# Purpose: Automatically build and install this package on the next login
# after pacman removes it on kernel upgrade. 
# Every package that needs to be autorebuilt should have a shell script
# like this one. All you need is a PKGBUILD and a sense file to tell
# when the package is missing.

# This shell script can be easily adapted to any PKGBUILD. As an alternative
# you can look into "DKMS" Dynamic Kernel Module Support.

# To launch, add this to any user's profile or the system profile.
# The preferred user is the one most likely to log on after an upgrade.
# sudo must be installed and configured. Each user expected to rebuild packages
# must be added to the wheel group (usermod -G).

# for install_group in `groups`; do
#   if [ "$install_group" = "wheel" ]; then
#     find ~/build -type f -perm /400 -name "autorebuild-*.sh" -exec sh '{}' ';'
#     break
#   fi
# done

# This presumes you have neatly placed all your packages into ~build.

# (Note: the multi user aspect has yet to be tested)

# For multiple users you can use a standard folder set to be world writable.

sensefile="/usr/lib/modules/$(uname -r)/misc/dgrp.ko"
rebuildtitle='Digi RealPort driver for Ethernet serial servers'
set -e
set -u

if [ ! -s "${sensefile}" ]; then
  if [ "${EUID}" -ne 0 ]; then
    cd "$(dirname "$0")" # compatible with cron and find
    #prevumask=$(umask); umask 000
    makepkg -sCcfi || sleep 5
    #umask ${prevumask}
    ## Allow other users to build without permissions interference
    ## This would be a security problem in most environments
    ## chmod 777 files with any x bit set
    #find . -type f ! "(" -perm 666 -o -perm 777 ")" -a -perm /111 -exec chmod 777 '{}' ';'
    ## chmod 666 files without any x bit set
    #find . -type f ! "(" -perm 666 -o -perm 777 ")" -a "!" -perm /111 -exec chmod 666 '{}' ';'
    ## chmod 777 files with any x bit set
    #find . -type d ! -perm 777 -exec chmod 777 '{}' ';'
  else
    # su user -c "$*" # this might work if you need the root user to rebuild.
    echo "$(tput clear)"
    echo "Important. A recent kernel upgrade has diabled your"
    echo ""
    echo "${rebuildtitle}"
    echo "Status: Disabled!"
    echo ""
    echo "It is easy to rebuild and enable but not by a root user."
    echo "You must log in as a non root user with sudo access (wheel group) and"
    echo ""
    echo "run: $0"
    echo ""
    echo "if it doesn't start automatically."
    echo "Press Enter"
    read autorebuild
  fi
else
  echo "${rebuildtitle} already installed"
fi