-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprepScript.sh
More file actions
executable file
·60 lines (50 loc) · 1.84 KB
/
prepScript.sh
File metadata and controls
executable file
·60 lines (50 loc) · 1.84 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
#!/usr/bin/env bash
# shellcheck disable=SC2129
set -o errexit
set -o nounset
set -o pipefail
if [[ "${TRACE-0}" == "1" ]]; then set -o xtrace; fi
###SOF###
# Use this script to combine multiple scripts into one script for deploying to a remote machine or management system like Workspace ONE UEM
# Directions:
# create an array of files to combine
# example: files=("bashFunctionLibrary.sh" "bashFunctionLibrary.sh")
# decide on a destination file name
# example: destination="fullScript.sh"
# run the script
# example: ./prepScript.sh "${files[@]}" "$destination"
# Notice how you must use the "${files[@]}" syntax to pass the array to the script
# take lines from the sfiles starting at ###SOF### and ending at ###EOF### and add them to the dfile
# if the dfile does not exist it will be created
# if the dfile does exist it will be overwritten
# note - do not include teh shebang line in the source files since it will be added to the destination file automatically
# $1 - source files array
# $2 - destination file
sfiles=("$@")
dfile=${sfiles[${#sfiles[@]}-1]}
rm -f "$dfile"
copyLines() {
# get the lines from the source file
lines=$(sed -n '/###SOF###/,/###EOF###/p' "$1")
# if the destination file does not exist create it
if [ ! -f "$2" ]; then
echo '#!/bin/bash' > "$2"
echo 'set -o errexit' >> "$2"
echo 'set -o nounset' >> "$2"
echo 'set -o pipefail' >> "$2"
echo 'if [[ "${TRACE-0}" == "1" ]]; then set -o xtrace; fi' >> "$2"
echo "$lines" >> "$2"
else # the destination file does exist and copy the lines at the end of the file
echo "" >> "$2"
echo "$lines" >> "$2"
fi
}
for ifile in "${sfiles[@]}"; do
echo "copying lines from $ifile to $dfile"
if [ "$ifile" == "$dfile" ]; then
continue
else
copyLines "$ifile" "$dfile"
fi
done
###EOF###