Create License agreement screen in OSX - objective-c

I am trying to implement license agreement as shown in the attached image, I can create a new WindowController and design in the same way, but i want to know if we have any default screens in Xcode to do this kind of stuff, as i noticed that most of the apps have similar kind of design.

That's a disk mount license agreement. You can embed a license agreement into a DMG disk image, to be displayed with this screen when a user mounts the image.
If your application is in example/Example.app, you can create example.dmg, embedding EULA.txt into it as follows:
hdiutil create -srcfolder example/ -volname "Example" "example.dmg"
./eula_into_dmg.sh "example.dmg" "EULA.txt"
# you should also codesign the dmg if you're going to distribute it:
codesign -s "$CODE_SIGN_IDENTITY" -v "$dmg"
This is eula_into_dmg.sh:
#!/bin/bash -u
if [[ $# -ne 2 ]]; then
echo "Usage: $0 <dmg> <license>"
exit 1
fi
prefix=$(base64 -D <<<\
H4sIAJtVUFoCA4VWW2vbSBh9bn7Fh3ahbci6o9FcLPahJJIMBbcNjaH7qjpyYupaiyW3pGX/+55vpJF1\
ianBYmTjo/Ody4zv8zqnl6v3t8uX9CqU8ysKlrfbdfCafl28+DMII6XIaGPIhFaTSawiKVSCW5ORsfxZ\
aGxAvdebS5qlxSY/7mpa5vuHY/5Al28YzWgpSMWAVEpb0hIroVVEZsFAGcDVQkVjtILepennT+ksKY/7\
+mPSoqlM4+dKXpO8dhfQ0hE+U5G4IRvZGBcpxmgfVrNLvJZ3q2RWPVXkuSUmBAVjeb4YBMFNWy2xCjFp\
YhZkIhOO0XYY0NPbleu8Q8OkVhrtKDQzSyHnmJS1NBYza6smaHQoKsDRq3KzqYq6RZMCPwIaKKRAi3SE\
i8DlJGMoIjlGo82h/EZaCOHoSY+WGkk2tmws0E6DW80rC9LRQk24/fXlqS7cvDC0eJu2aK1GQnkXcFGJ\
jkiD3ABjgMaEWhsyRvrv74uLe5dFjh+yyLTbEGIlCG9JfjW6KLeahHD0Gj7mbvXpj/YxyHy2f9htq0f6\
cqzrcl8FpycbEqnSjUCQijNl5vDSyQcbrYrCZ57sAeuiqsNWKkSd9bWSG6VJzLlbMUchZPU5LUYLPUG7\
fjgUxSzdVrlbeOEFA8WooVUCKUA4yRpgyExmuFj4EBszRrs9bPf17C7/XoDlz3ebLmKoi6shwtZniS8s\
swTV+bRM9FQeydGiH9v60ZfJKmjk0oWV5tHSpggu/o14cxOP0erHAoIdvlVUbnCz9WhRE9OYG+j2CW6P\
TJhq1H1xM0araLddF/uquKI1Vl+7SSUC21Mctw2jBT8mZEg8ZjJp4GwIqC4pX6+LjhvI+IGcWlEzpFWs\
W+hklNmEW+WGrcpN/SM/dJ6Cm3Cu0cAPzy3DDmDVMy4QfGQn7kval3W3pfWHZLVstyc50qyDmrrg7Lyi\
f7EVVRSkJxeGucikPFPv4aRNaINz7ZOn9g1bZ6etGxbofOuaxvjWnakZDQs0PcJ835rG+NZNanbzjGGT\
HaHt26/Wp+6YOFMzGhZojHbqW9MY79CZmtGwQGO0U9+axnhuvZo9Exyv5RjN9a3NDttwOvoHNXOyR3wb\
GvybSNqZJ0e/69t2X9X5bgeK/T8SiMSCj1JF1rIpsjFFNAe4MdOe9AvHlfG6xdwrdxYqrOBfxk6q0VY4\
RusVLu/lTbpZXLbc+cDaSznJ4BitVziXu4Fu2W+bNtFtdNytsn9W0+PubnntSvc/iogHYQYKAAA= | gunzip -)
suffix=$(base64 -D <<<\
H4sIANNVUFoCA6u15uJKSSxJVFAvLqnMUVfQMDUwMNBRUHLNS8/JLM5QCPZxVNJUqObiVFECShgrAAkD\
OOEMIiyBhKEJQkJJAQnoaynowcAxCKWgpQ81zUABgzAyRzMXp2nqEBNhphliMw3JXEewuThNAwEtZLeh\
+wqNQDEIbtoxZONAZtVacwEAUriwzWEBAAA= | gunzip -)
temp=$(mktemp)
echo -n "$prefix" > "$temp"
cat "$2" | dd conv=swab | hexdump -v -e '8/2 "%04x " "\n"' | sed -e 's/ *$//' -e 's/^/ $"/' -e 's/$/"/' >> "$temp"
echo -n "$suffix" >> "$temp"
hdiutil unflatten "$1"
Rez -a "$temp" -o "$1"
hdiutil flatten "$1"
rm "$temp"

There is no default UI Element for it, nor is there a well known community option. Best option is to design your own.

Related

Running a script when connecting to server with ssh

I use the kitty terminal emulator, so when I connect to a new server, I (usually) need to ad the terminfo (at least, this way it seems to work). To do this I wrote a script. While I was at it, I added a bit of code to add a public key if the user wants it to.
Not really relevant for the question, but here is the code:
#!/bin/bash
host=$1
ip=$(echo $host | cut -d# -f2 | cut -d: -f1)
# Check if it is a unknown host
if [[ -z $(ssh-keygen -F $ip) ]]; then
# Check if there are any ssh-keys
if [ $(ls $HOME/.ssh/*.pub > /dev/null | wc -l) -ne 0 ]; then
keys=$(echo $( (cd $HOME/.ssh/ && ls *.pub) | sed "s/.pub//g" ))
ssh -q -o PubkeyAuthentication=yes -o PasswordAuthentication=no $host "ls > /dev/null 2>&1"
# Check if the server has one of the public keys
if [ $? -ne 0 ]; then
echo "Do you want to add a SSh key to the server?"
while true; do
read -p " Choose [$keys] or leave empty to skip: " key
if [[ -z $key ]]; then
break
elif [[ -e $HOME/.ssh/$key ]]; then
# Give the server a public key
ssh $host "mkdir -p ~/.ssh && chmod 700 ~/.ssh && echo \"$(cat $HOME/.ssh/$key.pub)\" >> ~/.ssh/authorized_keys"
break
else
echo "No key with the name \"$key\" found."
fi
done
fi
fi
# Copy terminfo to server
ssh -t $host "echo \"$(infocmp -x)\" > \"\$TERM.info\" && tic -x \"\$TERM.info\" && rm \$TERM.info"
fi
It is not the best code, but it seems to work. Tips are ofcourse welcome.
The problem is that I need to run this script every time I connect te a new remote server (or I need to keep track of which server is new, but that is even worse). Is there a way to run this script every time I connect to a server (the script checks if the ip is a known host).
Or is there an other way to do this? Adding the public keys is nice to have, but not very important.
I hope somone can help,
Thanks!
There is a trick to identify that you are using ssh to login on the target machine:
pgrep -af "sshd.*"$USER |wc -l
The above command will count the user's processes using sshd
You can add the above command in the target machine, to test if you are connected via ssh. Add the above command to your .profile or .bash_profile script in the target machine.
So that only if you login via ssh your script will run initiation script on the target machine when you login/connect.
Sample .bash_profile on target machine
#!/bin/bash
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
if [[ $(pgrep -af "sshd.*"$USER |wc -l) -gt 0 ]]; then
your_init_script
fi

How can I use Tensorflow in tizen studio?

I want to use tensorflow in tizen.
Tizen studio's architecture is x86.
But tensorflow is only 64-bit.
How can I use tensorflow in tizen studio??
Download packages for target device
tensorflow
python
db4
mkdir tmp
cd tmp
BASE_URL='http://download.tizen.org/snapshots/tizen/5.0-base/latest/repos/standard/packages/armv7l/'
wget -O - $BASE_URL 2>/dev/null | egrep 'db4-[0-9]' | awk -F'"' '{print $2}' | xargs -i wget $BASE_URL{}
wget -O - $BASE_URL 2>/dev/null | egrep 'python-[0-9]' | awk -F'"' '{print $2}' | xargs -i wget $BASE_URL{}
UNIFIED_URL='http://download.tizen.org/snapshots/tizen/5.0-unified/latest/repos/standard/packages/armv7l/'
wget -O - $UNIFIED_URL 2>/dev/null | grep 'tensorflow-v' | awk -F'"' '{print $2}' | xargs -i wget $UNIFIED_URL{}
Install packages on target device
sdb root on; sdb shell 'mount -o remount,rw /'
sdb push *.rpm /tmp
sdb shell 'cd /tmp; rpm -ivh --force db4*.rpm; rpm -ivh --force *python*.rpm; rpm -ivh --force tensorflow*.rpm'
cd ..
rm -r tmp
Download packages needed for building
tensorflow
tensorflow-devel
libpython-2.7
libgfortran
libgomp
mkdir tmp
cd tmp
BASE_URL='http://download.tizen.org/snapshots/tizen/5.0-base/latest/repos/standard/packages/armv7l/'
wget -O - $BASE_URL 2>/dev/null | grep 'libpython-2.7' | awk -F'"' '{print $2}' | xargs -i wget $BASE_URL{}
wget -O - $BASE_URL 2>/dev/null | grep 'libgfortran-' | awk -F'"' '{print $2}' | xargs -i wget $BASE_URL{}
wget -O - $BASE_URL 2>/dev/null | grep 'libgomp-' | awk -F'"' '{print $2}' | xargs -i wget $BASE_URL{}
UNIFIED_URL='http://download.tizen.org/snapshots/tizen/5.0-unified/latest/repos/standard/packages/armv7l/'
wget -O - $UNIFIED_URL 2>/dev/null | grep 'tensorflow' | grep -v 'lite' | awk -F'"' '{print $2}' | xargs -i wget $UNIFIED_URL{}
Extract header and so files and selectively import to project lib folder
ls *.rpm | xargs -i bash -c "rpm2cpio {} | cpio -idmv"
cd usr/lib/
ln -s libpython2.7.so.1.0 libpython2.7.so
ln -s libgfortran.so.3 libgfortran.so
cp libgfortran.so* libgomp.so.1* libpython2.7.so* libpywrap_tensorflow_internal.so ../../../lib/
cd ../include
cp -r tensorflow ../../../inc/
cd ../../..
rm -r tmp
Set up include path in Tizen Studio project
screenshot
Set up library path and add libraries to Tizen Studio project
screenshot
Note that if you want to build the project for emulator, you have to use library files for x86 architecture, so you would have to replace "armv7l" in all the URLs above with "i686"
Tizen studio is just development tool.
Tizen supports x86-64(AMD64) and you can use the tensorflow on Tizen.
If you want to use Tizen with tensorflow, you need to install some packages(tensorflow, python,...) yourself.
If you can afford using Tensorflow-Lite, you can use it directly in Tizen-latest. Soon, with Tizen 5.5 M2, there will be Machine Learning APIs that allows app developers to directly plugin .tflite models as well as their own native models (as .so files or as functions) without worrying about importing external libraries.
Anyway, if you want to do it right now, use the Tizen-latest (Tizen:Unified project in build.tizen.org), use tensorflow-lite-dev.rpm package directly or use nnstreamer-capi package, which gives you some easy-to-use interfaces. Note that nnstreamer (https://github.com/nnsuite/nnstreamer ) is going to be the main engine for Tizen-Machine-Learning (backend of its Machine Learning API sets). Although nnstreamer is compatible with Tensorflow (non-lite), Caffe2, PyTorch, ROS, and so on, they are not included in Tizen by default.

A script to change file names

I am new to awk and shell based programming. I have a bunch of files name file_0001.dat, file_0002.dat......file_1000.dat. I want to change the file names such as the number after file_ will be a multiple of 4 in comparison to previous file name. SO i want to change
file_0001.dat to file_0004.dat
file_0002.dat to file_0008.dat
and so on.
Can anyone suggest a simple script to do it. I have tried the following but without any success.
#!/bin/bash
a=$(echo $1 sed -e 's:file_::g' -e 's:.dat::g')
b=$(echo "${a}*4" | bc)
shuf file_${a}.dat > file_${b}.dat
This script will do that trick for you:
#!/bin/bash
for i in `ls -r *.dat`; do
a=`echo $i | sed 's/file_//g' | sed 's/\.dat//g'`
almost_b=`bc -l <<< "$a*4"`
b=`printf "%04d" $almost_b`
rename "s/$a/$b/g" $i
done
Files before:
file_0001.dat file_0002.dat
Files after first execution:
file_0004.dat file_0008.dat
Files after second execution:
file_0016.dat file_0032.dat
Here's a pure bash way of doing it (without bc, rename or sed).
#!/bin/bash
for i in $(ls -r *.dat); do
prefix="${i%%_*}_"
oldnum="${i//[^0-9]/}"
newnum="$(printf "%04d" $(( 10#$oldnum * 4 )))"
mv "$i" "${prefix}${newnum}.dat"
done
To test it you can do
mkdir tmp && cd $_
touch file_{0001..1000}.dat
(paste code into convert.sh)
chmod +x convert.sh
./convert.sh
Using bash/sed/find:
files=$(find -name 'file_*.dat' | sort -r)
for file in $files; do
n=$(sed 's/[^_]*_0*\([^.]*\).*/\1/' <<< "$file")
let n*=4
nfile=$(printf "file_%04d.dat" "$n")
mv "$file" "$nfile"
done
ls -r1 | awk -F '[_.]' '{printf "%s %s_%04d.%s\n", $0, $1, 4*$2, $3}' | xargs -n2 mv
ls -r1 list file in reverse order to avoid conflict
the second part will generate new filename. For example: file_0002.dat will become file_0002.dat file_0008.dat
xargs -n2 will pass two arguments every time to mv
This might work for you:
paste <(seq -f'mv file_%04g.dat' 1000) <(seq -f'file_%04g.dat' 4 4 4000) |
sort -r |
sh
This can help:
#!/bin/bash
for i in `cat /path/to/requestedfiles |grep -o '[0-9]*'`; do
count=`bc -l <<< "$i*4"`
echo $count
done

AccuRev: how do you list the managed files?

I need to see which files have been added or removed between two streams. The most obvious way would be "git lsfiles" in each stream. Except this is not GIT and I do not see an analogous command. So for today:
for f in $(find * -type f);do
accurev stat "$f"
done | \
fgrep -v '(external)' | \
awk '{print $1}' > .list
If there is a better way, it should be clear and easy to find here:
http://www.accurev.com/download/docs/5.7.0_books/AccuRev_5_7_User_CLI.pdf
but it is not. Help? Thank you.
If you want to see the difference between two streams, run the following command: accurev diff -a -v "Stream1" -V "Stream2"
As the command line question has been answered, here's how to do the same via the AccuRev GUI.
Select one dynamic stream, workspace or snapshot.
Right click and select "Show Diff By Files"
Select a different dynamic stream, workspace or snapshot.
You'll be presented with a list of files different between the two choices, and yes you can mix-and-match between dynamic streams, workspaces and snapshots.
You can then select any file and select "Show Difference" to see differences between the two files.
Since neither of the two answers addressed the question, I eventually worked out a script to do what is really needed. "accurev lsfiles" is sorely needed.
#! /bin/bash
declare -r progpid=$$
declare -r progdir=$(cd $(dirname $0) >/dev/null && pwd)
declare -r prog=$(basename $0)
declare -r program="$progdir/$prog"
declare -r usage_text=' [ <directory> ... ]
If no directory is specified, "." is assumed'
die() {
echo "$prog error: $*"
exec 1>/dev/null 2>&1
kill -9 $progpid
exit 1
} 1>&2
usage() {
test $# -gt 0 && {
exec 1>&2
echo "$prog usage error: $*"
}
printf "USAGE: $prog %s\n" "$usage_text"
exit $#
}
init() {
shift_ct=$#
tmpd=$(mktemp -d ${TMPDIR:-/tmp}/ls-XXXXXX)
test -d "$tmpd" || die "mktemp -d does not work"
exec 4> ${tmpd}/files
trap "rm -rf '$tmpd'" EXIT
prune_pat=
while :
do
test $# -eq 0 && break
test -f "$1" && break
[[ "$1" =~ -.* ]] || break
case "X$1" in
X-p )
prune_pat+="${2}|"
shift 2 || usage "missing arg for '-p' option"
;;
X-p* )
prune_pat+="${1#-p}"
shift
;;
X-x* )
set -x
tput reset 1>&2
PS4='>${FUNCNAME:-lsf}> '
shift
;;
X-* )
usage "unknown option: $1"
;;
* )
break
;;
esac
done
(( shift_ct -= $# ))
test ${#prune_pat} -gt 0 && \
prune_pat='(^|/)('${prune_pat%|}')$'
}
chkdir() {
declare list=$(exec 2> /dev/null
for f in "$#"
do ls -d ${f}/* ${f}/.*
done | \
grep -v -E '.*/\.\.*$' )
for f in $(accurev stat ${list} | \
grep -v -F '(external)' | \
awk '{print $1}' | \
sed 's#^/*\./##')
do
test ${#prune_pat} -gt 0 && [[ $f =~ ${prune_pat} ]] && continue
if test -d "$f"
then chkdir "$f"
elif test -f "$f" -o -L "$f"
then echo "$f" 1>&4
fi
done
}
init ${1+"$#"}
(( shift_ct > 0 )) && shift ${shift_ct}
test $# -eq 0 && set -- .
chkdir "$#"
exec 4>&-
sort -u ${tmpd}/files
It is a bit over-the-top, but I have a boilerplate I always use for my scripts.

background xargs/wget not adhering to -P and -n limits

I'm having a problem with xargs and Wget when run as shell scripts in an Applescript app. I want Wget to run 4 parallel processes in the background. The problem: basically, when I try to run the process in the background with
cat urls.txt | xargs -P 4 -n 1 /usr/local/bin/wget -q -E -b 1> NUL 2> NUL
a Wget process is apparently started for each URL passed in from the .txt file. This is too burdensome on the user's memory. When I run it in the foreground, however, with something like:
cat urls.txt | xargs -P 4 -n 1 /usr/local/bin/wget -q -E
I seem to get the four parallel Wget processes I need. Does anybody know how to get this script to run in the background with only 4 processes? I'm a bit of a novice, and I'm afraid I can't figure out why backgrounding the process causes this change.
You might run xargs on the background instead:
cat urls.txt | xargs -P4 -n1 wget -q &
Or if you want to return control to the AppleScript, disown the xargs process:
do shell script "cat urls.txt | xargs -P4 -n1 /usr/local/bin/wget -q & disown $!"
As far as I can tell, I have solved the problem with
cat urls.txt| (xargs -P4 -n1 wget -q -E >/dev/null 2>&1) &
There may well be a better solution, though...