Xu Xiaodong avatar Xu Xiaodong committed e136ecb

rewrite resbox

Comments (0)

Files changed (1)

 #
 # description:  利用 ucloner 还原 ubox 系统
 # author:       Xu Xiaodong <xxdlhy@gmail.com>
-# modified:     2011 Aug 12
+# modified:     2011 Aug 14
 #
 
-BASE=$HOME/ucloner
-PROG=$BASE/program
-SH=$HOME/resbox
-#IMAGE=$BASE/ubox.squashfs
-IMAGE=$BASE/2011-06-16.squashfs
+BASE="$HOME"/tools
+PROG="$BASE"/ucloner/program
+SH="$BASE"/resbox
+IMAGE="$BASE"/ucloner/ubox.squashfs
 NAME=$(date +%Y-%m-%d)
 
-cd $PROG
+ACTION="$1"
+TYPE="$2"
 
-case "$1" in
+usage () {
+  echo "用法: $(basename $0) backup | restore <hdd | ssd | ssh16> | clone | udisk"
+  echo
+  echo "选项:"
+  echo "  backup  备份当前系统"
+  echo "  restore 还原系统"
+  echo "    hdd   还原到传统硬盘"
+  echo "    ssd   还原到 30G 固态硬盘"
+  echo "    ssh16 还原到 16G 固态硬盘"
+  echo "  clone   克隆当前系统"
+  echo "  udisk   还原到优盘"
+}
+
+cd "$PROG"
+
+case "$ACTION" in
   backup)
-    sudo ./ucloner_cmd.py mode=backup backup_to=$BASE/"$NAME".squashfs
+    sudo ./ucloner_cmd.py mode=backup backup_to="$BASE"/"$NAME".squashfs
     ;;
   restore)
-    if [ $(ls /dev/sdb) = '/dev/sdb' ]; then
-      $SH/part_"$2".sh > /dev/null 2>&1
-      sudo ./ucloner_cmd.py mode=restore restore_from=$IMAGE \
+    if [ -n $(ls /dev/sdb) ]; then
+      if [ -z "$TYPE" ]; then
+        usage
+        exit 1
+      fi
+      "$SH"/part_"$TYPE".sh > /dev/null 2>&1
+      sudo ./ucloner_cmd.py mode=restore restore_from="$IMAGE" \
         /=/dev/sda1 /_fs=ext4 \
         /tmp=/dev/sda2 /tmp_fs=ext4 \
         /var=/dev/sda3 /var_fs=ext4 \
         grubdev=/dev/sda
     else
       echo "请安装硬盘先."
-      exit 0
+      exit 1
     fi
     ;;
   clone)
       exclude=/home/ubox/ucloner
     ;;
   udisk)
-    sudo ./ucloner_cmd.py mode=restore restore_from=$IMAGE /=/dev/sdc1 /_fs=ext4 grubdev=/dev/sdc
+    sudo ./ucloner_cmd.py mode=restore restore_from="$IMAGE" \
+      /=/dev/sdc1 /_fs=ext4 \
+      grubdev=/dev/sdc
     ;;
   *)
-    echo "$0 backup | restore <hdd | ssd | ssh16> | clone | udisk"
-    exit 0
+    usage
+    exit 1
     ;;
 esac
 
-if [ $? -eq 0 ]; then
+if [ "$?" -eq 0 ]; then
   echo "系统安装成功, 将在 5 秒后自动重启."
   sleep 5
   sudo reboot
   echo "系统安装失败."
 fi
 
+exit 0
+
 # vim: ai:et:ts=2:sw=2:sts=2:tw=78:ft=sh
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.