File: Install.sh

package info (click to toggle)
bashburn 3.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, stretch
  • size: 1,140 kB
  • sloc: sh: 2,584; sed: 64; makefile: 19
file content (323 lines) | stat: -rwxr-xr-x 7,263 bytes parent folder | download | duplicates (2)
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
#!/bin/bash

errmsg()
{
    echo "$prog:$@" 1>&2
}
die()
{
    errmsg "$@"
    exit 1
}

proc_opts()
{
    typeset temp
    typeset arg

    temp=$(getopt -o :P:UHm --long prefix:,uninstall,help,make-tar -n $prog -- "$@")
    (( $? )) && usage && die 'getopt failure'

    # Note the quotes around `$temp': they are essential!
    eval set -- "$temp"
    while true
    do
        case "$1" in
	-P|--prefix)
	    [[ -z "$potprefix" ]] || usage 'You already specified --destdir'
	    potprefix="$2"	# POTential PREFIX
	    shift 2
	    ;;
	-U|--uninstall)
	    (( unistall )) && usage 'You said --uninstall twice?'
	    uninstall=1
	    shift
	    ;;
	-H|--help)
	    help=1
	    shift
	    ;;
	-m|--make-tar)
	    (( maketar )) && usage 'You said --make-tar twice?'
	    maketar=1
	    shift
	    ;;
	--)
	    shift
	    break
	    ;;
	*)
	    usage "$1: Unknown option"
	    ;;
        esac
    done
    (( $# > 0 )) && die "Too many arguments: $@"
} # proc_opts

usage()
{
    errmsg "$@"
    cat <<EOF 1>&2
Usage:
	$0 [OPTIONS]

	-P dir, --prefix=dir
	-U, --uninstall
	-H, --help
	-m, --make-tar

--prefix= will allow the user to specify the prefix directory 
where BashBurn will be installed or uninstalled.
The default is $defprefix. The support files will go
into \$dir/lib/BashBurn/lib and the program(s) will be in \$dir/bin

--uninstall will remove all of the BashBurn files from your system 
based on its knowledge of what prefix is.

--make-tar will create a .tar.bz2 file suitable for use in creating an RPM. 
           Must be used with --prefix.

--help This message

EOF
    exit 1
}

installation_finish()
{
    uninstall_info
    printf "\nInstallation finished successfully.
Now start %bBashBurn%b with the command %bbashburn%b, and
remember to configure it before trying to use it.\n\n" \
	"${green}" "${coloff}" "${blue}" "${coloff}"
}

install_files()
{
    typeset ii
    typeset jj
    typeset kk
    typeset -a dir_list=( \
	    burning \
	    config \
	    convert \
	    docs \
	    func \
	    lang \
	    menus \
	    misc \
	    )
    typeset -ra docs_files=( \
	    ChangeLog \
	    COPYING \
	    CREDITS \
	    FAQ \
	    HOWTO \
 	    README \
	    TODO \
	    TRANSLATION_RULE \
	    )
    typeset -ra top_files=( \
	    BashBurn.sh \
	    )
    typeset -ra burning_files=( \
	    bincue.sh \
	    burning.sh \
	    multi.sh \
	    )
    typeset -ra config_files=( \
	    apply_options.sh \
	    )
    typeset -ra convert_files=( \
	    convert_audio.sh \
	    convert_flacs.sh \
	    convert_mp3s.sh \
	    convert_oggs.sh \
	    )
    typeset -ra func_files=( \
	    advancedfunc.sh \
	    audiofunc.sh \
	    bincuefunc.sh \
	    configfunc.sh \
	    datafunc.sh \
	    definefunc.sh \
	    isofunc.sh \
	    mountfunc.sh \
	    multifunc.sh \
	    )
    typeset -ra languages=( \
	    Czech \
	    English \
	    German \
	    Italian \
	    Norwegian \
	    Polish \
	    Spanish \
	    Swedish \
	    )
    typeset -ra lang_files=( \
	    BashBurn.lang \
	    README \
	    advanced.lang \
	    audio_menu.lang \
	    bincue.lang \
	    burning.lang \
	    check_path.lang \
	    commonfunctions.lang \
	    configure.lang \
	    convert_flacs.lang \
	    convert_mp3s.lang \
	    convert_oggs.lang \
	    data_menu.lang \
	    datadefine.lang \
	    iso_menu.lang \
	    loopback.lang \
	    mount.lang \
	    multi.lang \
	    )
    typeset -ra menus_files=( \
	    advanced.sh \
	    audio_menu.sh \
	    bbmenu.sh
	    configure.sh \
	    datadefine.sh \
	    data_menu.sh \
	    iso_menu.sh \
	    mount.sh \
	    )
    typeset -ra misc_files=( \
	    check_path.sh \
	    colors.idx \
	    commands.idx \
	    commonfunctions.sh \
	    loopback.sh \
	    m3u_read.sh \
	    configure_temp_help.lang \  # This needs to go after all BBLANG help
					# texts are completed/updated
	    )
    echo -e "\nInstalling files... "
    mkdir -p $bblib || die 'Error: Can not create lib directory.'
    for ii in "${dir_list[@]}"
    do
	mkdir -p $bblib/$ii || 
		die 'Error: Can not create a subdirectory in lib.'
	if [[ $ii == lang ]]
	then
	    for jj in "${languages[@]}"
	    do
		mkdir -p $bblib/$ii/$jj || 
			die 'Error: Can not create a lang directory.'
		for kk in $(eval echo "\${${ii}_files[@]}")
		do
		    cp "lang/${jj}/$kk" $bblib/$ii/$jj/ || 
		    die "Failed to copy $ii/$jj/$kk" ||
			die 'Error: Failed to copy a file to a lang dir.'
		done
	    done
	else
	    for kk in $(eval echo "\${${ii}_files[@]}")
	    do
		cp $ii/$kk $bblib/$ii/ || die "Failed to copy $ii/$kk"
	    done
	fi
    done
    for ii in "${top_files[@]}"
    do
	cp $ii $bblib/$ii || die "Failed to copy $ii"
    done
    # After installing, See what tickles are needed.
    make -C bashburn_man
    mkdir -p $prefix/share/man/man1
    gzip < bashburn_man/bashburn.1 > $prefix/share/man/man1/bashburn.1.gz
    if (( ! maketar ))
    then
	cd $bblib
	sed -e "s%@@BBROOTDIR@@%$bblib%" BashBurn.sh > newbb-$$.sh
	mv newbb-$$.sh BashBurn.sh
	chmod +x BashBurn.sh
	echo -e "${green}[DONE]${coloff}"

	echo -n "Creating symlink... "
	mkdir -p $bin || die 'Error could not create the bin directory.'
	ln -sf $bblib/BashBurn.sh $bin/bashburn || die "Can not create symlink"
	echo -e "${green}[DONE]${coloff}"

	echo -en "Setting ownership..."
	(( $(id -u) == 0 )) && chown -R root:root $bblib
	echo -e "${green}[DONE]${coloff}"
	installation_finish
    fi
}

uninstall_info()
{
    printf "\nTo remove %bBashBurn%b from your system, just run
%bInstall.sh --uninstall%b
to delete these files:
%b%s%b  (symlink)\n%b%s%b  (directory).\n" \
	"${green}" "${coloff}" "$blue" "$coloff" "$blue" "$bin/bashburn" "$coloff" "$blue" "$lib" "$coloff"
}

uninstall_files()
{
    printf "\nRemoving %bBashBurn%b from your system..." "$blue" "$coloff"
    rm -rf $bin/bashburn $bblib $prefix/share/man/man1/bashburn.1.gz
    echo -e "${green}[DONE]${coloff}\n\n"
}

intro_banner()
{
   printf "%b
   (             )  (                  
 ( )\    )    ( /(( )\   (  (          
 )((_)( /( (  )\())((_) ))\ )(   (     
((_)_ )(_)))\((_)((_)_ /((_)()\  )\ )  
%b | _%b )(_)_((_)%b |(_) _%b )_))( ((_)_(_/(  
%b | _ \ _\` (_-< ' \| _ \ || | '_| ' \%b))%b 
 |___\__,_/__/_||_|___/\_,_|_| |_||_|  
                                       
%b" "$yellow" "$red" "$yellow" "$red" "$yellow" "$red" "$yellow" "$red" "$coloff"
} 

# Keep in spectrum order
typeset -r red="\e[1;31m"
typeset -r yellow="\e[1;33m"
typeset -r green="\e[1;32m"
typeset -r blue="\e[1;36m"
typeset -r coloff="\e[1;0m"	# Color off.

prog=$0
typeset -i uninstall=0
typeset -i help=0
typeset -i maketar=0
typeset -r defprefix=/usr

proc_opts "$@"
(( maketar && uninstall )) && usage '--make-tar is incompatible with --uninstall'
if (( maketar )) && [[ -z "$potprefix" ]]
then
    usage '--make-tar requires --prefix'
fi
(( help )) && usage
if (( uninstall ))
then
    echo -e "\nUninstall script for:"
else
    echo -e "\nInstallation script for:"
fi
intro_banner 
sleep 2
prefix=${potprefix:=${defprefix}}
[[ "${prefix:${#foo}-1:1}" == / ]] && prefix="${prefix:0:${#prefix}-1}"
printf "Directory prefix has been set to $blue $prefix $coloff\n"
bin=${prefix}/bin
lib=${prefix}/lib/Bashburn
bblib=${lib}/lib
bbpo=${lib}/po
if (( uninstall ))
then
    uninstall_files
else
    install_files
fi
exit 0