OSDN Git Service

[update] : browser background
[alterlinux/fascode-live-tools.git] / alterlinux-welcome-page / alterlinux-welcome-page
1 #!/usr/bin/env bash
2 # Yamada Hayao
3 # Twitter: @Hayao0819
4 # Email  : hayao@fascode.net
5 #
6 # (c) 2019-2020 Fascode Network.
7 #
8
9 set -e
10
11 checklive=false
12 alterlive=false
13 url="https://fascode.net/projects/linux/alter/alter-welcome.php"
14 browser="chromium --start-maximized --app=%s"
15 custombrowser=false
16
17 defaultbrowserlist=(
18     "firefox %s"
19     "chromium --start-maximized --app=%s"
20     "google-chrome  --start-maximized --app=%s"
21 )
22
23 remove () {
24     local _list
25     local _file
26     _list=($(echo "$@"))
27     for _file in "${_list[@]}"; do
28         if [[ -f ${_file} ]]; then
29             rm -f "${_file}"
30         elif [[ -d ${_file} ]]; then
31             rm -rf "${_file}"
32         fi
33     done
34 }
35
36 _help() {
37     echo "Displays the AlterLinux welcome page"
38     echo "usage alterlinux-welcome-page [options]"
39     echo
40     echo " General options:"
41     echo "    -b | --browser <cmd>  Specify the browser command."
42     echo "                          %s will be replaced with the URL"
43     echo "                          Default: ${browser}"
44     echo "    -u | --url <url>      Set the URL."
45     echo "                          Default: ${url}"
46     echo
47     echo "    -l | --live           Opens the page only in a live environment."
48     echo "    -h | --help           This help message and exit."
49 }
50
51 _msg_error() {
52     echo "${@}" >&2
53 }
54
55
56 # Argument analysis and processing
57 options="${@}"
58 _opt_short="b:u:lh"
59 _opt_long="browser:,url:,live,help,alterlive,aobuta"
60 OPT=$(getopt -o ${_opt_short} -l ${_opt_long} -- "${@}")
61 if [[ ${?} != 0 ]]; then
62     exit 1
63 fi
64
65 eval set -- "${OPT}"
66 unset OPT
67 unset _opt_short
68 unset _opt_long
69
70 while true; do
71     case ${1} in
72         -b | --browser)
73             browser="${2}"
74             custombrowser=true
75             shift 2
76             ;;
77         -l | --live)
78             checklive=true
79             shift 1
80             ;;
81         -u | --url)
82             url="${2}"
83             shift 2
84             ;;
85         -h | --help)
86             _help
87             shift 1
88             exit 0
89             ;;
90         --aobuta)
91             url="https://ao-buta.com/"
92             shift 1
93             ;;
94         --alterlive)
95             alterlive=true
96             shift 1
97             ;;
98         --)
99             shift
100             break
101             ;;
102         *)
103             _msg_error "Invalid argument '${1}'"
104             _help
105             exit 1
106             ;;
107     esac
108 done
109
110 if [[ "${checklive}" = true ]]; then
111     if [[ -n $(pacman -Q alterlinux-calamares) ]]; then
112         exit 0
113     fi
114 fi
115
116 if [[ "${custombrowser}" = false ]]; then
117     defaultbrowserlist+=("END_OF_LIST")
118     for ((_browser_count = 0; _browser_count < ${#defaultbrowserlist[@]}; _browser_count++)); do
119         _browser="${defaultbrowserlist[${_browser_count}]}"
120         if [[ -f $(type -P "$(echo ${_browser} | awk '{print $1}')") ]]; then
121             browser="${_browser}"
122             break
123         elif [[ "${_browser}" == "END_OF_LIST" ]]; then
124             _msg_error "No available browser is installed."
125             exit 1
126         fi
127     done
128 fi
129
130 eval $(printf "${browser}" "${url}") &
131
132 if [[ "${alterlive}" = true ]]; then
133     remove ~/.config/autostart/welcome_page.desktop
134 fi