~hristoast/mousikofidi

ref: ae0e0d325a28434f7994ecab1020d1f89ffa05b9 mousikofidi/example/mousikofidi-client -rwxr-xr-x 3.0 KiB View raw
ae0e0d32Hristos N. Triantafillou Added an executable for a 'client' 10 months ago
                                                                                
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
#!/bin/bash

Help() {
    cat << EOF
usage: mousikofidi-client [-h] [-u URL] [-n] [optional browser flag]

Run a web browser in incognito or private mode pointed at the
MousikóFídi instance of your choosing.

optional arguments:
  -h, --help            show this help message and exit

Options:
  --chrome              Open a MousikóFídi with Chrome.

  --chromium            Open a MousikóFídi with Chromium.
                        This is the default.

  --firefox             Open a MousikóFídi with Firefox.

  --icecat              Open a MousikóFídi with IceCat.

  -o BROWSER            Name of a web browser executable to use.
  --other BROWSER

  -u URL,               The address of the MousikóFídi instance to be opened.
  --instance-url URL    Default: mousikofidi.info

  -n, --no-private      Don't use an incognito or private browser session.
EOF
}

export browser=chromium
export instanceURL=${FIDI_URL:-mousikofidi.info}
export other=false
export private=true

opts=$(getopt -l "help,chrome,chromium,firefox,icecat,instance-url:,no-private,other:" -o "no:u:" -a -- "$@")

eval set -- "$opts"

while true
do
    case $1 in
        -h|--help)
            Help
            exit 0
            ;;
        --chrome)
            export browser=chrome
            ;;
        --chromium)
            export browser=chromium
            ;;
        --firefox)
            export browser=firefox
            ;;
        --icecat)
            export browser=icecat
            ;;
        --other)
            shift
            export browser=$1
            export other=true
            ;;
        -u|--instance-url)
            shift
            export instanceURL=$1
            ;;
        -p|--private)
            export private=true
            ;;
        --)
            shift
            break;;
    esac
    shift
done

if [ "${browser}" = "chrome" ]; then
    if [ "${private}" = "true" ]; then
        chrome --incognito "${instanceURL}" 2>/dev/null >/dev/null
    else
        chrome "${instanceURL}" 2>/dev/null >/dev/null
    fi

elif [ "${browser}" = "chromium" ]; then
    if [ "${private}" = "true" ]; then
        chromium --incognito "${instanceURL}" 2>/dev/null >/dev/null
    else
        chromium "${instanceURL}" 2>/dev/null >/dev/null
    fi

elif [ "${browser}" = "firefox" ]; then
    if [ "${private}" = "true" ]; then
        firefox --private-window "${instanceURL}" 2>/dev/null >/dev/null
    else
        firefox "${instanceURL}" 2>/dev/null >/dev/null
    fi

elif [ "${browser}" = "icecat" ]; then
    if [ "${private}" = "true" ]; then
        icecat --private-window "${instanceURL}" 2>/dev/null >/dev/null
    else
        icecat "${instanceURL}" 2>/dev/null >/dev/null
    fi

elif [ "${other}" = "true" ]; then
    eval "${browser}" "${instanceURL}" 2>/dev/null >/dev/null || echo [ERROR]: The given browser \""${browser}"\" failed!

else
    if [ "${private}" = "true" ]; then
        chromium --incognito "${instanceURL}" 2>/dev/null >/dev/null
    else
        chromium "${instanceURL}" 2>/dev/null >/dev/null
    fi

fi