Преглед на файлове

fixed FW update and network config

Danja Vasiliev преди 10 години
родител
ревизия
168aa640b1

+ 1 - 0
.gitignore

@@ -3,6 +3,7 @@ dist
 [._]*.s[a-w][a-z]
 [._]s[a-w][a-z]
 *.un~
+*.revision
 Session.vim
 .netrwhist
 *~*~

+ 2 - 2
openwrt/common/etc/config/wireless

@@ -3,9 +3,9 @@ config wifi-device 'radio0'
 	option channel 'auto'
 	option hwmode '11gn'
 	option path 'platform/ar933x_wmac'
-	option noscan 1
+	option noscan '1'
 	option htmode 'HT20'
-	option country DE
+	option country 'US' ## US regdom is 
 
 config wifi-iface
 	option device 'radio0'

+ 248 - 0
openwrt/common/lib/upgrade/common.sh

@@ -0,0 +1,248 @@
+#!/bin/sh
+
+RAM_ROOT=/tmp/root
+
+ldd() { LD_TRACE_LOADED_OBJECTS=1 $*; }
+libs() { ldd $* | awk '{print $3}'; }
+
+install_file() { # <file> [ <file> ... ]
+	for file in "$@"; do
+		dest="$RAM_ROOT/$file"
+		[ -f $file -a ! -f $dest ] && {
+			dir="$(dirname $dest)"
+			mkdir -p "$dir"
+			cp $file $dest
+		}
+	done
+}
+
+install_bin() { # <file> [ <symlink> ... ]
+	src=$1
+	files=$1
+	[ -x "$src" ] && files="$src $(libs $src)"
+	install_file $files
+	[ -e /lib/ld.so.1 ] && {
+		install_file /lib/ld.so.1
+	}
+	shift
+	for link in "$@"; do {
+		dest="$RAM_ROOT/$link"
+		dir="$(dirname $dest)"
+		mkdir -p "$dir"
+		[ -f "$dest" ] || ln -s $src $dest
+	}; done
+}
+
+supivot() { # <new_root> <old_root>
+	/bin/mount | grep "on $1 type" 2>&- 1>&- || /bin/mount -o bind $1 $1
+	mkdir -p $1$2 $1/proc $1/sys $1/dev $1/tmp $1/overlay && \
+	/bin/mount -o noatime,move /proc $1/proc && \
+	pivot_root $1 $1$2 || {
+		/bin/umount -l $1 $1
+		return 1
+	}
+
+	/bin/mount -o noatime,move $2/sys /sys
+	/bin/mount -o noatime,move $2/dev /dev
+	/bin/mount -o noatime,move $2/tmp /tmp
+	/bin/mount -o noatime,move $2/overlay /overlay 2>&-
+	return 0
+}
+
+run_ramfs() { # <command> [...]
+	install_bin /bin/busybox /bin/ash /bin/sh /bin/mount /bin/umount	\
+		/sbin/pivot_root /usr/bin/wget /sbin/reboot /bin/sync /bin/dd	\
+		/bin/grep /bin/cp /bin/mv /bin/tar /usr/bin/md5sum "/usr/bin/["	\
+		/bin/dd /bin/vi /bin/ls /bin/cat /usr/bin/awk /usr/bin/hexdump	\
+		/bin/sleep /bin/zcat /usr/bin/bzcat /usr/bin/printf /usr/bin/wc \
+		/bin/cut /usr/bin/printf /bin/sync /bin/mkdir /bin/rmdir	\
+		/bin/rm /usr/bin/basename /bin/kill /bin/chmod
+
+	install_bin /sbin/mtd
+	install_bin /sbin/ubi
+	install_bin /sbin/mount_root
+	install_bin /sbin/snapshot
+	install_bin /sbin/snapshot_tool
+	install_bin /usr/sbin/ubiupdatevol
+	install_bin /usr/sbin/ubiattach
+	install_bin /usr/sbin/ubiblock
+	install_bin /usr/sbin/ubiformat
+	install_bin /usr/sbin/ubidetach
+	install_bin /usr/sbin/ubirsvol
+	install_bin /usr/sbin/ubirmvol
+	install_bin /usr/sbin/ubimkvol
+	for file in $RAMFS_COPY_BIN; do
+		install_bin ${file//:/ }
+	done
+	install_file /etc/resolv.conf /lib/*.sh /lib/functions/*.sh /lib/upgrade/*.sh $RAMFS_COPY_DATA
+
+	[ -L "/lib64" ] && ln -s /lib $RAM_ROOT/lib64
+
+	supivot $RAM_ROOT /mnt || {
+		echo "Failed to switch over to ramfs. Please reboot."
+		exit 1
+	}
+
+	/bin/mount -o remount,ro /mnt
+	/bin/umount -l /mnt
+
+	grep /overlay /proc/mounts > /dev/null && {
+		/bin/mount -o noatime,remount,ro /overlay
+		/bin/umount -l /overlay
+	}
+
+	# spawn a new shell from ramdisk to reduce the probability of cache issues
+	exec /bin/busybox ash -c "$*"
+}
+
+kill_remaining() { # [ <signal> ]
+	local sig="${1:-TERM}"
+	echo -n "Sending $sig to remaining processes ... "
+
+	local my_pid=$$
+	local my_ppid=$(cut -d' ' -f4  /proc/$my_pid/stat)
+	local my_ppisupgraded=
+	grep -q upgraded /proc/$my_ppid/cmdline >/dev/null && {
+		local my_ppisupgraded=1
+	}
+	
+	local stat
+	for stat in /proc/[0-9]*/stat; do
+		[ -f "$stat" ] || continue
+
+		local pid name state ppid rest
+		read pid name state ppid rest < $stat
+		name="${name#(}"; name="${name%)}"
+
+		local cmdline
+		read cmdline < /proc/$pid/cmdline
+
+		# Skip kernel threads
+		[ -n "$cmdline" ] || continue
+
+		if [ $$ -eq 1 ] || [ $my_ppid -eq 1 ] && [ -n "$my_ppisupgraded" ]; then
+			# Running as init process, kill everything except me
+			if [ $pid -ne $$ ] && [ $pid -ne $my_ppid ]; then
+				echo -n "$name "
+				kill -$sig $pid 2>/dev/null
+			fi
+		else 
+			case "$name" in
+				# Skip essential services
+				*dtach*|*fw-upgrade*|*procd*|*ash*|*init*|*watchdog*|*ssh*|*dropbear*|*telnet*|*login*|*hostapd*|*wpa_supplicant*|*nas*) : ;;
+
+				# Killable process
+				*)
+					if [ $pid -ne $$ ] && [ $ppid -ne $$ ]; then
+						echo -n "$name "
+						kill -$sig $pid 2>/dev/null
+					fi
+				;;
+			esac
+		fi
+	done
+	echo ""
+}
+
+run_hooks() {
+	local arg="$1"; shift
+	for func in "$@"; do
+		eval "$func $arg"
+	done
+}
+
+ask_bool() {
+	local default="$1"; shift;
+	local answer="$default"
+
+	[ "$INTERACTIVE" -eq 1 ] && {
+		case "$default" in
+			0) echo -n "$* (y/N): ";;
+			*) echo -n "$* (Y/n): ";;
+		esac
+		read answer
+		case "$answer" in
+			y*) answer=1;;
+			n*) answer=0;;
+			*) answer="$default";;
+		esac
+	}
+	[ "$answer" -gt 0 ]
+}
+
+v() {
+	[ "$VERBOSE" -ge 1 ] && echo "$@"
+}
+
+rootfs_type() {
+	/bin/mount | awk '($3 ~ /^\/$/) && ($5 !~ /rootfs/) { print $5 }'
+}
+
+get_image() { # <source> [ <command> ]
+	local from="$1"
+	local conc="$2"
+	local cmd
+
+	case "$from" in
+		http://*|ftp://*) cmd="wget -O- -q";;
+		*) cmd="cat";;
+	esac
+	if [ -z "$conc" ]; then
+		local magic="$(eval $cmd $from 2>/dev/null | dd bs=2 count=1 2>/dev/null | hexdump -n 2 -e '1/1 "%02x"')"
+		case "$magic" in
+			1f8b) conc="zcat";;
+			425a) conc="bzcat";;
+		esac
+	fi
+
+	eval "$cmd $from 2>/dev/null ${conc:+| $conc}"
+}
+
+get_magic_word() {
+	(get_image "$@" | dd bs=2 count=1 | hexdump -v -n 2 -e '1/1 "%02x"') 2>/dev/null
+}
+
+get_magic_long() {
+	(get_image "$@" | dd bs=4 count=1 | hexdump -v -n 4 -e '1/1 "%02x"') 2>/dev/null
+}
+
+jffs2_copy_config() {
+	if grep rootfs_data /proc/mtd >/dev/null; then
+		# squashfs+jffs2
+		mtd -e rootfs_data jffs2write "$CONF_TAR" rootfs_data
+	else
+		# jffs2
+		mtd jffs2write "$CONF_TAR" rootfs
+	fi
+}
+
+default_do_upgrade() {
+	sync
+	if [ "$SAVE_CONFIG" -eq 1 ]; then
+		get_image "$1" | mtd $MTD_CONFIG_ARGS -j "$CONF_TAR" write - "${PART_NAME:-image}"
+	else
+		get_image "$1" | mtd write - "${PART_NAME:-image}"
+	fi
+}
+
+do_upgrade() {
+	v "Performing system upgrade..."
+	if type 'platform_do_upgrade' >/dev/null 2>/dev/null; then
+		platform_do_upgrade "$ARGV"
+	else
+		default_do_upgrade "$ARGV"
+	fi
+
+	if [ "$SAVE_CONFIG" -eq 1 ] && type 'platform_copy_config' >/dev/null 2>/dev/null; then
+		platform_copy_config
+	fi
+
+	v "Upgrade completed"
+	[ -n "$DELAY" ] && sleep "$DELAY"
+	ask_bool 1 "Reboot" && {
+		v "Rebooting system..."
+		reboot -f
+		sleep 5
+		echo b 2>/dev/null >/proc/sysrq-trigger
+	}
+}

+ 46 - 29
openwrt/common/opt/lib/cgi/admin2.cgi

@@ -1,4 +1,4 @@
-#!/usr/bin/haserl --shell=/bin/bash  --upload-limit=32768 --upload-dir=/www/tmp 
+#!/usr/bin/haserl --shell=/bin/bash  --upload-limit=32768 --upload-dir=/tmp
 <%# upload limit: 32Mb %>
 <%
 
@@ -88,6 +88,7 @@ setQueryVars() {
 runSuid() {
   local _SID=$(/usr/bin/ps -p $$ -o sid=)  ## pass session id to the child
   local _CMD=$@
+  logThis "command: $_CMD"
   /usr/bin/sudo ./suid.sh $_CMD $_SID 2>/dev/null
 }
 
@@ -143,8 +144,11 @@ lanAddr() {
   if [[ $_ERR -gt 0 ]]; then
     showMesg 'Setting network address failed'
   else
-    (sleep 1; doUci commit network; doUci commit wireless;)&
-    showMesg 'New network address is set' '30' "Your server is now accessible under <a href='http://superglue.local/admin'>http://superglue.local/admin</a>"
+    doUci commit network &&
+    runSuid "dtach -n -zE /opt/lib/scripts/net-restart.sh" &&
+
+    showMesg 'New network address is set' '30' "Your server is now accessible under <a href='http://superglue.local/admin'>http://superglue.local/admin</a>" || 
+    showMesg 'Setting network address failed'
   fi 
 }
 
@@ -196,8 +200,14 @@ wanSet() {
     ## background the following
     ##(doUci commit network; doUci commit wireless) &&
     (doUci commit network; doUci commit wireless;) &&
-    showMesg 'Internet connection is being configured' '25' 'initializing - ' ||
-    showMesg 'Configuring Internet connection failed'
+    runSuid "dtach -n -zE /opt/lib/scripts/net-restart.sh"
+  
+    _ERR=$?
+    if [[ $_ERR -gt 0 ]]; then
+      showMesg 'Configuring Internet connection failed'
+    else
+      showMesg 'Internet connection is being configured' '35' 'check your Internet connection on completion - '
+    fi 
   fi
   logThis "new WAN iface is: $POST_wanifname"
 }
@@ -246,11 +256,21 @@ ssidChange() {
     [[ $_ERR -gt 0 ]] && showMesg 'Passphrase is not set'
   fi
   [[ $_ERR -gt 0 ]] && showMesg 'Wireless configuration failed'
-  doUci set lanipaddr ${POST_lanipaddr}
-  _ERR=$?
-  [[ $_ERR -gt 0 ]] && showMesg 'LAN IP configuration failed'
-  (doUci commit network; doUci commit wireless;) &&
-  showMesg 'Local network configuration applied' '25' 'please reconnect to your network - '
+  if [[ $POST_iface == 'lan' ]]; then
+    #doUci set lanipaddr ${POST_lanipaddr}
+    #_ERR=$?
+    #[[ $_ERR -gt 0 ]] && showMesg 'LAN IP configuration failed'
+    if [[ "$(doUci get lanipaddr)" !=  "${POST_lanipaddr}" ]]; then
+      logThis 'local IP was changed'
+      lanAddr
+    fi
+  fi
+  doUci commit wireless &&
+  runSuid "dtach -n -zE /opt/lib/scripts/net-restart.sh"
+
+  if [[ $POST_iface == 'lan' ]]; then
+    showMesg 'Local network configuration is progress' '45' 'check your connection on completion - '
+  fi
 }
 
 #showError() {
@@ -275,10 +295,10 @@ showMesg() {
     local _TYPE='OK: '
     headerPrint 200
   fi
-  htmlHead "<meta http-equiv='refresh' content='${_TIMEOUT};url=${HTTP_REFERER}'>"
+  htmlHead "<meta http-equiv='refresh' content='${_TIMEOUT};url=http://${HTTP_HOST}/admin'>"
   _echo "<body>
   <h1>Superglue server control panel</h1>
-  <img src='http://"${HTTP_HOST}"/resources/img/superglueLogo.png' class='logo'>
+  <img src='http://${HTTP_HOST}/resources/img/superglueLogo.png' class='logo'>
   <hr>
   <h2 style='display:inline'>$_TYPE $_MSG</h2>
   <span style='display:block'>$_SUBMSG</span>
@@ -287,8 +307,8 @@ showMesg() {
   <script type='text/javascript'>(function(e){var t=document.getElementById(e);var n=t.innerHTML;var r=setInterval(function(){if(n==0){t.innerHTML='0';clearInterval(r);return}t.innerHTML=n;n--},1e3)})('timeout')
   </script>
   </html>"
-
   exit 0
+
 #  _echo "<body>
 #<h1>SG</h1>
 #<hr>
@@ -302,15 +322,12 @@ showMesg() {
 updateFw() {
   logThis "updating fw"
   _FWFILE="${_TMP}/fwupload.bin"
-  logThis "fwfile is: $(ls -lad $_FWFILE)"
   _OUT="$(/sbin/sysupgrade -T $_FWFILE 2>&1)"
   _ERR=$?
-  [[ $_ERR -gt 0 ]] && showMesg "$_OUT"
-  _OUT="$(runSuid /sbin/mtd -r -e firmware -q write $_FWFILE firmware)"
-  _ERR=$?
-  [[ $_ERR -gt 0 ]] && showMesg "mtd failed, $_OUT"
-  #runSuid reboot
-  showMesg 'Firmware update is completing..' '90' 'Device will be rebooted -'
+  [[ $_ERR -gt 0 ]] && showMesg "Firmware upgrade failed! $_OUT"
+  ## using dtach to prevent sysupgrade getting killed
+  runSuid "dtach -n -zE /opt/lib/scripts/fw-upgrade.sh $_FWFILE"
+  showMesg 'Firmware upgrade is in progress..' '120' 'Device needs to reboot -'
 }
 
 usbInit() {
@@ -434,14 +451,14 @@ doUci() {
   fi
 
   if [[ $_CMD == 'commit' ]]; then
-    runSuid /sbin/uci commit $_ARG|| echo "uci commit $_ARG: error"
-    if [[ "$_ARG" == 'wireless' ]]; then
-      runSuid /sbin/wifi || echo 'wifi: error'
-    fi
-    if [[ "$_ARG" == 'network' ]]; then
-      runSuid "/etc/init.d/dnsmasq reload"
-      runSuid "/etc/init.d/network reload"
-    fi
+    runSuid /sbin/uci commit $_ARG || echo "uci commit $_ARG: error"
+#    if [[ "$_ARG" == 'wireless' ]]; then
+#      runSuid /sbin/wifi || echo 'wifi: error'
+#    fi
+#    if [[ "$_ARG" == 'network' ]]; then
+#      runSuid /etc/init.d/dnsmasq reload
+#      runSuid /etc/init.d/network reload
+#    fi
   fi
 }
 
@@ -656,7 +673,7 @@ wankey=$(doUci get wankey)
 
 
 <section>
-  <h2>Update firmware:</h2>
+  <h2>Firmware upgrade:</h2>
   <form method='post' action='/admin/updatefw' enctype='multipart/form-data'>
   <div id='uploadbox'>
     <input id='uploadfile' placeholder='Choose file' disabled='disabled'>

+ 3 - 1
openwrt/common/opt/lib/scripts/jshn-helper.sh

@@ -5,6 +5,8 @@
 ## assumes that DEST host has key based auth enabled,
 ## otherwise password will be prompted everytime
 
+pwd
+
 CMD='FILE=%f; DEST_FILE=${FILE#*/*/};
 scp $FILE superglue:/$DEST_FILE; 
 if [ $? -eq 0 ]; then 
@@ -15,5 +17,5 @@ fi'
 
 #CMD='echo %f'
 
-iwatch -c "eval $CMD" -e modify -X '\.sw.?' -r .
+iwatch -c "eval $CMD" -e modify -r -X "\.sw.?|\.revision|\.tmp|tools" ./
 

+ 56 - 25
openwrt/tools/make_fw.sh

@@ -5,8 +5,10 @@
 ##
 ## Needs:
 ## - OpenWRT ImageBuilder blob:
-##    http://downloads.openwrt.org/barrier_breaker/14.07-rc3/ar71xx/generic 
+##    http://downloads.openwrt.org/barrier_breaker/14.07/ar71xx/generic
 ##    or http://downloads.openwrt.org/snapshots/trunk/ar71xx
+## - Fetch (needed) packages:
+##    https://downloads.openwrt.org/barrier_breaker/14.07/ar71xx/generic/packages
 ## - Superglue serverfiles local repo (which this script is part of):
 ##    http://git.superglue.it/superglue/serverfiles/tree/master
 
@@ -31,22 +33,32 @@ _TARGETS='TLWR710'
 ## dir with common files
 _COMMON='common'
 
-_MAJOR='0.1'  ## bump that on major changes
-#_SUFFIX='git'  ## could be 'beta', 'rc', etc
-_SUFFIX='k0a1a'  ## could be 'beta', 'rc', etc
+_SG_REVISION="$_PWD/superglue.revision"
 
-_SG_REVISION="$_PWD/include/superglue.revision"
-_OPENWRT_REVISION="$_PWD/include/openwrt.revision"
+if [[ -e $_SG_REVISION ]]; then
+  source $_SG_REVISION
+else
+  ## versioning defaults
+  ## change these in $_SG_REVISION 
+  _MAJOR='0.1'
+  _MINOR='0'
+  _SUFFIX='testing'
+fi
+
+let _MINOR++
+
+#_SG_REVISION="$_PWD/superglue.revision"
+_OPENWRT_REVISION="$_PWD/openwrt.revision"
 
 ## browser extension (if any)
 _EXT_SRC="$_PWD/../../editor/build/firefox/superglue.xpi"
 
 ## read build serial, incremented on every successful build
-if [[ -e $_SG_REVISION ]]; then
-  read _MINOR < $_SG_REVISION
-  let _MINOR++
-else _MINOR=0
-fi
+#if [[ -e $_SG_REVISION ]]; then
+#  read _MINOR < $_SG_REVISION
+#  let _MINOR++
+#else _MINOR=0
+#fi
 
 ## get OpenWRT revision number
 _OPENWRT=$(fgrep -m1 'REVISION:=' $_IMAGEBUILDER/include/version.mk || echo 'r00000')
@@ -55,8 +67,22 @@ echo $_OPENWRT > $_OPENWRT_REVISION
 
 _VERSION="$_MAJOR"."$_MINOR"-"$_SUFFIX"
 
-echo "About to start building version: $_VERSION"
-echo -e "Targets for this build: $_TARGETS\n"
+echo -e "Build ver: $_VERSION
+Targets: $_TARGETS\n"
+
+trap abort INT
+
+abort() {
+  echo -e "Bye..\n"
+  exit 1
+}
+
+echo 'Ready? [Y/n] '; read _USER_ANSW
+if [[ $_USER_ANSW == 'n' ]]; then
+  abort
+elif [[ $_USER_ANSW == 'y' || $_USER_ANSW == '' ]]; then
+  true
+fi
 
 echo 'Removing temporary dirs (if any)'
 find -maxdepth 1 -name *.tmp -exec rm -Rf {} \;
@@ -89,26 +115,30 @@ for _TARGET in $_TARGETS; do
   echo $_VERSION > $_TARGET.tmp/etc/superglue_version
   cd $_IMAGEBUILDER && make clean
 
-  echo 'ready for building the image!'
-  sleep 3; clear
+  echo -e "\nbuilding $_TARGET image!\n"
+  sleep 2
 
   ## package stash, might need these:
   # kmod-fs-vfat kmod-fs-btrfs btrfs-progs
 
-  make image PROFILE=$_TARGET PACKAGES="bash gawk sudo procps-ps openssh-sftp-server haserl lighttpd lighttpd-mod-access lighttpd-mod-cgi lighttpd-mod-compress lighttpd-mod-accesslog lighttpd-mod-rewrite lighttpd-mod-auth lighttpd-mod-alias lighttpd-mod-setenv blkid kmod-fs-ext4 block-mount mini-sendmail kmod-usb-storage kmod-scsi-generic mount-utils kmod-nls-cp437 kmod-nls-iso8859-1 kmod-nls-utf8 kmod-nls-base coreutils-stat mini-httpd-htpasswd wireless-tools avahi-daemon kmod-fs-btrfs btrfs-progs swap-utils sfdisk coreutils-base64 rpcd-mod-iwinfo" FILES=$_PWD/$_TARGET.tmp BIN_DIR=$_BIN_DIR/openwrt && 
+  make image PROFILE=$_TARGET PACKAGES="bash gawk sudo procps-ps openssh-sftp-server haserl lighttpd lighttpd-mod-access lighttpd-mod-cgi lighttpd-mod-compress lighttpd-mod-accesslog lighttpd-mod-rewrite lighttpd-mod-auth lighttpd-mod-alias lighttpd-mod-setenv blkid kmod-fs-ext4 block-mount mini-sendmail kmod-usb-storage kmod-scsi-generic mount-utils kmod-nls-cp437 kmod-nls-iso8859-1 kmod-nls-utf8 kmod-nls-base coreutils-stat mini-httpd-htpasswd wireless-tools avahi-daemon kmod-fs-btrfs btrfs-progs swap-utils sfdisk coreutils-base64 rpcd-mod-iwinfo dtach" FILES=$_PWD/$_TARGET.tmp BIN_DIR=$_BIN_DIR/openwrt
+  _ERR=$?
+  if [[ $_ERR -gt 0 ]]; then
+    echo -e "\nFAILED to build $_TARGET image :/ (are we missing packages?) \n"
+    exit 1
+  fi
 
   ## define how firmware files are named
   _FN_PREFIX='superglue-firmware'
   _FILENAME="$_FN_PREFIX"_"$_VERSION"_"$(echo $_TARGET | tr [:upper:] [:lower:])"
 
-  ln -s $_BIN_DIR/openwrt/openwrt-*-factory.bin $_BIN_DIR/$_FILENAME'_initial.bin'
-  ln -s $_BIN_DIR/openwrt/openwrt-*-sysupgrade.bin $_BIN_DIR/$_FILENAME'_upgrade.bin'
-  cd $_BIN_DIR
+  ln -s $_BIN_DIR/openwrt/openwrt-*-factory.bin $_BIN_DIR/$_FILENAME'_initial.bin' &&
+  ln -s $_BIN_DIR/openwrt/openwrt-*-sysupgrade.bin $_BIN_DIR/$_FILENAME'_upgrade.bin' &&
+  cd $_BIN_DIR &&
   md5sum *.bin > md5sums
   cd -
 
   _ERR=$?
-
   if [[ $_ERR -eq 0 ]]; then 
     echo -e "\n$_TARGET build completed\n"
   else
@@ -124,7 +154,8 @@ done
 
 if [[ $_ERR -eq 0 ]]; then
   ## if build succeeded bump revision
-  echo $_MINOR > $_SG_REVISION
+  ## echo $_MINOR > $_SG_REVISION
+  echo -e "_MAJOR=$_MAJOR\n_MINOR=$_MINOR\n_SUFFIX=$_SUFFIX" > $_SG_REVISION
   echo -e "\nBuilding SUCCEEDED! :)\n"
 
   ## create symlinks to latest
@@ -132,12 +163,12 @@ if [[ $_ERR -eq 0 ]]; then
   for _TARGET in $_TARGETS; do
     [[ -e $_BUILDS/latest/$_TARGET ]] && rm -f $_BUILDS/latest/$_TARGET/* || mkdir $_BUILDS/latest/$_TARGET
     #set -o xtrace
-    _FACTORY="$_BUILDS"/latest/"$_TARGET"/$_FILENAME-initial.bin
-    _SYSUPGRADE=$_BUILDS/latest/"$_TARGET"/$_FILENAME-upgrade.bin
+    _FACTORY="$_BUILDS"/latest/"$_TARGET"/$_FILENAME'_initial.bin'
+    _SYSUPGRADE=$_BUILDS/latest/"$_TARGET"/$_FILENAME'_upgrade.bin'
 
-    ln -sf $_BIN_DIR/$_FN_PREFIX-*-initial.bin $_FACTORY &&
+    ln -sf $_BIN_DIR/$_FILENAME'_initial.bin' $_FACTORY &&
       echo -e "$_FACTORY\n"
-    ln -sf $_BIN_DIR/$_FN_PREFIX-*-upgrade.bin $_SYSUPGRADE &&
+    ln -sf $_BIN_DIR/$_FILENAME'_upgrade.bin' $_SYSUPGRADE &&
       echo -e "$_SYSUPGRADE\n"
 
     # set +o xtrace