-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnew_app_setup.sh
executable file
·69 lines (58 loc) · 1.94 KB
/
new_app_setup.sh
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
#!/bin/bash
TARGET_COMPANY_NAME="gchristov"
TARGET_APP_PACKAGE="newsfeed"
TARGET_APP_CLASS_NAME="Newsfeed"
NEEDS_CLEANUP=0
# Needed for byte sequence error in ascii to utf conversion on OSX
export LC_CTYPE=C;
export LANG=C;
# Read required properties
read -p "Enter company name (spaces will be trimmed): " cn
read -p "Enter app name (spaces will be trimmed): " an
if [ -z "$cn" ] || [ -z "$an" ]; then
echo "Invalid input. Please enter app and company name."
exit 1
fi
companyName=$(echo $cn | tr -d '[:space:]' | tr '[:upper:]' '[:lower:]') # Trim and convert to lowercase
appPackageName=$(echo $an | tr -d '[:space:]' | tr '[:upper:]' '[:lower:]') # Trim and convert to lowercase
appClassName=$(echo $an | tr -d '[:space:]') # Trim
# Check if 'brew' tool is installed
if ! command -v brew &> /dev/null
then
echo "Homebrew not setup. Please follow instructions here to set it up"
echo "https://brew.sh"
exit 1
fi
# Check if 'rename' tool is installed
if ! command -v rename &> /dev/null
then
echo "Setting up environment. This may take a while..."
brew update -q
brew install rename -q
NEEDS_CLEANUP=1
echo "Setting up environment. Done"
fi
# Define replace function
function replace() {
# sed -i "" is needed by the osx version of sed (instead of sed -i)
find . -type f -exec sed -i "" "s|${1}|${2}|g" {} +
find . * | rename -f "s|${1}|${2}|" &> /dev/null
}
# Replace relevant items in the template
echo "Configuring company..."
replace $TARGET_COMPANY_NAME $companyName
echo "Configuring company. Done"
echo "Configuring app package..."
replace $TARGET_APP_PACKAGE $appPackageName
echo "Configuring app package. Done"
echo "Configuring app name..."
replace $TARGET_APP_CLASS_NAME $appClassName
echo "Configuring app name. Done"
# Cleanup in case the user didn't have the 'rename' tool installed previously
if NEEDS_CLEANUP==1
then
echo "Cleaning up..."
brew uninstall rename -q
echo "Cleaning up. Done"
fi
exit 0