-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall
More file actions
executable file
·74 lines (66 loc) · 2.45 KB
/
install
File metadata and controls
executable file
·74 lines (66 loc) · 2.45 KB
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
#!/bin/bash
install () {
builder=$(dirname "$(realpath "$BASH_SOURCE")")
target=$1
if [[ "$1" == "remove" ]]; then
_remove=true
shift
else
unset _remove
fi
[[ "$1" == "-d" ]] && dir="$2" && shift 2
target=${dir:-/usr/bin}/${1:-udib}
cmd=$(basename $target)
dir=$(dirname $target)
if [[ $_remove ]]; then
if [[ -f $target ]]; then
echo link to builder found at "$target. Do you want to REMOVE IT? (y/n) "
read -e ans
[[ ! $ans == "y" ]] && return 1
usesudo=""
[[ $(stat -c "%U" $target) == "root" ]] && usesudo=sudo && echo owned by root, sudo required
$usesudo /bin/rm $target
return 0
else
echo link to builder not found at $target, nothing to remove
fi
return
fi
# echo "$PATH --- $dir"
declare -a a="(${PATH//:/ })"
for i in ${a[*]}; do [[ "$i" == "$dir" ]] && found=true; done
if [[ $found ]]; then
echo creating a link \'$cmd\' in \'$dir\' to \'$builder\'
if [[ -f $target ]]; then
echo "$target already exists do you want to overwrite? (y/n) "
read -e ans
[[ ! $ans == "y" ]] && exit 1
fi
usesudo=""
[[ $(stat -c "%U" $dir) == "root" ]] && usesudo=sudo && echo link target directory owned by root requires sudo
if $usesudo ln -fns $builder/build $target; then
if [[ ! $(command -v $cmd) ]]; then
echo FATAL: link failed $cmd not found in path
else
echo install success: link $target created
ls -ls $target
echo now try running: \'$cmd -h\' now
fi
else
echo Error creating link
echo if \': Permission denied\' 'then' run \'sudo ./install\'
fi
else
echo "Install failed: $dir not in current path"
echo $PATH
echo "link to script not created. your install options are:"
echo "1. add $dir to your PATH"
echo "2. rerun this script using a directory in the system path (e.g ./install /usr/bin build)"
echo "3. add the following export somewhere in your shell (e.g. ~/.bashrc)"
echo " export UDIB=$builder/build"
echo ' and then use $UDIB to invoke the build script'
echo ' ( e.g $UDBI -e mybuild.env myimagename)'
fi
}
# if script was executed then call the function
(return 0 2>/dev/null) || install "$@"