From b1a220d4117fbf284fb3107366effa4b3d14ed95 Mon Sep 17 00:00:00 2001 From: Roberto Previdi Date: Mon, 4 May 2009 00:55:18 +0200 Subject: [PATCH] scripta first commit --- menu/opkg/1_select_feeds | 25 ++++++ menu/opkg/2_update | 4 + menu/opkg/3_upgrade | 10 +++ menu/opkg/4_install | 7 ++ menu/system/d | 0 menu/system/e | 0 scripta | 218 +++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 264 insertions(+) create mode 100644 menu/opkg/1_select_feeds create mode 100644 menu/opkg/2_update create mode 100644 menu/opkg/3_upgrade create mode 100644 menu/opkg/4_install create mode 100644 menu/system/d create mode 100644 menu/system/e create mode 100755 scripta diff --git a/menu/opkg/1_select_feeds b/menu/opkg/1_select_feeds new file mode 100644 index 0000000..95774e4 --- /dev/null +++ b/menu/opkg/1_select_feeds @@ -0,0 +1,25 @@ +function run() +{ + mkdir -p /etc/opkg/disabled + + ENABLED=`ls /etc/opkg/*-feed.conf` + DISABLED=`ls /etc/opkg/disabled/*-feed.conf` + ENABLED_LIST="" + DISABLED_LIST="" + for i in $ENABLED; do + ENABLED_LIST=$ENABLED_LIST" TRUE "`basename $i` + done + + for i in $DISABLED; do + DISABLED_LIST=$DISABLED_LIST" FALSE "`basename $i` + done + + FEED_SELECTED=`$ZENITY --column="Enabled" --column="Feed" --list --checklist $ENABLED_LIST $DISABLED_LIST` + + if [ $? -eq 0 ]; then + mv /etc/opkg/*-feed.conf /etc/opkg/disabled + for i in $FEED_SELECTED; do + mv /etc/opkg/disabled/$i /etc/opkg + done + fi +} diff --git a/menu/opkg/2_update b/menu/opkg/2_update new file mode 100644 index 0000000..1ff30b9 --- /dev/null +++ b/menu/opkg/2_update @@ -0,0 +1,4 @@ +function run() +{ + opkg update |$ZENITY --text-info +} diff --git a/menu/opkg/3_upgrade b/menu/opkg/3_upgrade new file mode 100644 index 0000000..b934dcd --- /dev/null +++ b/menu/opkg/3_upgrade @@ -0,0 +1,10 @@ +function run() +{ + UPG_SELECTED=`opkg list_upgradable| sed 's/\(^.*$\)/TRUE\n\1/' | $ZENITY --column="Upgrade" --column="Package" --list --checklist` + if [ $? -eq 0 ]; then + UPG_SELECTED=`echo $UPG_SELECTED| sed 's/|/\n/'|cut -f1 -d" "` + for i in $UPG_SELECTED; do + echo "opkg upgrade "$i + done + fi +} diff --git a/menu/opkg/4_install b/menu/opkg/4_install new file mode 100644 index 0000000..bc0c5c4 --- /dev/null +++ b/menu/opkg/4_install @@ -0,0 +1,7 @@ +function run() +{ + opkg list>$TMP/installable + opkg list_installed>$TMP/installed + INSTALLED_REGEXP=`cat $TMP/installed | sed -e :a -e '$ P; /$/N; s/\n/|/; ta;'` + egrep -v "$INSTALLED_REGEXP" installable +} diff --git a/menu/system/d b/menu/system/d new file mode 100644 index 0000000..e69de29 diff --git a/menu/system/e b/menu/system/e new file mode 100644 index 0000000..e69de29 diff --git a/scripta b/scripta new file mode 100755 index 0000000..7e0c0b0 --- /dev/null +++ b/scripta @@ -0,0 +1,218 @@ +#!/bin/bash +# Copyright 2009, Roberto Previdi +# GPL v2 or later + +ZENITY="zenity --width=400 --height=400" +MSGBOX="$ZENITY --info --text " +ERROR="$ZENITY --error --text " +ENTRY="$ZENITY --entry --text " +EDITFILE="$ZENITY --text-info --editable --filename " +TMP="/tmp" +ROOT_MENU_DIR="menu" +SEP="===================" +TITLE="scripta" + +# arg1: relative/absolute path to switch to +function change_dir() +{ + echo "change_dir($1)" + cd $1 + MENU_DIR=$(pwd) +} + +function new_menu() +{ + NAME="$($ENTRY "enter the name of the menu")" + if [ $? -gt 0 ]; then + $MSGBOX operation cancelled + else + mkdir "$NAME" + fi +} + +function new_script() +{ + NAME="$($ENTRY "enter the name of the script")" + if [ $? -gt 0 ]; then + $MSGBOX operation cancelled + else + touch "$NAME" +# ---> # + cat >> "$NAME" << _END +function run() +{ + $MSGBOX "edit me!" +} +_END +# ---> # + fi +} + +#arg1: menu to edit +function edit_menu() +{ + ACTION=$($ZENITY --column "Select action" --list rename remove) + if [ $? -gt 0 ]; then + $MSGBOX operation cancelled + elif [ "$ACTION" == "remove" ]; then + PASSWORD=$($ZENITY --entry --text "enter \"DELETE this MENU\"" --entry-text "pleeease, don't kill meeee") + if [ $? -gt 0 -o $PASSWORD != "DELETE this MENU"]; then + $MSGBOX operation cancelled + else + rm -rf $1 + fi + elif [ "$ACTION" == "rename" ]; then + NEW_NAME=$($ENTRY "enter new name" --entry-text $1) + if [ $1 -gt 0 ]; then + $MSGBOX operation cancelled + else + mv $1 $NEW_NAME + fi + fi +} + +#arg1: file to edit +function edit_file() +{ + ACTION=$($ZENITY --column "Select action" --list edit rename remove) + if [ $? -gt 0 ]; then + $MSGBOX operation cancelled + elif [ "$ACTION" == "edit" ]; then + $EDITFILE $1 > $1.tmp + mv -f $1.tmp $1 + elif [ "$ACTION" == "remove" ]; then + PASSWORD="$($ZENITY --entry --text "enter \"DELETE this FILE\"" --entry-text "noooo, save meeee")" + if [ $? -gt 0 -o $PASSWORD != "DELETE this FILE"]; then + $MSGBOX operation cancelled + else + rm -rf $1 + fi + + elif [ "$ACTION" == "rename" ]; then + NEW_NAME=$($ZENITY --entry --text "enter new name" --entry-text $1) + if [ $? -gt 0 ]; then + $MSGBOX operation cancelled + else + mv $1 $NEW_NAME + fi + fi +} + +#edit the menus in the current path +function edit_fn() +{ + while [ 1 ]; do + TITLE="scripta - EDIT" + menu_items --desc-prefix "edit--" back new_submenu new_script quit + + if [ "$SELECTED" == $SEP ]; then + do_nothing + elif [ "$SELECTED" == "back" ]; then + return 0 + elif [ "$SELECTED" == "new_submenu" ]; then + new_menu + elif [ "$SELECTED" == "new_script" ]; then + new_script + elif [ -d $SELECTED ]; then + edit_menu $SELECTED + elif [ -f $SELECTED ]; then + edit_file $SELECTED + fi + done + +} + +# arg1: bash script which defines a "run" function +function execute() +{ + function run() + { + $ERROR "Error, the file doesn't define a run() function" + } + + . $1 + + run + +} + +function do_nothing() +{ + DUMMY=$DUMMY +} + +# arg1: return value of zenity +# arg2: selected command +function parse_menu_commons() +{ + if [ $1 -gt 0 ]; then + echo exiting with status $1 + exit $1 + fi + + if [ "$2" == "quit" ]; then + exit 0 + fi +} + +#arg1: prefix for the description part +function get_items() +{ + SUBMENUS=$( + find -maxdepth 1 -type d | + sort | + sed 's/.*\/\([^/]*\)/\1/' | + sed 's/[.]//' | + sed -e :a -e '$ P; /$/N; s/\n/ /; ta;'| + head -n 1 | + sed 's/$/ /' | + sed "s/\([a-z]\+\) /\1 $1\1... /g" + ) + MENU_ITEMS=$( + find -maxdepth 1 -type f | + sort | + sed "s/.*\/\([^/]*\)/\1 $1\1/" | + sed -e :a -e '$ P; /$/N; s/\n/ /; ta;'| + head -n 1) +} + +# arg1-n: additional menu entries +function menu_items() +{ + cd $MENU_DIR + ADDITIONAL="" + DESC_PREFIX="" + while [ $# -gt 0 ]; do + if [ "$1" == "--desc-prefix" ]; then + shift + DESC_PREFIX="$1" + else + ADDITIONAL="$ADDITIONAL $1 $1" + fi + shift + done + + get_items "$DESC_PREFIX" + + SELECTED=$($ZENITY --title "$TITLE" --hide-column 1 --column Command --column Operation --list $SUBMENUS $MENU_ITEMS $SEP $SEP $ADDITIONAL) + parse_menu_commons $? "$SELECTED" +} + + +change_dir $ROOT_MENU_DIR +while [ 1 ]; do + TITLE="scripta" + menu_items back edit quit + + if [ "$SELECTED" == $SEP ]; then + do_nothing + elif [ "$SELECTED" == "edit" ]; then + edit_fn + elif [ "$SELECTED" == "back" ]; then + change_dir .. + elif [ -d $SELECTED ]; then + change_dir $SELECTED + elif [ -f $SELECTED ]; then + execute $SELECTED + fi +done -- 2.11.4.GIT