Selaa lähdekoodia

Customize searx background

Bob Mottram 8 vuotta sitten
vanhempi
commit
079e370def
1 muutettua tiedostoa jossa 108 lisäystä ja 2 poistoa
  1. 108
    2
      src/freedombone-app-searx

+ 108
- 2
src/freedombone-app-searx Näytä tiedosto

@@ -40,12 +40,14 @@ SEARX_ONION_PORT=8094
40 40
 SEARX_ONION_HOSTNAME=
41 41
 SEARX_LOGIN_TEXT=$"Search engine login"
42 42
 SEARX_PASSWORD=
43
+SEARX_BACKGROUND_IMAGE_URL=
43 44
 
44 45
 searx_variables=(SEARX_REPO
45 46
                  SEARX_COMMIT
46 47
                  SEARX_PATH
47 48
                  SEARX_LOGIN_TEXT
48 49
                  MY_USERNAME
50
+                 SEARX_BACKGROUND_IMAGE_URL
49 51
                  SYSTEM_TYPE)
50 52
 
51 53
 function searx_set_default_background {
@@ -60,6 +62,102 @@ function searx_set_default_background {
60 62
     fi
61 63
 }
62 64
 
65
+function searx_set_background_image_from_url {
66
+    url="$1"
67
+
68
+    ext=
69
+    if [ ${#url} -gt 0 ]; then
70
+        if [[ "$url" == *".jpeg" || "$url" == *".jpg" ]]; then
71
+            ext="jpg"
72
+        fi
73
+        if [[ "$url" == *".png" ]]; then
74
+            ext="png"
75
+        fi
76
+        if [[ "$url" == *".gif" ]]; then
77
+            ext="gif"
78
+        fi
79
+    fi
80
+
81
+    if [ ${#ext} -gt 0 ]; then
82
+        if [ -d /etc/searx/searx/static/themes/courgette/img ]; then
83
+            cd /etc/searx/searx/static/themes/courgette/img
84
+
85
+
86
+            # remove any existing image
87
+            if [ -f bg-body-index.jpg ]; then
88
+                rm bg-body-index.jpg
89
+            fi
90
+
91
+            # get the new image
92
+            if [[ "$ext" != 'jpg' ]]; then
93
+                if [ -f bg-body-index.${ext} ]; then
94
+                    rm bg-body-index.${ext}
95
+                fi
96
+                wget "$url" -O bg-body-index.${ext}
97
+                convert bg-body-index.${ext} bg-body-index.jpg
98
+            else
99
+                wget "$url" -O bg-body-index.jpg
100
+            fi
101
+            if [ ! -f bg-body-index.jpg ]; then
102
+                echo "$url"
103
+                echo $'Custom background image for SearX could not be downloaded'
104
+                echo "1"
105
+                return
106
+            fi
107
+            chown -R searx:searx ${SEARX_PATH}/searx
108
+        fi
109
+    else
110
+        echo "2"
111
+        return
112
+    fi
113
+
114
+    echo "0"
115
+}
116
+
117
+function searx_set_background_image {
118
+    data=$(tempfile 2>/dev/null)
119
+    trap "rm -f $data" 0 1 2 5 15
120
+    dialog --title $"SearX Metasearch" \
121
+           --backtitle $"Freedombone Control Panel" \
122
+           --inputbox $'Set a background image URL' 10 60 2>$data
123
+    sel=$?
124
+    case $sel in
125
+        0)
126
+            temp_background=$(<$data)
127
+            if [ ${#temp_background} -gt 0 ]; then
128
+                SEARX_BACKGROUND_IMAGE_URL="$temp_background"
129
+                write_config_param "SEARX_BACKGROUND_IMAGE_URL" "$SEARX_BACKGROUND_IMAGE_URL"
130
+                if [[ $(searx_set_background_image_from_url "$SEARX_BACKGROUND_IMAGE_URL" | tail -n 1) == "0" ]]; then
131
+                    dialog --title $"Set SearX background" \
132
+                           --msgbox $"The background image has been set" 6 60
133
+                fi
134
+            fi
135
+           ;;
136
+    esac
137
+}
138
+
139
+function configure_interactive_searx {
140
+    while true
141
+    do
142
+        data=$(tempfile 2>/dev/null)
143
+        trap "rm -f $data" 0 1 2 5 15
144
+        dialog --backtitle $"Freedombone Control Panel" \
145
+               --title $"SearX Metasearch" \
146
+               --radiolist $"Choose an operation:" 11 70 2 \
147
+               1 $"Set a background image" off \
148
+               2 $"Exit" on 2> $data
149
+        sel=$?
150
+        case $sel in
151
+            1) return;;
152
+            255) return;;
153
+        esac
154
+        case $(cat $data) in
155
+            1) searx_set_background_image;;
156
+            2) break;;
157
+        esac
158
+    done
159
+}
160
+
63 161
 function remove_user_searx {
64 162
     remove_username="$1"
65 163
 
@@ -625,8 +723,16 @@ function create_searx_config {
625 723
 }
626 724
 
627 725
 function upgrade_searx {
726
+    background_image=/etc/searx/searx/static/themes/courgette/img/bg-body-index.jpg
727
+    if [ -f ${background_image} ]; then
728
+        cp ${background_image} ${background_image}.prev
729
+    fi
730
+
628 731
     set_repo_commit $SEARX_PATH/searx "searx commit" "$SEARX_COMMIT" $SEARX_REPO
629
-    searx_set_default_background
732
+    if [ -f ${background_image}.prev ]; then
733
+        cp ${background_image}.prev ${background_image}
734
+        chown -R searx:searx ${SEARX_PATH}/searx
735
+    fi
630 736
 }
631 737
 
632 738
 function backup_local_searx {
@@ -672,7 +778,7 @@ function install_searx {
672 778
     fi
673 779
 
674 780
     apt-get -yq install python-pip libyaml-dev python-werkzeug python-babel python-lxml apache2-utils
675
-    apt-get -yq install git build-essential libxslt-dev python-dev python-virtualenv python-pybabel zlib1g-dev uwsgi uwsgi-plugin-python libapache2-mod-uwsgi
781
+    apt-get -yq install git build-essential libxslt-dev python-dev python-virtualenv python-pybabel zlib1g-dev uwsgi uwsgi-plugin-python libapache2-mod-uwsgi imagemagick
676 782
 
677 783
     pip install --upgrade pip
678 784