|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +ENABLE=$1 |
| 4 | + |
| 5 | +set -x |
| 6 | + |
| 7 | +export DEBIAN_FRONTEND=noninteractive |
| 8 | +GLOBAL_MIME_FILE="/usr/share/applications/defaults.list" |
| 9 | +OKULAR_CONFIG_1="/home/.skjult/.config/okularpartrc" |
| 10 | +OKULAR_CONFIG_2="/home/.skjult/.local/share/kxmlgui5/okular/part.rc" |
| 11 | + |
| 12 | +cleanup_mime_file() { |
| 13 | + MIME_FILE=$1 |
| 14 | + |
| 15 | + sed --in-place "\@application/pdf@d" "$MIME_FILE" |
| 16 | + sed --in-place "\@application/x-bzpdf@d" "$MIME_FILE" |
| 17 | + sed --in-place "\@application/x-gzpdf@d" "$MIME_FILE" |
| 18 | + sed --in-place "\@application/x-xzpdf@d" "$MIME_FILE" |
| 19 | +} |
| 20 | + |
| 21 | +make_okular_default() { |
| 22 | + |
| 23 | + cleanup_mime_file $GLOBAL_MIME_FILE |
| 24 | + |
| 25 | + cat <<- EOF >> $GLOBAL_MIME_FILE |
| 26 | + application/pdf=okularApplication_kimgio.desktop; |
| 27 | + application/x-bzpdf=okularApplication_kimgio.desktop; |
| 28 | + application/x-gzpdf=okularApplication_kimgio.desktop; |
| 29 | + application/x-xzpdf=okularApplication_kimgio.desktop; |
| 30 | + EOF |
| 31 | +} |
| 32 | + |
| 33 | +apt-get update --assume-yes |
| 34 | + |
| 35 | +# Clean up from earlier versions of this script |
| 36 | +PREVIOUS_MIME_FILE="/home/.skjult/.config/mimeapps.list" |
| 37 | +cleanup_mime_file $PREVIOUS_MIME_FILE |
| 38 | + |
| 39 | +if [ "$ENABLE" = "True" ]; then |
| 40 | + |
| 41 | + apt-get remove --assume-yes evince # Unfortunately removing this alone does not mean Okular becomes default. Instead LibreOffice Draw becomes default. |
| 42 | + apt-get install --assume-yes okular |
| 43 | + |
| 44 | + make_okular_default |
| 45 | + |
| 46 | + cat <<- EOF > $OKULAR_CONFIG_1 |
| 47 | +
|
| 48 | + [General] |
| 49 | + ttsEngine=flite |
| 50 | +
|
| 51 | + [Reviews] |
| 52 | + AnnotationTools=<tool type="typewriter" id="1"><engine type="PickPoint" block="true"><annotation type="Typewriter" width="0" textColor="#ff000000" color="#00ffffff"/></engine><shortcut>1</shortcut></tool>,<tool type="note-linked" id="2"><engine type="PickPoint" hoverIcon="tool-note" color="#ffffff00"><annotation type="Text" color="#ffffff00" icon="Note"/></engine><shortcut>2</shortcut></tool>,<tool type="note-inline" id="3"><engine type="PickPoint" hoverIcon="tool-note-inline" color="#ffffff00" block="true"><annotation type="FreeText" color="#ffffff00"/></engine><shortcut>3</shortcut></tool>,<tool type="ink" id="4"><engine type="SmoothLine" color="#ff00ff00"><annotation type="Ink" width="2" color="#ff00ff00"/></engine><shortcut>4</shortcut></tool>,<tool type="highlight" id="5"><engine type="TextSelector" color="#ffffff00"><annotation type="Highlight" color="#ffffff00"/></engine><shortcut>5</shortcut></tool>,<tool type="straight-line" id="6"><engine type="PolyLine" color="#ffffe000" points="2"><annotation type="Line" width="1" color="#ffffe000"/></engine><shortcut>6</shortcut></tool>,<tool type="polygon" id="7"><engine type="PolyLine" color="#ff007eee" points="-1"><annotation type="Line" width="1" color="#ff007eee"/></engine><shortcut>7</shortcut></tool>,<tool type="stamp" id="8"><engine type="PickPoint" hoverIcon="okular" size="64" block="true"><annotation type="Stamp" icon="okular"/></engine><shortcut>8</shortcut></tool>,<tool type="underline" id="9"><engine type="TextSelector" color="#ff000000"><annotation type="Underline" color="#ff000000"/></engine><shortcut>9</shortcut></tool>,<tool type="ellipse" id="10"><engine type="PickPoint" color="#ff00ffff" block="true"><annotation type="GeomCircle" width="5" color="#ff00ffff"/></engine></tool> |
| 53 | +
|
| 54 | + EOF |
| 55 | + |
| 56 | + mkdir --parents "$(dirname $OKULAR_CONFIG_2)" |
| 57 | + |
| 58 | + cat <<- EOF > $OKULAR_CONFIG_2 |
| 59 | +
|
| 60 | + <!DOCTYPE kpartgui> |
| 61 | + <kpartgui name="okular_part" version="42"> |
| 62 | + <MenuBar> |
| 63 | + <Menu name="file" noMerge="1"> |
| 64 | + <text translationDomain="okular">&File</text> |
| 65 | + <Action name="get_new_stuff" group="file_open"/> |
| 66 | + <Action name="import_ps" group="file_open"/> |
| 67 | + <Action name="file_save" group="file_save"/> |
| 68 | + <Action name="file_save_as" group="file_save"/> |
| 69 | + <Action name="file_reload" group="file_save"/> |
| 70 | + <Action name="file_print" group="file_print"/> |
| 71 | + <Action name="file_print_preview" group="file_print"/> |
| 72 | + <Action name="open_containing_folder" group="file_print"/> |
| 73 | + <Action name="properties" group="file_print"/> |
| 74 | + <Action name="embedded_files" group="file_print"/> |
| 75 | + <Action name="file_export_as" group="file_print"/> |
| 76 | + <Action name="file_share" group="file_print"/> |
| 77 | + </Menu> |
| 78 | + <Menu name="edit" noMerge="1"> |
| 79 | + <text translationDomain="okular">&Edit</text> |
| 80 | + <Action name="edit_undo"/> |
| 81 | + <Action name="edit_redo"/> |
| 82 | + <Separator/> |
| 83 | + <Action name="edit_copy"/> |
| 84 | + <Separator/> |
| 85 | + <Action name="edit_select_all"/> |
| 86 | + <Action name="edit_select_all_current_page"/> |
| 87 | + <Separator/> |
| 88 | + <Action name="edit_find"/> |
| 89 | + <Action name="edit_find_next"/> |
| 90 | + <Action name="edit_find_prev"/> |
| 91 | + </Menu> |
| 92 | + <Menu name="view" noMerge="1"> |
| 93 | + <text translationDomain="okular">&View</text> |
| 94 | + <Action name="presentation"/> |
| 95 | + <Separator/> |
| 96 | + <Action name="view_zoom_in"/> |
| 97 | + <Action name="view_zoom_out"/> |
| 98 | + <Action name="view_actual_size"/> |
| 99 | + <Action name="view_fit_to_width"/> |
| 100 | + <Action name="view_fit_to_page"/> |
| 101 | + <Action name="view_auto_fit"/> |
| 102 | + <Separator/> |
| 103 | + <Action name="view_continuous"/> |
| 104 | + <Action name="view_render_mode"/> |
| 105 | + <Separator/> |
| 106 | + <Menu name="view_orientation" noMerge="1"> |
| 107 | + <text translationDomain="okular">&Orientation</text> |
| 108 | + <Action name="view_orientation_rotate_ccw"/> |
| 109 | + <Action name="view_orientation_rotate_cw"/> |
| 110 | + <Action name="view_orientation_original"/> |
| 111 | + </Menu> |
| 112 | + <Action name="view_pagesizes"/> |
| 113 | + <Action name="view_trim_mode"/> |
| 114 | + <Separator/> |
| 115 | + <Action name="view_toggle_forms"/> |
| 116 | + </Menu> |
| 117 | + <Menu name="go" noMerge="1"> |
| 118 | + <text translationDomain="okular">&Go</text> |
| 119 | + <Action name="go_previous"/> |
| 120 | + <Action name="go_next"/> |
| 121 | + <Separator/> |
| 122 | + <Action name="first_page"/> |
| 123 | + <Action name="last_page"/> |
| 124 | + <Separator/> |
| 125 | + <Action name="go_document_back"/> |
| 126 | + <Action name="go_document_forward"/> |
| 127 | + <Separator/> |
| 128 | + <Action name="go_goto_page"/> |
| 129 | + </Menu> |
| 130 | + <Menu name="bookmarks" noMerge="1"> |
| 131 | + <text translationDomain="okular">&Bookmarks</text> |
| 132 | + <Action name="bookmark_add"/> |
| 133 | + <Action name="rename_bookmark"/> |
| 134 | + <Action name="previous_bookmark"/> |
| 135 | + <Action name="next_bookmark"/> |
| 136 | + <Separator/> |
| 137 | + <ActionList name="bookmarks_currentdocument"/> |
| 138 | + </Menu> |
| 139 | + <Menu name="tools" noMerge="1"> |
| 140 | + <text translationDomain="okular">&Tools</text> |
| 141 | + <Action name="mouse_drag"/> |
| 142 | + <Action name="mouse_zoom"/> |
| 143 | + <Action name="mouse_select"/> |
| 144 | + <Action name="mouse_textselect"/> |
| 145 | + <Action name="mouse_tableselect"/> |
| 146 | + <Action name="mouse_magnifier"/> |
| 147 | + <Separator/> |
| 148 | + <Action name="mouse_toggle_annotate"/> |
| 149 | + <Separator/> |
| 150 | + <Action name="speak_document"/> |
| 151 | + <Action name="speak_current_page"/> |
| 152 | + <Action name="speak_stop_all"/> |
| 153 | + <Action name="speak_pause_resume"/> |
| 154 | + </Menu> |
| 155 | + <Menu name="settings" noMerge="1"> |
| 156 | + <text translationDomain="okular">&Settings</text> |
| 157 | + <Action name="show_leftpanel" group="show_merge"/> |
| 158 | + <Action name="show_bottombar" group="show_merge"/> |
| 159 | + <Action name="options_configure_generators" group="configure_merge"/> |
| 160 | + <Action name="options_configure" group="configure_merge"/> |
| 161 | + </Menu> |
| 162 | + <Menu name="help" noMerge="1"> |
| 163 | + <text translationDomain="okular">&Help</text> |
| 164 | + <Action name="help_about_backend" group="about_merge"/> |
| 165 | + </Menu> |
| 166 | + </MenuBar> |
| 167 | + <ToolBar name="mainToolBar" noMerge="1"> |
| 168 | + <text translationDomain="okular">Main Toolbar</text> |
| 169 | + <Action name="go_previous"/> |
| 170 | + <Action name="go_next"/> |
| 171 | + <Separator name="separator_0"/> |
| 172 | + <Action name="zoom_to"/> |
| 173 | + <Action name="view_zoom_out"/> |
| 174 | + <Action name="view_zoom_in"/> |
| 175 | + <Separator name="separator_1"/> |
| 176 | + <Action name="mouse_drag"/> |
| 177 | + <Action name="mouse_zoom"/> |
| 178 | + <Action name="mouse_selecttools"/> |
| 179 | + <Action name="mouse_toggle_annotate"/> |
| 180 | + </ToolBar> |
| 181 | + <ActionProperties scheme="Default"> |
| 182 | + <Action name="mouse_toggle_annotate" iconText="Indsæt tekst"/> |
| 183 | + </ActionProperties> |
| 184 | + </kpartgui> |
| 185 | + EOF |
| 186 | +else |
| 187 | + apt-get remove --assume-yes okular |
| 188 | + apt-get install --assume-yes evince # Hopefully this means evince is automatically set as the default reader for its types, so we don't have to handle that manually |
| 189 | + rm --force $OKULAR_CONFIG_1 $OKULAR_CONFIG_2 |
| 190 | +fi |
0 commit comments