My favorites | Sign in
Project Home Issues Source
Checkout   Browse   Changes    
 
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/bin/bash
########################################################################
#### Script Name: smxi-stub
#### stub installer for smxi scripts
#### Only supports true Debian based distros.
#### version: 3.0
#### Date: 24 February 2010
########################################################################
#### Copyright (C) Harald Hope, sidux team members 2007-2010
####
#### This program is free software; you can redistribute it and/or modify it under
#### the terms of the GNU General Public License as published by the Free Software
#### Foundation; either version 2 of the License, or (at your option) any later version.
####
#### This program is distributed in the hope that it will be useful, but WITHOUT
#### ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
#### FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
####
#### Get the full text of the GPL here: http://www.gnu.org/licenses/gpl.txt
########################################################################

# Please do not change the logic here, it makes it too hard to read linearly:
# [ ! -f somefile ] && do something is far easier to read than [ -f somefile ] || do something
# tempfile primary cleanup is now handled by called scripts, so no need to complicate this
# simple stub with the cleanup stuff. Now it just cleans up after itself each time.

# To get the full power and user friendliness for this stub installer
# rename it to: smxi
# place it in /usr/sbin, that is, as /usr/sbin/smxi, make it executable: chmod +x /usr/sbin/smxi
# add the following symbolic links in /usr/sbin pointing to /usr/sbin/smxi:
# ln -s /usr/sbin/smxi /usr/sbin/inxi
# ln -s /usr/sbin/smxi /usr/sbin/sgfxi
# ln -s /usr/sbin/smxi /usr/sbin/svmi
# because of how default $PATH works, /usr/sbin will always be checked first for the
# scripts, and if they are missing, this stub will download and execute them, otherwise
# the request will simply be passed along to /usr/local/bin location of actual scripts

# this will handle stub for any other script also
CALLER="$( basename $0 )"
PREFIX='/usr/local/bin/'
DOWNLOAD_URL=''
DOWNLOAD_URL_INXI='http://inxi.googlecode.com/svn/trunk/'
DOWNLOAD_URL_SGFXI='http://smxi.org/sg/'
DOWNLOAD_URL_SMXI='http://smxi.org/sm/'
DOWNLOAD_URL_SVMI='http://smxi.org/sv/'
FILE_DATA_TEMP='' # will handle failed downloads
IS_GOOD=''
# this is the tester for ##**EOF**## endings present in scripts, change this
# if you want to extend this stub to other scripts, smxi/svmi/inxi/sgfxi all use this
SCRIPT_EOF='##\*\*EOF\*\*##'

# args: $1 - error number; $2 - extra data
error_handler()
{
local message=''
case $1 in
1) message='You must be root to run this script!'
;;
2) message="Script download exited with errors.\nThe following download url failed with wget error: $2/n$DOWNLOAD_URL$SCRIPT"
;;
3) message='Failed to download script properly. The file data is corrupted or incomplete!'
;;
4) message="$PREFIX$SCRIPT exec command failed with error number: $2\nPlease try again."
;;
5) message="$PREFIX$SCRIPT not executable!"
;;
6) message="Unknown script requested: $CALLER"
;;
*) message='Unknown error, exiting now.'
;;
esac
echo -e "Error No: $1 - $message"
exit $1
}

# set the SCRIPT/DOWNLOAD_URL/SCRIPT_EOFvalues
case $CALLER in
sgfxi)
SCRIPT="$CALLER"
DOWNLOAD_URL=$DOWNLOAD_URL_SGFXI
;;
smxi)
SCRIPT="$CALLER"
DOWNLOAD_URL=$DOWNLOAD_URL_SMXI
;;
svmi)
SCRIPT="$CALLER"
DOWNLOAD_URL=$DOWNLOAD_URL_SVMI
;;
inxi)
SCRIPT="$CALLER"
DOWNLOAD_URL=$DOWNLOAD_URL_INXI
;;
*)
error_handler 6
;;
esac

# if $SCRIPT exists, it will handle the root tests. Root tests cannot
# be run first because they kill the -h help function
if [ -x "$PREFIX$SCRIPT" ];then
# I'm just going to put a test for basically everything that can go wrong
exec "$PREFIX$SCRIPT" "$@" || error_handler 4 "$?"
else
# only in case of requirement to download script do root test, and just exit
# if not root, anything else is counterintuitive I think for users.
if [ "$( id -u )" -ne 0 ];then
error_handler 1
fi
# downloading to overwrite existing file, but to temp variable, which we then test
FILE_DATA_TEMP="$( wget -q -O - $DOWNLOAD_URL$SCRIPT )" || error_handler 2 "$?"
IS_GOOD=$( grep -si "$SCRIPT_EOF" <<< "$FILE_DATA_TEMP" )
# test to make sure downloaded data has EOF marker, if yes, it's complete
if [ -z "$IS_GOOD" ];then
error_handler 3
else
# now that the data is tested and not corrupted move to real file
echo "$FILE_DATA_TEMP" > $PREFIX$SCRIPT
# make new file executable
chmod 705 "$PREFIX$SCRIPT"
# then run it with an error handler for unknown weirdness which I'm sure will appear.
if [ -x "$PREFIX$SCRIPT" ];then
# If for some reason it errors on script execution, exit here, but that could be
# something as simple as bad options used
exec "$PREFIX$SCRIPT" "$@" || error_handler 4 "$?"
else
error_handler 5
fi
fi
fi

Change log

r1667 by inxi-...@techpatterns.com on Feb 24, 2010   Diff
tweak to smxi-stub
Go to: 
Project members, sign in to write a code review

Older revisions

r1666 by inxi-...@techpatterns.com on Feb 24, 2010   Diff
accidentally overwrote, fixed
r1665 by inxi-...@techpatterns.com on Feb 24, 2010   Diff
cleanup
r1664 by inxi-...@techpatterns.com on Feb 24, 2010   Diff
small bug fix
All revisions of this file

File info

Size: 4992 bytes, 131 lines

File properties

svn:executable
*
Powered by Google Project Hosting