├── MiSTer_misc_update.sh ├── README.md └── MiSTer_misc.sh /MiSTer_misc_update.sh: -------------------------------------------------------------------------------- 1 | 2 | #!/usr/bin/env bash 3 | 4 | # This file was generated by './MiSTer_misc.sh show_shortcut' 5 | 6 | 7 | # Test internet 8 | ping -c 1 www.google.com > /dev/null 9 | if [ "$?" != "0" ]; then 10 | echo "Network not found: check your internet connection or try later" 11 | exit 126 12 | fi 13 | 14 | # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv 15 | # You can simply run the following command instead of running this file 16 | # 17 | curl -L -k "https://raw.githubusercontent.com/pocomane/MiSTer_misc/master/MiSTer_misc.sh" | bash -s update 18 | # 19 | # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 20 | 21 | X=("${PIPESTATUS[@]}") 22 | EXIT_CODE=${X[0]} 23 | if [ "$EXIT_CODE" = "0" ]; then 24 | EXIT_CODE=${X[1]} 25 | fi 26 | if [ "$EXIT_CODE" != "0" ]; then 27 | echo "Error downloading the package ($EXIT_CODE)" 28 | fi 29 | 30 | read -n 1 -s -r -p "Press any key to continue" 31 | echo "" 32 | exit $EXIT_CODE 33 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # MiSTer_misc 3 | 4 | This is a script to install and update miscellaneous software on a target device. 5 | The default distribution is meant to be used on a MiSTer FPGA, however it is 6 | designed to be easly adapted to other systems. Read the dedicated section to more 7 | information on such scenarios, the rest of this documentation will assume a 8 | MiSTer FPGA target with default miscellaneous software. 9 | 10 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 11 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 12 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 13 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 14 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 15 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 16 | SOFTWARE. 17 | 18 | # Features 19 | 20 | The features of the script are: 21 | 22 | - It is very simple: you can read and fully understand it in minutes 23 | - The packages are distributed as github repository 24 | - It automatically creates links and wrapper scripts to recall package functionality 25 | - It keeps the filesystem clean: all the software is installed the `/media/fat/misc` folder 26 | - TODO : automatic boot script ! ? 27 | 28 | # Installation 29 | 30 | To install or update all the software, you can download the 31 | [MiSTer_misc_update.sh](https://raw.githubusercontent.com/pocomane/MiSTer_misc/master/MiSTer_misc_update.sh) 32 | to your device and run it. Alternatively you can run 33 | 34 | ``` 35 | curl -L -k "https://raw.githubusercontent.com/pocomane/MiSTer_misc/master/MiSTer_misc.sh" | bash -s update 36 | ``` 37 | 38 | in a shell on the target device. 39 | 40 | Both the methods will download the last script from the repo and install it in the 41 | default path: `/media/fat/misc/MiSTer_misc`. It will also generate some script 42 | in the default path: `/media/fat/Scripts`. One of this is the updater script 43 | itself: `/media/fat/Scripts/MiSTer_misc_update.sh`. 44 | 45 | # Contained software 46 | 47 | This is a list of the software that will be installed. 48 | 49 | - [webkeyboard](https://github.com/pocomane/webkeyboard) - It let you to 50 | control the device from a remote keyboard. The scripts 51 | `webkeyboard_start.sh` and `webkeyboard_stop.sh` will be created to launch 52 | and stop the service. Connect http://ip.addes.of_the.device:8081 from any 53 | computer in the network to send keystroks through the web. 54 | - [webmenu with wrapper](https://github.com/pocomane/MiSTer_webmenu_package) - It 55 | is a GUI served as a web-page. Connecting a browser from any computer to it, you 56 | can launch core and roms, search your collection, etc. The script 57 | `webmenu_start.sh` and `webmenu_stop.sh` will be created to start/stop the 58 | app. 59 | - [mbc](https://github.com/pocomane/MiSTer_Batch_Control) - It is an utility to 60 | control the MiSTer from the command line (e.g. launch a rom). 61 | 62 | # How it works 63 | 64 | The script is very simple. It just download a list of software from the github 65 | repos (defined by the owner and its name) into an `Installation` directory. In 66 | case there is already something in such directory, it first remove it, so it 67 | always got the latest revision. Each package will be placed in the sub-folder of 68 | the `Installation` one with the same name of the package. 69 | 70 | The list of packages to download, with their `repo_type` and `package_name` can 71 | be quickly changed in the script, as described in the following sections. The 72 | `repo_type` defines how download the software from it. 73 | 74 | For each installed software, some functionality script are linked in the 75 | `Scripts` and `Links` directories to be easly recalled. The difference between 76 | the two directories is that the `Links` will contain proper links, while the 77 | `Scripts` one will contain wrapper script that perform some auxiliary work ( 78 | change the current dir, and wait a keypress at the end). Note, by default, 79 | `Scripts` and `Links` directories are the same, so you get a single directory 80 | with a mix of wrappers and links. 81 | 82 | TODO : implement automatic boot script ! ? 83 | 84 | # Adapt the script to other devices 85 | 86 | To adapt the script to other device and software, you can fork this repo, and 87 | change the following variables in the main script 88 | 89 | - PACKAGE_UPDATER_OWNER and NAME define the github repo of the owner of the 90 | uptade script itself; you should place here you github username (in OWNER) 91 | and forked repo name (in NAME); 92 | - MISC_DIR defines the `Installation` directory, where the software will be 93 | copied; 94 | - SCRIPT_DIR defines the path for the `Scripts` folder; an empty value will 95 | disable the creation of the script wrappers; 96 | - LINK_DIR defines the path for the `Links` folder; an empty value will disable 97 | the creation of the links; 98 | 99 | You can also change the following variables for some advanced configuration 100 | (some of them tweaks the package specification, so refer to the relative 101 | section for more details): 102 | 103 | - PACKAGE_UPDATER_TYPE is the type of repo containing the updater script itself; 104 | (the default "github.master" should be good for most of the scenarios, see next 105 | section for other options): 106 | - EXPOSE_HOOK specifies which subfolder in a package contains the scripts to be 107 | place in the `Links` folder; 108 | - ACTION_HOOK specifies which subfolder in a package contains the scripts to be 109 | wrapped in `Scripts` directory; 110 | - BOOT_HOOK si not implemented yet ! ? ; 111 | - QUICK_HOOK_NAME contains the name of the script that will be linked with the 112 | same name of the package (default is `__unnamed__`, wihout any extension) 113 | 114 | After that you have to find the package list definition function: just search 115 | for `PACKAGE LIST` to find it. You have to clean-up the function and refill it 116 | with the list of the packages you want to include. The exact syntax is defined 117 | in the next section, in general each package must correspond to a github repo. 118 | 119 | Finally you can regenerate the shortcut script with 120 | 121 | ``` 122 | ./MiSTer_misc.sh show_shortcut > MiSTer_misc_update.sh 123 | ``` 124 | 125 | Obviously you can rename the scripts as you wish. 126 | 127 | # Package Specification 128 | 129 | As said in the previous sections, in the script there is a list of package to 130 | install. Each line define one package. The general sintax is: 131 | 132 | ``` 133 | us_package_do "$1" github_user github_repo opt_pattern repo_type package_name 134 | ``` 135 | 136 | The first two terms must be always the same. Then there is the user name of 137 | the owner of the github repo containing the software, and the repo name. If any 138 | of the other options is dot (.) or it is missing, a default value is used. 139 | 140 | The `package_name` is the name you want to use to refer to the software (e.g. 141 | for naming the package directory); as default it the same string passed as 142 | `github_repo`. The `opt_pattern` define a regex pattern used for some repo 143 | types (details in following) and they have; its default is `github_repo` too. 144 | 145 | Each package will be installed in its `Target` directory, i.e. the 146 | `package_name` subfolder of the `Installation` directory. What is placed inside 147 | such directory depends on the value of `repo_type` (which default is "gz.tar"): 148 | 149 | - "github.master" - the target repo is simply cloned inside the `Target` 150 | directory; the `.git` auxiliary folder is removed (note: `opt_pattern` is 151 | ignored); the master branch is checked-out; 152 | 153 | - "bare" - it looks in the last github release page for the first file matching 154 | the `opt_pattern`; it is downloaded in the `Target` directory; 155 | 156 | - "uudecode.xz", or "gz.tar", or "tar" - it behaves like the "bare" package, 157 | but the file is decompressed according to the desired algorithm (uuencode, 158 | gz, etc); 159 | 160 | Once the software is installed, some sub-folder are treated in the followng 161 | special way: 162 | 163 | - hook/action - all the script in this subfolder are linked in the `Scripts` 164 | folder, to be quickly searched and launched; the content of the `package_name` is 165 | used as prefix for the target name, so, for example, if two packages `pkg_a` 166 | and `pkg_b` provide a `start.sh` script, in the desired subfolder you will 167 | fined two files `pkg_a_start.sh`, `pkg_b_start.sh`; the `__unnamed__` script 168 | is a special case since it will be linked in `pkg_a` or `pkg_b` without any 169 | suffix; 170 | 171 | - hook/boot - it is currently ignored (to be implemented yet ! ? ) 172 | 173 | -------------------------------------------------------------------------------- /MiSTer_misc.sh: -------------------------------------------------------------------------------- 1 | #/usr/bin/env bash 2 | 3 | MISC_DIR="/media/fat/misc" 4 | LINK_DIR="/media/fat/Scripts" 5 | SCRIPT_DIR="/media/fat/Scripts" 6 | PACKAGE_UPDATER_OWNER="pocomane" 7 | PACKAGE_UPDATER_NAME="MiSTer_misc" 8 | PACKAGE_UPDATER_TYPE="github.master" 9 | ACTION_HOOK="hook/action" 10 | EXPOSE_HOOK="hook/expose" 11 | BOOT_HOOK="hook/boot" 12 | QUICK_HOOK_NAME="__unnamed__" 13 | 14 | # DEBUG="true" 15 | # DEBUG_MISC_SUB="/media/data/temp/MiSTer_misc_test/misc" 16 | # DEBUG_LINK_DIR="/media/data/temp/MiSTer_misc_test/Scripts" 17 | # DEBUG_SCRIPT_DIR="/media/data/temp/MiSTer_misc_test/Scripts" 18 | 19 | # --------------------------------------------------------------------------------- 20 | 21 | TMPFILE="./.download.tmp" 22 | CURL=" curl -L -k " 23 | # TAR=" tar --no-same-owner --no-same-permissions " 24 | TAR=" tar --no-same-owner " 25 | UNZIP=" unzip " 26 | 27 | die(){ 28 | echo "ERROR $1" 29 | exit 127 30 | } 31 | 32 | # All the function use the following suffix (from "Updater Script"): us_ 33 | 34 | us_init() { 35 | echo "" 36 | } 37 | 38 | us_is_default_argument() { 39 | if [ "$1" = "" -o "$1" = "." ]; then 40 | return 0 # true when checked in a "if" 41 | fi 42 | return 1 # false when checked in a "if" 43 | } 44 | 45 | us_set_package_info() { 46 | 47 | if [ "$DEBUG" == "true" ]; then 48 | MISC_DIR="$DEBUG_MISC_SUB" 49 | LINK_DIR="$DEBUG_LINK_DIR" 50 | SCRIPT_DIR="$DEBUG_SCRIPT_DIR" 51 | fi 52 | 53 | PACKAGE_OWNER="$1" 54 | PACKAGE_NAME="$2" 55 | PACKAGE_PATTERN="$3" 56 | PACKAGE_TYPE="$4" 57 | PACKAGE_SIMPLENAME="$5" 58 | 59 | # Fallback to UPDATER package (the one containing this file) when the first two 60 | # arguments are empty 61 | PACKAGE_FALLBACK="" 62 | if us_is_default_argument "$PACKAGE_OWNER"; then 63 | if us_is_default_argument "$PACKAGE_NAME"; then 64 | PACKAGE_FALLBACK="true" 65 | fi 66 | fi 67 | if [ "$PACKAGE_FALLBACK" = "true" ]; then 68 | PACKAGE_TYPE="$PACKAGE_UPDATER_TYPE" 69 | PACKAGE_OWNER="$PACKAGE_UPDATER_OWNER" 70 | PACKAGE_NAME="$PACKAGE_UPDATER_NAME" 71 | fi 72 | 73 | # Other defaults 74 | if us_is_default_argument "$PACKAGE_PATTERN"; then 75 | PACKAGE_PATTERN="$PACKAGE_NAME" 76 | fi 77 | if us_is_default_argument "$PACKAGE_TYPE"; then 78 | PACKAGE_TYPE="gz.tar" 79 | fi 80 | if us_is_default_argument "$PACKAGE_SIMPLENAME"; then 81 | PACKAGE_SIMPLENAME="$PACKAGE_NAME" 82 | fi 83 | 84 | PACKAGE_REPO_SERVER="https://github.com" 85 | PACKAGE_REPO_API_SERVER="https://api.github.com/repos" 86 | PACKAGE_REPO="$PACKAGE_OWNER/$PACKAGE_NAME" 87 | PACKAGE_REPO_URL="$PACKAGE_REPO_SERVER/$PACKAGE_REPO" 88 | PACKAGE_REPO_API_URL="$PACKAGE_REPO_API_SERVER/$PACKAGE_REPO" 89 | PACKAGE_REPO_CONTENT="https://raw.githubusercontent.com/$PACKAGE_OWNER/$PACKAGE_NAME" 90 | PACKAGE_WORKING_DIR="$MISC_DIR/$PACKAGE_NAME" 91 | PACKAGE_DEFAULT_SCRIPT_NAME="$PACKAGE_NAME.sh" 92 | PACKAGE_DEFAULT_SCRIPT="$PACKAGE_WORKING_DIR/$PACKAGE_DEFAULT_SCRIPT_NAME" 93 | PACKAGE_EXPOSE="$PACKAGE_WORKING_DIR/$EXPOSE_HOOK" 94 | PACKAGE_ACTION="$PACKAGE_WORKING_DIR/$ACTION_HOOK" 95 | PACKAGE_BOOT="$PACKAGE_WORKING_DIR/$BOOT_HOOK" 96 | } 97 | 98 | us_prepare_folder() { 99 | if [ "$LINK_DIR" != "" ] ; then 100 | mkdir -p "$LINK_DIR" ||die "can not create the link directory '$LINK_DIR'" 101 | fi 102 | if [ "$SCRIPT_DIR" != "" ] ; then 103 | mkdir -p "$SCRIPT_DIR" ||die "can not create the script directory '$SCRIPT_DIR'" 104 | fi 105 | } 106 | 107 | us_remove() { 108 | echo "Removing $PACKAGE_NAME..." 109 | 110 | # Remove links for the exposed hooks 111 | if [ "$LINK_DIR" != "" ] ; then 112 | for HOOK in $(ls "$PACKAGE_EXPOSE" 2>/dev/null) ; do 113 | # Print error when not found, but DO NOT stop the process ! 114 | FULLPATH="$LINK_DIR/${PACKAGE_SIMPLENAME}_$HOOK" 115 | if [ "$HOOK" = "$QUICK_HOOK_NAME" ] ; then 116 | FULLPATH="$LINK_DIR/${PACKAGE_SIMPLENAME}" 117 | fi 118 | rm "$FULLPATH" 119 | done 120 | fi 121 | 122 | # Remove script wrappers for the action hooks 123 | if [ "$SCRIPT_DIR" != "" ] ; then 124 | for HOOK in $(ls "$PACKAGE_ACTION" 2>/dev/null) ; do 125 | # Print error when not found, but DO NOT stop the process ! 126 | FULLPATH="$SCRIPT_DIR/${PACKAGE_SIMPLENAME}_$HOOK" 127 | if [ "$HOOK" = "$QUICK_HOOK_NAME" ] ; then 128 | FULLPATH="$SCRIPT_DIR/${PACKAGE_SIMPLENAME}" 129 | fi 130 | rm "$FULLPATH" 131 | done 132 | fi 133 | 134 | # Remove package content 135 | rm -fR "$PACKAGE_WORKING_DIR" 136 | } 137 | 138 | us_install(){ 139 | echo "Updating $PACKAGE_NAME..." 140 | 141 | mkdir -p "$PACKAGE_WORKING_DIR" ||die "can not create the working directory '$PACKAGE_WORKING_DIR'" 142 | cd "$PACKAGE_WORKING_DIR" ||die "can not enter in the working direrctory '$PACKAGE_WORKING_DIR'" 143 | 144 | # download 145 | case $PACKAGE_TYPE in 146 | "github.master") 147 | PACK_URL="$PACKAGE_REPO_URL/archive/refs/heads/master.zip" 148 | ;; 149 | *) 150 | PACK_LIST=$($CURL -L -s "$PACKAGE_REPO_API_URL/releases/latest" | grep '"browser_download_url"' | sed 's:.*"\(.*\)"[^"]*:\1:g') 151 | PACK_URL=$(echo "$PACK_LIST" | grep "$PACKAGE_PATTERN" | head -n 1) 152 | PACKAGE_INFO="repo '$PACKAGE_REPO_URL' / file '$PACK_URL'" 153 | ;; 154 | esac 155 | $CURL "$PACK_URL" -o "$TMPFILE" ||die "can not download $PACKAGE_INFO" 156 | 157 | # extract 158 | case $PACKAGE_TYPE in 159 | "bare") 160 | # mv "$TMPFILE" "$(echo "$PACK_URL" | sed 's:^.*/::')" 161 | mv "$TMPFILE" "$PACKAGE_PATTERN" 162 | ;; 163 | "uudecode.xz") 164 | uudecode -o "$TMPFILE.xz" "$TMPFILE" ||die "can not unpack $PACKAGE_INFO" 165 | rm "$TMPFILE" ||die "can not unpack $PACKAGE_INFO" 166 | xz --decompress "$TMPFILE.xz" ||die "can not unpack $PACKAGE_INFO" 167 | cp "$TMPFILE" "$PACKAGE_NAME" ||die "can not unpack $PACKAGE_INFO" 168 | ;; 169 | "gz.tar") 170 | $TAR -xzf "$TMPFILE" ||die "can not unpack $PACKAGE_INFO" 171 | ;; 172 | "tar") 173 | $TAR -xf "$TMPFILE" ||die "can not unpack $PACKAGE_INFO" 174 | ;; 175 | "github.master") 176 | $UNZIP "$TMPFILE" ||die "can not unpack $PACKAGE_INFO" 177 | SUBNAM="$(ls)" 178 | mv "$SUBNAM"/* "$SUBNAM"/.[!.]* "$SUBNAM"/..?* . 2> /dev/null 179 | rmdir "$SUBNAM" ||die "can not unpack $PACKAGE_INFO" 180 | ;; 181 | *) 182 | false ||die "unsupported package type" 183 | ;; 184 | esac 185 | 186 | if [ "$?" != "0" ]; then 187 | false ||die "Installation failed" 188 | fi 189 | 190 | rm -f "$TMPFILE" 191 | } 192 | 193 | us_show_shortcut() { 194 | echo "#!/usr/bin/env bash" 195 | if [ "$SHORTCUT_INFO" != "" ] ;then 196 | echo -e "\n# $SHORTCUT_INFO\n" 197 | fi 198 | cat << EOF 199 | 200 | # Test internet 201 | ping -c 1 www.google.com > /dev/null 202 | if [ "\$?" != "0" ]; then 203 | echo "Network not found: check your internet connection or try later" 204 | exit 126 205 | fi 206 | 207 | # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv 208 | # You can simply run the following command instead of running this file 209 | # 210 | curl -L -k "$PACKAGE_REPO_CONTENT/master/$PACKAGE_DEFAULT_SCRIPT_NAME" | bash -s update 211 | # 212 | # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 213 | 214 | X=("\${PIPESTATUS[@]}") 215 | EXIT_CODE=\${X[0]} 216 | if [ "\$EXIT_CODE" = "0" ]; then 217 | EXIT_CODE=\${X[1]} 218 | fi 219 | if [ "\$EXIT_CODE" != "0" ]; then 220 | echo "Error downloading the package (\$EXIT_CODE)" 221 | fi 222 | 223 | read -n 1 -s -r -p "Press any key to continue" 224 | echo "" 225 | exit \$EXIT_CODE 226 | EOF 227 | } 228 | 229 | us_generate_wrapper() { 230 | cat << EOF 231 | #!/usr/bin/env bash 232 | cd "$PACKAGE_WORKING_DIR" 233 | "$1" \$@ 234 | EXIT_CODE="\$?" 235 | read -n 1 -s -r -p "Press any key to continue" 236 | echo "" 237 | exit \$EXIT_CODE 238 | EOF 239 | } 240 | 241 | us_is_updater_package(){ 242 | if [ "$PACKAGE_OWNER" = "$PACKAGE_UPDATER_OWNER" -a "$PACKAGE_NAME" = "$PACKAGE_UPDATER_NAME" ]; then 243 | return 0 # true when checked in a "if" 244 | fi 245 | return 1 # false when checked in a "if" 246 | } 247 | 248 | us_config() { 249 | echo "Configuring $PACKAGE_NAME..." 250 | 251 | if us_is_updater_package; then 252 | # This is done with a wrapper for other packages, however the Updater is 253 | # an exception since the "Shortcut" MUST work also withou any installation) 254 | if [ "$SCRIPT_DIR" != "" ] ; then 255 | us_show_shortcut > "$SCRIPT_DIR/${PACKAGE_NAME}_update.sh" ||die 256 | fi 257 | else 258 | 259 | # Add link for the exposed hooks 260 | if [ "$LINK_DIR" != "" ] ; then 261 | for HOOK in $(ls "$PACKAGE_EXPOSE" 2>/dev/null) ; do 262 | FULLPATH="$LINK_DIR/${PACKAGE_SIMPLENAME}_$HOOK" ||die 263 | if [ "$HOOK" = "$QUICK_HOOK_NAME" ] ; then 264 | FULLPATH="$LINK_DIR/${PACKAGE_SIMPLENAME}" ||die 265 | fi 266 | ln -s "$PACKAGE_EXPOSE/$HOOK" "$FULLPATH" ||die 267 | done 268 | fi 269 | 270 | # Add script wrappers for the action hooks 271 | if [ "$SCRIPT_DIR" != "" ] ; then 272 | for HOOK in $(ls "$PACKAGE_ACTION" 2>/dev/null) ; do 273 | FULLPATH="$SCRIPT_DIR/${PACKAGE_SIMPLENAME}_$HOOK" ||die 274 | if [ "$HOOK" = "$QUICK_HOOK_NAME" ] ; then 275 | FULLPATH="$SCRIPT_DIR/${PACKAGE_SIMPLENAME}" ||die 276 | fi 277 | us_generate_wrapper "$PACKAGE_ACTION/$HOOK" > "$FULLPATH" ||die 278 | done 279 | fi 280 | fi 281 | 282 | # TODO : other configs ? boot hooks ? 283 | } 284 | 285 | us_finish(){ 286 | echo "Done." 287 | } 288 | 289 | us_package_do() { 290 | ACTION="$1" 291 | shift 292 | 293 | # This will fallback to the UPDATER package (i.e. the one containing this 294 | # file) when no other parameter are given 295 | us_set_package_info $@ 296 | 297 | case $ACTION in 298 | "install") 299 | us_install 300 | ;; 301 | "remove") 302 | us_remove 303 | ;; 304 | "config") 305 | us_config 306 | ;; 307 | *) 308 | echo "Invalid action '$1'" 309 | exit -1; 310 | ;; 311 | esac 312 | } 313 | 314 | # PACKAGE LIST 315 | us_do_for_other() { 316 | us_package_do "$1" pocomane webkeyboard 'arm.*tar.gz' 317 | us_package_do "$1" pocomane MiSTer_Batch_Control 'mbc.tar.gz' . 'mbc' 318 | us_package_do "$1" nilp0inter MiSTer_WebMenu 'webmenu.sh' uudecode.xz 319 | us_package_do "$1" pocomane MiSTer_webmenu_package . . 'webmenu' 320 | # TODO : add ther packages 321 | } 322 | 323 | us_do_for_updater() { 324 | us_package_do "$1" 325 | } 326 | 327 | us_do_for_all() { 328 | us_do_for_updater $1 329 | us_do_for_other $1 330 | } 331 | 332 | us_info(){ 333 | echo "Usage Summary." 334 | echo "To download and update the software:" 335 | echo " $0 update" 336 | echo "To remove the software:" 337 | echo " $0 remove" 338 | echo "To configure the software:" 339 | echo " $0 config" 340 | echo "To view a simple Updater Shortcut script:" 341 | echo " $0 show_shortcut" 342 | } 343 | 344 | us_is_updater_installed() { 345 | us_set_package_info 346 | if [[ -x "$PACKAGE_DEFAULT_SCRIPT" ]]; then 347 | return 0 # true when checked in a "if" 348 | fi 349 | return 1 # false when checked in a "if" 350 | } 351 | 352 | us_run_installed_updater() { 353 | us_set_package_info 354 | 355 | if [ "$DEBUG" == "true" ]; then 356 | # for debug: use current script to install packages 357 | us_main_dispatch $@ 358 | else 359 | # for release: use the downloaded script to install packages 360 | "$PACKAGE_DEFAULT_SCRIPT" $@ ||die 361 | fi 362 | } 363 | 364 | us_main_dispatch() { 365 | if [ "$#" = "0" ]; then 366 | us_info 367 | else 368 | case $1 in 369 | 370 | "update") 371 | us_set_package_info 372 | us_prepare_folder 373 | 374 | if us_is_updater_installed; then 375 | us_run_installed_updater remove 376 | else 377 | us_do_for_all remove # it will call us_remove 378 | fi 379 | 380 | us_do_for_updater install 381 | us_run_installed_updater internal_installer_for_update 382 | ;; 383 | "remove") 384 | us_do_for_all remove # it will call us_remove 385 | ;; 386 | "internal_installer_for_update") 387 | us_do_for_other install # it will call us_install 388 | us_do_for_all config # it will call us_config 389 | ;; 390 | "config") 391 | us_do_for_all config # it will call us_config 392 | ;; 393 | "show_shortcut") 394 | us_set_package_info 395 | SHORTCUT_INFO="This file was generated by '$0 $@'" 396 | us_show_shortcut 397 | SHORTCUT_INFO="" 398 | exit 0 # skip the ending summary so the result can be store in a script without any changes 399 | ;; 400 | *) 401 | echo "Invalid option" 402 | us_info 403 | false ||die "invalid option" 404 | ;; 405 | esac 406 | fi 407 | } 408 | 409 | us_init 410 | us_main_dispatch $@ 411 | us_finish 412 | 413 | --------------------------------------------------------------------------------