-
Notifications
You must be signed in to change notification settings - Fork 0
/
install
134 lines (124 loc) · 4.25 KB
/
install
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
#!/bin/sh
# Get filename of this script, with fallback
progname="$(basename "$0" || 'cttab-install')"
# Must be `firefox` or `librewolf`
browser="$1"
case "$browser" in
# Valid
firefox|librewolf) ;;
# Invalid - empty or unsupported browser
*)
echo 'please enter a supported browser name to install for'
if [ "$browser" ]; then
echo "'$browser' is not supported by this script"
fi
echo 'options: [ firefox | librewolf ]'
echo " EXAMPLE: $progname firefox <FILEPATH>"
echo 'or uninstall for a browser:'
echo " EXAMPLE: $progname firefox --uninstall"
exit 1
;;
esac
# Uninstall for a browser
if [ "$2" = '--uninstall' ] || [ "$1" = '--remove' ]; then
uninstall=1
else
# If this script is ran from cttab directory, `./index.html` is used
filepath="$2"
if [ ! "$filepath" ]; then
# Use relative filepath to current directory
filepath_rel="$(pwd)/index.html"
if [ -f "$filepath_rel" ]; then
filepath="$filepath_rel"
echo "NOTE: using $filepath_rel as filepath"
echo
else
# No filename given or could be inferred
echo "please enter the FULL filefilepath to the 'index.html' file"
echo " EXAMPLE: $progname <BROWSER> ~/Documents/cttab/index.html"
echo
echo "alternatively, run this script from inside your 'cttab' folder"
echo " EXAMPLE: cd ~/Documents/cttab && $progname <BROWSER>"
exit 2
fi
fi
# Replace `~` with full path to home directory
if [ "${filepath%"${filepath#?}"}" = "~" ]; then
filepath="$HOME${filepath#?}"
fi
# Check index file exists
if [ ! -f "$filepath" ]; then
echo "cannot find a file at '$filepath'"
echo 'please make sure that is the correct filepath'
echo "NOTE: do NOT include 'file:///' at the start of the path"
echo " EXAMPLE: $progname <BROWSER> ~/Documents/cttab/index.html"
exit 3
fi
# Add `file://` prefix to filename
# Note only 2 extra slashes are needed, as path is already absolute, starting at root
filepath_full="file://$filepath"
fi
# Path to create all files in
path="/usr/lib/$browser"
# Check path exists
if [ ! -d "$path" ]; then
echo "ERROR: cannot find $path"
echo 'maybe the selected browser is not installed on your system, or installed in a different directory?'
exit 4
fi
# Files to create
# autoconfig.cfg
path_1="$path/autoconfig.cfg"
file_1="// First line must be comment! Do not delete this line!
var {classes:Cc,interfaces:Ci,utils:Cu} = Components;
try { Cu.import(\"resource:///modules/AboutNewTab.jsm\");
var newTabURL = \"$filepath_full\";
AboutNewTab.newTabURL = newTabURL;
} catch(e){Cu.reportError(e);} // report errors in the Browser Console"
# defaults/pref/autoconfig.cfg
path_2="$path/defaults/pref/autoconfig.js"
file_2='// First line must be comment! Do not delete this line!
pref("general.config.filename", "autoconfig.cfg");
pref("general.config.obscure_value", 0);
pref("general.config.sandbox_enabled", false);'
action='create'
[ -n "$uninstall" ] && action='remove'
echo "NOTE: root access is required to $action 2 files:"
echo " $path_1"
echo " $path_2"
if [ -z "$uninstall" ]; then
# Create files
echo "$file_1" | sudo tee "$path_1" > /dev/null || {
echo "ERROR: cannot create file $path_1"
exit 5
}
echo "$file_2" | sudo tee "$path_2" > /dev/null || {
echo "ERROR: cannot create file $path_2"
exit 6
}
else
# Remove files
if [ ! -e "$path_1" ] && [ ! -e "$path_1" ]; then
echo
echo 'WARNING: no files to remove!'
exit 0
fi
if [ -e "$path_1" ]; then
sudo rm "$path_1" || {
echo "ERROR: cannot remove file $path_1"
exit 7
}
fi
if [ -e "$path_2" ]; then
sudo rm "$path_2" || {
echo "ERROR: cannot remove file $path_2"
exit 8
}
fi
fi
echo
echo 'All good!'
echo "NOTE: $browser needs to be restarted for changes to be applied"
echo "NOTE: to apply to new *windows* as well, change this setting:"
echo " about:preferences > Home > Homepage and new windows > Custom URLS"
echo " to: $filepath"