|
1 | 1 | #!/bin/bash |
2 | | -# prefer running as root |
3 | | -DIR=$(dirname $0) |
4 | | -PROGRAM=/usr/local/bin/comfortable-swipe |
5 | | -COMPILE=$DIR/comfortable-swipe.compile.sh |
6 | | -CONF_PATH=/usr/local/share/comfortable-swipe/comfortable-swipe.conf |
7 | | -DCONF_PATH=$DIR/defaults.conf |
8 | | -OLD_CONF_PATH=${XDG_CONFIG_HOME:-$HOME/.config}/comfortable-swipe.conf |
9 | 2 |
|
10 | | -if [ -x "$(command -v $PROGRAM)" ]; then |
11 | | - # stop any running comfortable-swipe if it exists |
12 | | - $PROGRAM stop |
13 | | -fi |
| 3 | +function install { |
| 4 | + # prefer running as root |
| 5 | + local dir="$(dirname $0)" |
| 6 | + local program=comfortable-swipe |
| 7 | + local program_exe=/usr/local/bin/$program |
| 8 | + local compile_command="$dir/$program.compile.sh" |
| 9 | + local conf_path=/usr/local/share/$program/$program.conf |
| 10 | + local dconf_path="$dir/defaults.conf" |
| 11 | + local old_conf_path="${XDG_CONFIG_HOME:-$HOME/.config}/$program.conf" |
14 | 12 |
|
15 | | -#copy config file |
16 | | -abort () { |
17 | | - exec echo "Installation aborted" |
18 | | -} |
19 | | -sudo mkdir -p $(dirname $CONF_PATH) || abort |
| 13 | + if [ -x "$(command -v $program_exe)" ]; then |
| 14 | + # stop any running $program if it exists |
| 15 | + $program_exe stop |
| 16 | + fi |
| 17 | + |
| 18 | + #copy config file |
| 19 | + abort () { |
| 20 | + exec echo "Installation aborted" |
| 21 | + } |
| 22 | + sudo mkdir -p "$(dirname $conf_path)" || abort |
20 | 23 |
|
21 | | -# check if "-y" or "--yes" is passed as an argument |
22 | | -YES=false |
23 | | -while test $# -gt 0 |
24 | | -do |
25 | | - case "$1" in |
26 | | - -y) YES=true |
27 | | - ;; |
28 | | - --yes) YES=true |
29 | | - ;; |
30 | | - esac |
31 | | - shift |
32 | | -done |
| 24 | + # check if "-y" or "--yes" is passed as an argument |
| 25 | + YES=false |
| 26 | + while test $# -gt 0 |
| 27 | + do |
| 28 | + case "$1" in |
| 29 | + -y) YES=true |
| 30 | + ;; |
| 31 | + --yes) YES=true |
| 32 | + ;; |
| 33 | + esac |
| 34 | + shift |
| 35 | + done |
33 | 36 |
|
34 | | -sudo chown $USER $(dirname $CONF_PATH) |
35 | | -if [ ! -f $CONF_PATH ]; then |
36 | | - if [ ! -f $OLD_CONF_PATH ]; then |
37 | | - # old config file not found, create from scratch |
38 | | - cat $DCONF_PATH > $CONF_PATH || abort |
| 37 | + sudo chown $USER "$(dirname $conf_path)" |
| 38 | + if [ ! -f "$conf_path" ]; then |
| 39 | + if [ ! -f "$old_conf_path" ]; then |
| 40 | + # old config file not found, create from scratch |
| 41 | + cat "$dconf_path" > "$conf_path" || abort |
| 42 | + else |
| 43 | + # old config file found, move to the new path |
| 44 | + cat "$old_conf_path" > "$conf_path" || abort |
| 45 | + echo "Configuration copied from $old_conf_path to $conf_path" |
| 46 | + fi |
39 | 47 | else |
40 | | - # old config file found, move to the new path |
41 | | - cat $OLD_CONF_PATH > $CONF_PATH || abort |
42 | | - echo "Configuration copied from $OLD_CONF_PATH to $CONF_PATH" |
43 | | - fi |
44 | | -else |
45 | | - # config file found, ask user if overwrite |
46 | | - echo "Old conf file found in $CONF_PATH" |
47 | | - if [ $YES == false ]; then |
48 | | - read -r -p "Keep the old conf file? (default: yes) [Y/n] " response |
49 | | - response=${response,,} # tolower |
50 | | - if [[ "$response" =~ ^(no|n)$ ]]; then |
51 | | - read -r -p "Conf file will be overwritten. Are you sure? [Y/n] " response |
52 | | - response=${response,,} |
53 | | - if [[ "$response" =~ ^(yes|y)$ ]]; then |
54 | | - cat $DCONF_PATH > $CONF_PATH || abort |
55 | | - else |
56 | | - abort |
| 48 | + # config file found, ask user if overwrite |
| 49 | + echo "Old conf file found in $conf_path" |
| 50 | + if [ "$YES" == false ]; then |
| 51 | + read -r -p "Keep the old conf file? (default: yes) [Y/n] " response |
| 52 | + response="${response,,}" # tolower |
| 53 | + if [[ "$response" =~ ^(no|n)$ ]]; then |
| 54 | + read -r -p "Conf file will be overwritten. Are you sure? [Y/n] " response |
| 55 | + response="${response,,}" |
| 56 | + if [[ "$response" =~ ^(yes|y)$ ]]; then |
| 57 | + cat "$dconf_path" > "$conf_path" || abort |
| 58 | + else |
| 59 | + abort |
| 60 | + fi |
57 | 61 | fi |
58 | 62 | fi |
59 | 63 | fi |
60 | | -fi |
61 | 64 |
|
62 | | -echo "Installing..." |
| 65 | + echo "Installing to $program_exe ..." |
63 | 66 |
|
64 | | -# remove existing comfortable-swipe |
65 | | -if [ -x "$(command -v $PROGRAM)" ]; then |
66 | | - sudo rm -f $(which comfortable-swipe) |
67 | | -fi |
| 67 | + # remove existing $program |
| 68 | + if [ -x "$(command -v $program_exe)" ]; then |
| 69 | + sudo rm -f "$(which $program)" |
| 70 | + fi |
| 71 | + |
| 72 | + # compile library |
| 73 | + sudo "$compile_command" "$program_exe" || abort |
68 | 74 |
|
69 | | -# compile library |
70 | | -sudo $COMPILE $PROGRAM || abort |
| 75 | + # add permissions to input group (defer) |
| 76 | + # GROUP=$(ls -l /dev/input/event* | awk '{print $4}' | head --line=1) || abort |
71 | 77 |
|
72 | | -# add permissions to input group (defer) |
73 | | -# GROUP=$(ls -l /dev/input/event* | awk '{print $4}' | head --line=1) || abort |
| 78 | + # turn on autostart by default |
| 79 | + local autostart_status="$($program_exe autostart)" |
| 80 | + if [[ "$autostart_status" == *off* ]]; then |
| 81 | + autostart_status="$($program_exe autostart)" |
| 82 | + fi |
74 | 83 |
|
75 | | -# toggle autostart twice to refresh any changes |
76 | | -$PROGRAM autostart > /dev/null || abort |
77 | | -$PROGRAM autostart > /dev/null || abort |
| 84 | + echo "Successfully installed $program $(cat $dir/VERSION | tr -d '[:space:]')" |
| 85 | + echo "" |
| 86 | + echo "$autostart_status" |
| 87 | + echo "Edit configuration file: gedit \$($program config)" |
| 88 | + echo "" |
| 89 | + echo "Try running: $program start" |
| 90 | +} |
78 | 91 |
|
79 | | -echo "Successfully installed comfortable-swipe." |
80 | | -echo "Configuration file is located at $CONF_PATH" |
81 | | -echo "" |
82 | | -echo "Try running 'comfortable-swipe start' to test." |
| 92 | +install |
| 93 | +unset -f install |
0 commit comments